View unanswered posts | View active topics It is currently Fri Dec 27, 2024 8:52 am



Reply to topic  [ 5 posts ] 
 Get the Currently Held Weapon 
Author Message
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Get the Currently Held Weapon
How do you get the currently held weapon of an actor? "actor:Inventory()" seems to only get weapons not being currently held.


Sat Oct 24, 2009 5:44 pm
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: Get the Currently Held Weapon
You can use Mail's find attachment script I suppose.

Code:
   -- Find the gun
   local thisID = self.ID
   local MoObj = nil
   
   for i = 1, MovableMan:GetMOIDCount() do
      if MovableMan:GetRootMOID(i) == thisID then   -- an obj without a parent has ID == RootID
         MoObj = MovableMan:GetMOFromID(i)
         if MoObj.ClassName == "HDFirearm" then
            self.Weapon = ToAttachable(MoObj)
            print(self.Weapon.PresetName)
            break
         end
      end
   end


Sat Oct 24, 2009 6:09 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Get the Currently Held Weapon
I didn't think of that. Thanks.


Sat Oct 24, 2009 6:27 pm
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Get the Currently Held Weapon
Code:
   -- Find the gun
   local thisID = self.ID
   local MoObj = nil
   
   for i = 1, MovableMan:GetMOIDCount() - 1 do --so the last result isnt nil
      if MovableMan:GetRootMOID(i) == thisID then   -- an obj without a parent has ID == RootID
         MoObj = MovableMan:GetMOFromID(i)
         if MoObj.ClassName == "HDFirearm" then
            self.Weapon = ToAttachable(MoObj)
            print("Weapon found: "..self.Weapon.PresetName)
            break
         end
      end
   end
A little addendum.


Sun Oct 25, 2009 9:36 am
Profile WWW
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: Get the Currently Held Weapon
Quote:
for i = 1, MovableMan:GetMOIDCount() - 1 do --so the last result isnt nil
At first, this did not make any sense to me since Lua generally iterates from 1 to "end" and C generally iterates from 0 to "end-1", but now I know better. Thanks!


Sun Oct 25, 2009 11:29 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users


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

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.050s | 13 Queries | GZIP : Off ]