Author |
Message |
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
Inventory things
I've got an ACRocket, and I want to know how to access it's inventory.
You know, checking which actor it has inside and deleting it. The only functions I know for inventory are the ones for adding items, check if it has a certain item, changing to the next one and dropping it, but nothing else.
|
Mon Nov 28, 2011 3:12 am |
|
|
Coops
Joined: Wed Feb 17, 2010 12:07 am Posts: 1545 Location: That small peaceful place called Hell.
|
Re: Inventory things
You could try going through all Actors and Items to see the ship has them.
I don't know if that's very efficient though.
|
Mon Nov 28, 2011 5:03 am |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
Re: Inventory things
You mean checking every actor in the game and see if it is in the ship's inventory?
I'd run that chunk only in the create function, so I don't think it would lag much, but would it work properly? And how would that look in a code?
|
Mon Nov 28, 2011 5:21 am |
|
|
Coops
Joined: Wed Feb 17, 2010 12:07 am Posts: 1545 Location: That small peaceful place called Hell.
|
Re: Inventory things
Well you'd only have to check it once for every passenger and add him to a list, and if he leaves the ship then remove him from the list.
I'm not sure if I'm right, But the RootID of the passenger would be the ship's ID. I don't know if that's true or not but if it is then it would make things easier.
I'd show an example, but I haven't touched lua for a while now.
|
Mon Nov 28, 2011 6:04 am |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: Inventory things
MOs need to exist in the "real world" at least once before they actually get an ID, so trying to run an ID check on inventory items usually don't work.
There's a function that returns the current object in an actor's inventory (not including the currently held item), and another that switches through inventory items, so you can use that to check all of the items in an actor's inventory.
The method is prone to bugs though, since you can't tell how many times to switch through items since you don't know how many items are in the inventory, but I believe I managed to get around that by adding an item with a unique PresetName (like "Inventory switcher rock") before switching through items, and when I land on the added item, stop switching and remove it.
I don't remember what the names of the functions were, but I'll look for them later and post back if no one else beats me to it.
|
Mon Nov 28, 2011 3:51 pm |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
Re: Inventory things
Oh great, thanks CC.
EDIT:
Wait, I should explain more what I want to do.
I've got a craft, an ACRocket, that doesn't have doors. What I want to do is that when I buy it with an actor inside, I want to get the actor out with everything I bought without needing the doors at all.
|
Mon Nov 28, 2011 7:19 pm |
|
|
Roast Veg
Data Realms Elite
Joined: Tue May 25, 2010 8:27 pm Posts: 4521 Location: Constant motion
|
Re: Inventory things
I had a look at the old Coming of God mod by TLB I found lying around, and the way he did it was by instagibbing the craft, then with the particle he created subsequently found the closest actor and storing it.
I appreciate you don't want to be spawning craft on top of your cargo, but if you used a filler particle between the original craft and the actual craft you could work from there.
|
Mon Nov 28, 2011 8:28 pm |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
Re: Inventory things
Admittedly, that's a pretty terrible and slapdash way of doing it, so I wouldn't suggest it. It only works well for one actor, and has a tendency to lose their weapons.
|
Mon Nov 28, 2011 8:39 pm |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
Re: Inventory things
Roast, we are in B26, there must be a simpler way to do it.
If not, I might do that.
|
Mon Nov 28, 2011 8:41 pm |
|
|
Roast Veg
Data Realms Elite
Joined: Tue May 25, 2010 8:27 pm Posts: 4521 Location: Constant motion
|
Re: Inventory things
TheLastBanana wrote: has a tendency to lose their weapons To be fair you were just storing the actor's name and then recreating it later. If you found a way to keep it (outside the map?) instead of deleting it, then it'd retain everything.
|
Mon Nov 28, 2011 8:45 pm |
|
|
ramonimbao
Joined: Sat Jan 17, 2009 8:53 am Posts: 79 Location: Philippines
|
Re: Inventory things
Code: local thing = actor:Inventory(); if thing.PresetName == "actor" then self:SwapNextInventory(nil, false); else self:SwapNextInventory(thing, false); end This could probably work for you. From here. Untested though.
|
Tue Nov 29, 2011 4:44 pm |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
Re: Inventory things
actor:Inventory()?
What's that for?
|
Tue Nov 29, 2011 7:35 pm |
|
|
ramonimbao
Joined: Sat Jan 17, 2009 8:53 am Posts: 79 Location: Philippines
|
Re: Inventory things
Oh, that should be self:Inventory(). Sorry.
|
Wed Nov 30, 2011 7:13 am |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
Re: Inventory things
No I mean, what does that code do?
|
Wed Nov 30, 2011 7:28 pm |
|
|
ramonimbao
Joined: Sat Jan 17, 2009 8:53 am Posts: 79 Location: Philippines
|
Re: Inventory things
It appears to return the next item in the inventory.
|
Fri Dec 02, 2011 6:17 pm |
|
|
|