Author |
Message |
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
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 |
|
|
xenoargh
Joined: Fri Dec 30, 2011 3:33 am Posts: 276
|
Re: Accessing an actor's inventory
What does
local myInv = actor:Inventory() return?
|
Wed Jun 27, 2012 2:45 am |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
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 |
|
|
xenoargh
Joined: Fri Dec 30, 2011 3:33 am Posts: 276
|
Re: Accessing an actor's inventory
Is there any reason why you can't use HasObject / HasObjectInGroup ?
|
Wed Jun 27, 2012 3:39 am |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
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 |
|
|
xenoargh
Joined: Fri Dec 30, 2011 3:33 am Posts: 276
|
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 |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
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 |
|
|
xenoargh
Joined: Fri Dec 30, 2011 3:33 am Posts: 276
|
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 |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
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 |
|
|
|