Data Realms Fan Forums http://45.55.195.193/ |
|
Accessing an actor's inventory http://45.55.195.193/viewtopic.php?f=73&t=31357 |
Page 1 of 1 |
Author: | Asklar [ Wed Jun 27, 2012 1:10 am ] |
Post subject: | 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. |
Author: | xenoargh [ Wed Jun 27, 2012 2:45 am ] |
Post subject: | Re: Accessing an actor's inventory |
What does local myInv = actor:Inventory() return? |
Author: | Asklar [ Wed Jun 27, 2012 2:52 am ] |
Post subject: | 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. |
Author: | xenoargh [ Wed Jun 27, 2012 3:39 am ] |
Post subject: | Re: Accessing an actor's inventory |
Is there any reason why you can't use HasObject / HasObjectInGroup ? |
Author: | Asklar [ Wed Jun 27, 2012 3:47 am ] |
Post subject: | 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. |
Author: | xenoargh [ Wed Jun 27, 2012 3:58 am ] |
Post subject: | 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. |
Author: | Asklar [ Wed Jun 27, 2012 4:07 am ] |
Post subject: | 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. |
Author: | xenoargh [ Wed Jun 27, 2012 4:25 am ] |
Post subject: | 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. |
Author: | Asklar [ Thu Jun 28, 2012 12:27 am ] |
Post subject: | 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. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |