Data Realms Fan Forums http://45.55.195.193/ |
|
Held weapons? http://45.55.195.193/viewtopic.php?f=73&t=15522 |
Page 1 of 1 |
Author: | Areku [ Tue Jun 23, 2009 11:00 pm ] |
Post subject: | Held weapons? |
I've used the search option, but had no luck finding any answers to this. So, here it comes: is there any way to check if an actor is holding a specific weapon? Because, as far as I know, held weapons are classified as attachables, and don't appear in the inventory. I could use alternate ways to check that, such as giving the weapon an AEmitter that emitted a specific particle, and having the script check if such particle was within a certain radius of the actor on which the the script will be run, but that would add a lot of unneeded complexity ( and lag thereof ) to the system. Thanks in advance. |
Author: | mail2345 [ Tue Jun 23, 2009 11:06 pm ] |
Post subject: | Re: Held weapons? |
I would iterate though all MOIDs and check the rootID and presetname for the actors ID and the name of the weapon. |
Author: | Areku [ Tue Jun 23, 2009 11:51 pm ] |
Post subject: | Re: Held weapons? |
Tried that, but doesn't seem to work. Here's the script I'm using: Code: function Create(self) -- The variables: self.timer1 = Timer(); end function Update(self) for RedSaw in MovableMan.Items do if RedSaw.PresetName == "Red's Saw" then if RedSaw:IsAttachedTo(self) then print ("It works!") end end end Is there anything wrong with it? |
Author: | mail2345 [ Wed Jun 24, 2009 12:01 am ] |
Post subject: | Re: Held weapons? |
Code: local mo = self for i = 1, MovableMan:GetMOIDCount() do mo = MovableMan:GetMOFromID(i) if mo.RootID == self.ID and mo.PresetName == "Red Saw" then print ("It works!") end end |
Author: | Areku [ Wed Jun 24, 2009 2:31 am ] |
Post subject: | Re: Held weapons? |
1. post Uh, tried that, but it still doesn't work. The console just gives error messages and says that it's "attempting to index a nil value: mo". 2. post Sorry for the double post, but weird stuff has happened. Trying to make the code mail2345 gave me work, I messed around with some variables, and what happens now is that the code works just as it should. If the actor is holding the said weapon, the console prints that it works. There is one little problem, though: it keeps spamming error messages! Every frame a new " attempting to index a nil value! " appears. Even though this is not a big problem, I would really like to know what's happening has the code seems ok now. Anyone can explain? Code: function Create(self) -- The variables: self.timer1 = Timer(); end function Update(self) --local mo = 0 for mo in MovableMan.Particles do for i = 1, MovableMan:GetMOIDCount() do mo = MovableMan:GetMOFromID(i) if mo.RootID == self.ID and mo.PresetName == "Red's Saw" then print ("It works!") end end end end merged |
Author: | mail2345 [ Wed Jun 24, 2009 2:39 am ] |
Post subject: | Re: Held weapons? |
Oh, right, I forgot about what TLB said: Code: function Create(self) -- The variables: self.timer1 = Timer(); end function Update(self) --local mo = 0 for mo in MovableMan.Particles do for i = 1, MovableMan:GetMOIDCount() - 1 do mo = MovableMan:GetMOFromID(i) if mo.RootID == self.ID and mo.PresetName == "Red's Saw" then print ("It works!") end end end end |
Author: | piipu [ Wed Jun 24, 2009 9:12 am ] |
Post subject: | Re: Held weapons? |
You'll want to drop that for loop. There's no need to do this 100 times a frame. |
Author: | Areku [ Wed Jun 24, 2009 2:59 pm ] |
Post subject: | Re: Held weapons? |
I do believe so. Even if I make the script only check that every 15ms, it still generates unholy amounts of lag. EDIT: No, forget what I said. By making the script only check if the actor has the weapon when a specific key is pressed, I managed to circumvent the lag issue. P.S. : See, Thor? I used the edit function this time! |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |