View unanswered posts | View active topics It is currently Fri Dec 13, 2019 12:57 am



Reply to topic  [ 11 posts ] 
 Pointer to Attachables 
Author Message
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post 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.


Fri Aug 05, 2011 11:23 am
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post 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.


Fri Aug 05, 2011 12:09 pm
Profile
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: Pointer to Attachables
That seems a little redundant.

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


Fri Aug 05, 2011 12:24 pm
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post 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


Fri Aug 05, 2011 12:48 pm
Profile
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post 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.


Fri Aug 05, 2011 12:57 pm
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post 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.


Fri Aug 05, 2011 1:38 pm
Profile
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: Pointer to Attachables
I'm talking about these.

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


Fri Aug 05, 2011 1:41 pm
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post 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


Fri Aug 05, 2011 2:36 pm
Profile
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: Pointer to Attachables
Nope,

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


Fri Aug 05, 2011 2:46 pm
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post 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


Fri Aug 05, 2011 4:13 pm
Profile
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post 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.


Fri Aug 05, 2011 4:24 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 11 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.021s | 15 Queries | GZIP : Off ]