Data Realms Fan Forums
http://45.55.195.193/

Get the Currently Held Weapon
http://45.55.195.193/viewtopic.php?f=73&t=16939
Page 1 of 1

Author:  CaveCricket48 [ Sat Oct 24, 2009 5:44 pm ]
Post subject:  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.

Author:  Abdul Alhazred [ Sat Oct 24, 2009 6:09 pm ]
Post subject:  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

Author:  CaveCricket48 [ Sat Oct 24, 2009 6:27 pm ]
Post subject:  Re: Get the Currently Held Weapon

I didn't think of that. Thanks.

Author:  Geti [ Sun Oct 25, 2009 9:36 am ]
Post subject:  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.

Author:  Abdul Alhazred [ Sun Oct 25, 2009 11:29 am ]
Post subject:  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!

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