Data Realms Fan Forums http://45.55.195.193/ |
|
Inventory things http://45.55.195.193/viewtopic.php?f=73&t=26711 |
Page 1 of 2 |
Author: | Asklar [ Mon Nov 28, 2011 3:12 am ] |
Post subject: | 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. |
Author: | Coops [ Mon Nov 28, 2011 5:03 am ] |
Post subject: | 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. |
Author: | Asklar [ Mon Nov 28, 2011 5:21 am ] |
Post subject: | 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? |
Author: | Coops [ Mon Nov 28, 2011 6:04 am ] |
Post subject: | 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. |
Author: | CaveCricket48 [ Mon Nov 28, 2011 3:51 pm ] |
Post subject: | 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. |
Author: | Asklar [ Mon Nov 28, 2011 7:19 pm ] |
Post subject: | 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. |
Author: | Roast Veg [ Mon Nov 28, 2011 8:28 pm ] |
Post subject: | 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. |
Author: | TheLastBanana [ Mon Nov 28, 2011 8:39 pm ] |
Post subject: | 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. |
Author: | Asklar [ Mon Nov 28, 2011 8:41 pm ] |
Post subject: | Re: Inventory things |
Roast, we are in B26, there must be a simpler way to do it. If not, I might do that. |
Author: | Roast Veg [ Mon Nov 28, 2011 8:45 pm ] |
Post subject: | 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. |
Author: | ramonimbao [ Tue Nov 29, 2011 4:44 pm ] |
Post subject: | 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. |
Author: | Asklar [ Tue Nov 29, 2011 7:35 pm ] |
Post subject: | Re: Inventory things |
actor:Inventory()? What's that for? |
Author: | ramonimbao [ Wed Nov 30, 2011 7:13 am ] |
Post subject: | Re: Inventory things |
Oh, that should be self:Inventory(). Sorry. |
Author: | Asklar [ Wed Nov 30, 2011 7:28 pm ] |
Post subject: | Re: Inventory things |
No I mean, what does that code do? |
Author: | ramonimbao [ Fri Dec 02, 2011 6:17 pm ] |
Post subject: | Re: Inventory things |
It appears to return the next item in the inventory. |
Page 1 of 2 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |