View unanswered posts | View active topics It is currently Thu Dec 26, 2024 5:14 pm



Reply to topic  [ 5 posts ] 
 CPU-controlled actor inventory 
Author Message
DRL Developer
DRL Developer
User avatar

Joined: Thu Jun 11, 2009 2:34 pm
Posts: 966
Location: Moscow, Russia
Reply with quote
Post CPU-controlled actor inventory
I'm trying to get actor's inventory, script works fine with player-controlled actors but for AI-controlled actor EquippedItem property is always nil. To check I use a simple piece of code:

Code:
   for actor in MovableMan.Actors do
      if actor.Team == CF_CPUTeam then
         print(actor.EquippedItem)
      end
   end


Although the contents of backpack seem to retreive correctly, the only problem is equipped item. Any reasonbale workarounds for this problem?


Sun Dec 25, 2011 12:03 am
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: CPU-controlled actor inventory
Well, you could do a check through all the MOs of the actor and check which one has ClassName == "HDFirearm" or ClassName == "TDExplosive".

I'm pretty sure that kind of code is used in mods for B24 or something.

EDIT:

CaveCricket don't kill me for taking this bits of code from your scanner!

Code:
for i = 1, MovableMan:GetMOIDCount()-1 do
      local gun = MovableMan:GetMOFromID(i);
      if gun.ClassName == "HDFirearm" and gun.PresetName == "Scanner" and SceneMan:ShortestDistance(self.Pos,ToHDFirearm(gun).MuzzlePos,self.mapwrapx).Magnitude < 5 then


Well, I suppose you can modify the if to fit your needs, like "if gun.ClassName == "HDFirearm" or gun.ClassName == "TDExplosive" then actorweapon = gun" or something like it.


Sun Dec 25, 2011 7:51 am
Profile
DRL Developer
DRL Developer
User avatar

Joined: Thu Jun 11, 2009 2:34 pm
Posts: 966
Location: Moscow, Russia
Reply with quote
Post Re: CPU-controlled actor inventory
Ok, I'll try it, thank to both of you, your names won't be forgotten :)


Sun Dec 25, 2011 11:33 am
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: CPU-controlled actor inventory
weegee wrote:
Code:
   for actor in MovableMan.Actors do
      if actor.Team == CF_CPUTeam then
         print(actor.EquippedItem)
      end
   end
Although the contents of backpack seem to retreive correctly, the only problem is equipped item. Any reasonbale workarounds for this problem?

This is a side effect of the underlying C++ code. The EquippedItem property only exists for AHumans, but you are working with Actor pointers in the code above. The correct way of doing this would be to convert the pointer using ToAHuman() when appropriate.


Sun Dec 25, 2011 7:42 pm
Profile
DRL Developer
DRL Developer
User avatar

Joined: Thu Jun 11, 2009 2:34 pm
Posts: 966
Location: Moscow, Russia
Reply with quote
Post Re: CPU-controlled actor inventory
Thank's a lot, now everything's back to normal :) Didn't took into account that actors and ahumans are not the same.


Sun Dec 25, 2011 9:47 pm
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.070s | 15 Queries | GZIP : Off ]