View unanswered posts | View active topics It is currently Fri Mar 29, 2024 10:22 am



Reply to topic  [ 9 posts ] 
 Accessing an actor's inventory 
Author Message
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 Accessing an actor's inventory
How do I do it?

I want to know which items the actor has inside it's inventory, and using actor:Inventory() isn't enough.


Wed Jun 27, 2012 1:10 am
Profile

Joined: Fri Dec 30, 2011 3:33 am
Posts: 276
Reply with quote
Post Re: Accessing an actor's inventory
What does

local myInv = actor:Inventory() return?


Wed Jun 27, 2012 2:45 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: Accessing an actor's inventory
Code:
      self.Bought = self:Inventory()
      if self.Bought ~= nil then
         if self.Bought.ClassName == "AHuman" or self.Bought.ClassName == "ACrab" then
            self.Actor = self.Bought


This is a part of a script in which the function is used succesfully, it's used to spawn an actor which is inside a craft out of it.

I think it returns the next item on the inventory, since if I buy many actors it only considers the first one.


Wed Jun 27, 2012 2:52 am
Profile

Joined: Fri Dec 30, 2011 3:33 am
Posts: 276
Reply with quote
Post Re: Accessing an actor's inventory
Is there any reason why you can't use HasObject / HasObjectInGroup ?


Wed Jun 27, 2012 3:39 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: Accessing an actor's inventory
Because I don't want to know if they have a specific item, I just want to know if they have any and which are them.


Wed Jun 27, 2012 3:47 am
Profile

Joined: Fri Dec 30, 2011 3:33 am
Posts: 276
Reply with quote
Post Re: Accessing an actor's inventory
Well, "if they have any" can be found by using IsInventoryEmpty().

If not, hmm.

There's clearly a table (with sub-tables, presumably, for each item in the inventory) involved there, but it doesn't look like it's exposed to Lua.

So that leaves brute force. If you use HasObjectInGroup and develop some smart group categories, you could do it pretty easily.


Wed Jun 27, 2012 3:58 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: Accessing an actor's inventory
Actually, I'm trying to get some variables of whichever items they are holding, like mass and gold value. Specially gold value.

I can't think of any way to do this, I've never done much things related to inventories.


Wed Jun 27, 2012 4:07 am
Profile

Joined: Fri Dec 30, 2011 3:33 am
Posts: 276
Reply with quote
Post Re: Accessing an actor's inventory
If you don't care about finding specifics, then you could just use:

Code:
   for Item in MovableMan.Items do   -- store all HeldDevices of the correct type and within a cerain range in a table
      HD = ToHeldDevice(Item)
      if HD and... <insert some logic>
end
end


That will iterate through every Item and determine whether it's in an Actor's Inventory or not. To get the Actor that holds the Item, get the Parent's ID, which should match your desired actor's ID. You can filter out ACrabs and other undesirables along the way.

Big problem with all of this, though; it's pretty darn expensive. You'll need to eliminate as much clutter as possible or run it very infrequently.


Wed Jun 27, 2012 4:25 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: Accessing an actor's inventory
I'd just have to run it once, but, I'm way too busy to script that. I'll take a look on it when I get time.


Thu Jun 28, 2012 12:27 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 9 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.139s | 15 Queries | GZIP : Off ]