Alright, I have a plethora of theoretically hypothetical weapons. To have them all be individually buyable would be horrendous for the buy menu. The plan is to have weapon cases be the way to obtain some of these weapons.
Upon purchasing the cases and the unit leaves whatever shuttle they were carried in on, the cases are replaced with a single, random weapon from a small database of possible choices.
The only prerequisite I can think of, aside from being Lua attached to an HDFirearm, would be easy editing of the database.
Brolands has one weapon, but a bunch of attachments. I'm talking about several seperate weapons. Like buying a pistol case and having a chance you could get an M1911 or a flintlock pistol, among others.
Script isn't entirely accurate and theres a few kinks and bugs in it but it gives the idea of the concept.
Tue Apr 23, 2013 8:05 am
XavierStudios
Joined: Tue Feb 08, 2011 4:14 am Posts: 59
Re: Randomized Weapon upon Buying
Coops wrote:
Script isn't entirely accurate and theres a few kinks and bugs in it but it gives the idea of the concept.
I appreciate you lending the time, and I can confirm it works after fixing a few errors. I'm not sure if it was intended or not, but after a few tries, it seems the weapon never enters the actor's hands after switching to the case. This, unfortunately, isn't ideal for reasons mostly regarding physics.
Tue Apr 23, 2013 9:29 pm
p3lb0x
Forum Moderator
Joined: Fri Feb 02, 2007 3:53 pm Posts: 1896 Location: in my little gay bunker
Re: Randomized Weapon upon Buying
Yeah, this just creates a weapon at the position of the case. What you need is to check if it is held and if it is then replace the case with a weapon in the actors inventory.
Tue Apr 23, 2013 9:49 pm
XavierStudios
Joined: Tue Feb 08, 2011 4:14 am Posts: 59
Re: Randomized Weapon upon Buying
p3lb0x wrote:
Yeah, this just creates a weapon at the position of the case. What you need is to check if it is held and if it is then replace the case with a weapon in the actors inventory.
I really wouldn't know where to start. I know the forum gets this often, but there are people who have a head for code and I'm not one of them.
Foa, if I recall correctly scripts are only actually run on a weapon while it's selected, so you can't run scripts from an actor's inventory. Thus trying to cycle through the actor's inventory wouldn't accomplish anything. That said, the trick to it is to make a dummy object that you start and end at so you can catalogue the actor's entire inventory for, in the case you mentioned, reproduction.
Anyway, asides aside, try this. It's been a while and I'm kind of fuzzy on CC lua things now so it may not work right off the bat. Post error text if you get any.
Code:
function Create(self) //This part finds the parent actor if there is one self.parent = nil; self.parentpickingdone = false; local actor = MovableMan:GetMOFromID(self.RootID); if MovableMan:IsActor(actor) then self.parent = ToActor(actor); self.parentpickingdone = true; end
//This part makes the weapon list and picks the weapon self.randPistol = {"","",""} -- Pistol preset names here self.pistol = CreateHDfirearm(self.randomPistol[math.random(#self.randomPistol)])
end function Update(self) //Check again for parents due to CC's weirdness when dropping troops in or spawning them in edit mode. May not be necessary for this, I'm not sure if self.parentpickingdone == false then if self.parent == nil then local actor = MovableMan:GetMOFromID(self.RootID);
if MovableMan:IsActor(actor) then self.parent = ToActor(actor); self.parentpickingdone = true; end end end if self.parent ~= nil then //If we have a parent then add the gun to his inventory self.parent.AddInventoryItem(self.pistol); self.ToDelete = true elseif self.parent == nil and self.Age > 1000 //Otherwise, after a second delay to double check if we have a parent, just add the pistol to the map. self.pistol.Pos = self.Pos MovableMan:AddParticle(self.Pistol) self.ToDelete = true end end
Last edited by Bad Boy on Wed Apr 24, 2013 3:26 pm, edited 1 time in total.
That's the one thing I remember, it created an actor that had x weapons up to a count of 30, and it had problems with overlapping names, like the Coalition Shotgun, and the Base.rte Shotgun, there was some point it was resolved, but now it is unresolved now.
Also, double slashes are for ini comments, double hyphens are for lua comments.
Wed Apr 24, 2013 3:16 am
XavierStudios
Joined: Tue Feb 08, 2011 4:14 am Posts: 59
Re: Randomized Weapon upon Buying
Bad Boy wrote:
Post error text if you get any.
First, there was a missing 'then' at line 32. I fixed that, along with the comments. Now it says:
Code:
ERROR: no overload of 'MovableManager:AddParticle' matched the arguments (MovableManager, nil) candidates are: MovableManager:AddParticle(MovableManager, MovableObject)
Wed Apr 24, 2013 3:35 am
Coops
Joined: Wed Feb 17, 2010 12:07 am Posts: 1545 Location: That small peaceful place called Hell.
Re: Randomized Weapon upon Buying
Code:
if self.parent ~= nil then //If we have a parent then add the gun to his inventory self.parent.AddInventoryItem(self.pistol); self.ToDelete = true elseif self.parent == nil and self.Age > 1000 //Otherwise, after a second delay to double check if we have a parent, just add the pistol to the map. self.pistol.Pos = self.Pos MovableMan:AddParticle(self.Pistol) <<------------------------------------------<< self.ToDelete = true end
Shouldn't be capitalized.
Wed Apr 24, 2013 5:21 am
XavierStudios
Joined: Tue Feb 08, 2011 4:14 am Posts: 59
Re: Randomized Weapon upon Buying
Code:
ERROR: no overload of 'Actor:AddInventoryItem' matched the arguments (HDFirearm) candidates are: Actor:AddInventoryItem(MovableObject)
Also, double slashes are for ini comments, double hyphens are for lua comments.
Oh wow, embarrassing, my mind is all filled with java at the moment.
And sorry about that Xavier (also, sorry for the sloppiness of this, I made way too many errors for something so simple), change the line that says MovableMan:AddInventoryItem(self.pistol) to MovableMan:AddInventoryItem(CreateHDFirearm(self.pistol));
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum