Data Realms Fan Forums
http://45.55.195.193/

Randomized Weapon upon Buying
http://45.55.195.193/viewtopic.php?f=1&t=45260
Page 1 of 2

Author:  XavierStudios [ Mon Apr 22, 2013 4:38 pm ]
Post subject:  Randomized Weapon upon Buying

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.

Thanks in advance

Author:  Benpasko [ Mon Apr 22, 2013 5:06 pm ]
Post subject:  Re: Randomized Weapon upon Buying

There's a mod like that, I think. Here you go.
viewtopic.php?f=61&t=31852

Author:  XavierStudios [ Mon Apr 22, 2013 5:16 pm ]
Post subject:  Re: Randomized Weapon upon Buying

Benpasko wrote:
There's a mod like that, I think. Here you go.
viewtopic.php?f=61&t=31852


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.

Author:  Foa [ Tue Apr 23, 2013 7:02 am ]
Post subject:  Re: Randomized Weapon upon Buying

Sounds like a few tables, and a few random selectors.

Someone brief him on this, I think Weegee uses this extensibly in his scenes for unit generation/archetypes.

Author:  Coops [ Tue Apr 23, 2013 8:05 am ]
Post subject:  Re: Randomized Weapon upon Buying

It's a pretty simple task, really.

Just have all your weapons premade in the ini.

Code:
function Create(self)

   self.randPistol = {"","",""} -- Pistol preset names here
   
   self.pistol = CreateHDfirearm(self.randomPistol[math.random(#self.randomPistol)])
   self.pistol.Pos = self.Pos
   MovableMan:AddParticle(self.pistol)
   self.ToDelete = true

end


Script isn't entirely accurate and theres a few kinks and bugs in it but it gives the idea of the concept.

Author:  XavierStudios [ Tue Apr 23, 2013 9:29 pm ]
Post subject:  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.

Author:  p3lb0x [ Tue Apr 23, 2013 9:49 pm ]
Post subject:  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.

Author:  XavierStudios [ Tue Apr 23, 2013 9:58 pm ]
Post subject:  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.

Author:  Foa [ Wed Apr 24, 2013 2:26 am ]
Post subject:  Re: Randomized Weapon upon Buying

Cave Cricket uses something that reads the Actor's inventory, I guess it's the Repair Kit.

Author:  Bad Boy [ Wed Apr 24, 2013 2:51 am ]
Post subject:  Re: Randomized Weapon upon Buying

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.

Author:  Foa [ Wed Apr 24, 2013 3:16 am ]
Post subject:  Re: Randomized Weapon upon Buying

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.

Author:  XavierStudios [ Wed Apr 24, 2013 3:35 am ]
Post subject:  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)

Author:  Coops [ Wed Apr 24, 2013 5:21 am ]
Post subject:  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.

Author:  XavierStudios [ Wed Apr 24, 2013 6:12 am ]
Post subject:  Re: Randomized Weapon upon Buying

Code:
ERROR: no overload of 'Actor:AddInventoryItem' matched the arguments (HDFirearm)
candidates are:
Actor:AddInventoryItem(MovableObject)

Author:  Bad Boy [ Wed Apr 24, 2013 6:26 am ]
Post subject:  Re: Randomized Weapon upon Buying

Foa wrote:
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));

Page 1 of 2 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/