Data Realms Fan Forums
http://45.55.195.193/

Pointer to Attachables
http://45.55.195.193/viewtopic.php?f=73&t=24968
Page 1 of 1

Author:  Coops [ Fri Aug 05, 2011 11:23 am ]
Post subject:  Pointer to Attachables

Is there any known way to find an attachable when its not the scripted object?

I added this script to the Coalition Heavy:

Code:
function Update(self)
   for attachable in MovableMan.Particles do
      if attachable.ClassName == "Attachable" then
         if attachable:IsAttached() then
            print(attachable.PresetName)
         end
      end
   end
end


I start a skirmish and nothing shows up in the console, ever. Is there something I'm missing or is this currently impossible?

EDIT: It seemed to have passed the ClassName check but then it tells me that ::IsAttached() isnt a function.

Author:  Abdul Alhazred [ Fri Aug 05, 2011 12:09 pm ]
Post subject:  Re: Pointer to Attachables

Only for AHumans. Look at the documentation under Properties:

TFM wrote:
Head
Read-only property. The head AttachableA pointer to the head Attachable of this. Ownership is NOT transferred!

FGArm
Read-only property. The FG Arm as an Attachable. This is for Lua binding mostly.A pointer to the FG Arm Attachable of this. Ownership is NOT transferred!

BGArm
Read-only property. The BG Arm as an Attachable. This is for Lua binding mostly.A pointer to the BG Arm Attachable of this. Ownership is NOT transferred!

FGLeg
Read-only property. The FG Leg as an Attachable. This is for Lua binding mostly.A pointer to the FG Leg Attachable of this. Ownership is NOT transferred!

BGLeg
Read-only property. The BG Leg as an Attachable. This is for Lua binding mostly.A pointer to the BG Leg Attachable of this. Ownership is NOT transferred!

EquippedItem
Read-only property. Returns whatever is equipped in the FG Arm, if anything. OINT.The currently equipped item, if any.

Author:  Coops [ Fri Aug 05, 2011 12:24 pm ]
Post subject:  Re: Pointer to Attachables

That seems a little redundant.

Why would we have seperate functions for something thats only meant for actors?

Author:  Abdul Alhazred [ Fri Aug 05, 2011 12:48 pm ]
Post subject:  Re: Pointer to Attachables

I'm not sure what you are trying to do, but if you wanted to find the head of the AHuman "TargetActor" in B24 you would have to use one of Mail's tricks:
Code:
   local MoObj
   for i = 1, MovableMan:GetMOIDCount()-1 do
      if MovableMan:GetRootMOID(i) == TargetActor.ID then -- this MO has a root ID so we know it is an attachable. and it belongs to TargetActor since the IDs match
         MoObj = MovableMan:GetMOFromID(i)
         if MoObj.PresetName == "The Name of the Head" then
            self.Head = ToAttachable(MoObj)
            break
         end
      end
   end


Now you can just do this:
Code:
TargetActor.Head

Author:  Coops [ Fri Aug 05, 2011 12:57 pm ]
Post subject:  Re: Pointer to Attachables

Well its useful for actors but only actors, I was hoping for the attachable functions to work with Chestplates or Helmets and whatnot.

Author:  Abdul Alhazred [ Fri Aug 05, 2011 1:38 pm ]
Post subject:  Re: Pointer to Attachables

If the attachable is a Movable Object with GetsHitByMOs set to 1 you can still use Mail's method described above.

Author:  Coops [ Fri Aug 05, 2011 1:41 pm ]
Post subject:  Re: Pointer to Attachables

I'm talking about these.

Those functions dont work with any kind of MO. Only the AHuman's, it seems.

Author:  Abdul Alhazred [ Fri Aug 05, 2011 2:36 pm ]
Post subject:  Re: Pointer to Attachables

It is probably because you have the wrong pointer type. Try casting the pointer before you try to access those functions:
Code:
-- find the attachable and store it in "Armor"
...
if Armor.ClassName == "Attachable" then
    Armor = ToAttachable(Armor)
    Armor:Detach() -- should work now
end

Author:  Coops [ Fri Aug 05, 2011 2:46 pm ]
Post subject:  Re: Pointer to Attachables

Nope,

unless the attachable is not attached to anything then it picks it up, if it is attached, then nothing.

Author:  Abdul Alhazred [ Fri Aug 05, 2011 4:13 pm ]
Post subject:  Re: Pointer to Attachables

Attach this to a Coalition "Soldier Light".
Code:
function Create(self)
   local MoObj
   for i = 1, MovableMan:GetMOIDCount()-1 do
      if MovableMan:GetRootMOID(i) == self.ID then
         MoObj = MovableMan:GetMOFromID(i)
         if MoObj.PresetName == "Soldier Helmet A" then
            self.Helmet = ToAttachable(MoObj)
            break
         end
      end
   end
end

function Update(self)
   if self.Helmet then
      if self.Helmet:IsAttached() then   -- check if the pointer is safe to access
         self.Helmet:Detach()
      else
         self.Helmet = nil
      end
   end
end

Author:  Coops [ Fri Aug 05, 2011 4:24 pm ]
Post subject:  Re: Pointer to Attachables

That does work.

Looking at that script I think I didn't get it to work is because I did it all in one frame update, or attachables are not listed in MovableMan.Particles.

Anyhow, thanks for your help. I'll be playing around with this some more to see what works and what doesn't.

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