Hey, im trying to set up a system that allows to open and look at a storage content, but prevent players from actually grabbing / splitting / consuming *some* items inside that storage.
I have the list of items I want to "lock" and can identify which item is being grabbed from the container. However thing get real messy when spliting : it calls both the split and take events, im not sure you can figure out what are both the origin and destination containers, and you can split from the storage to your inventory and also within the storage.
So far I only achieved to prevent direct "take full stack" from the storage (by creating a new item equal to what has been taken, puting it back in the storage and destroying the taken item), but as soon as spliting is involved its a mess (duplicates, items disappearing / reappearing).
Is there a clean way to lock some specific items in their containers ?
Bonus question : Is there a way to make sure the client view of a container is up to date ?
thanks in advance
Solved Prevent looting *some* items from inventories
Discussion in 'Rust Development' started by Yatta, Jul 17, 2016.
-
btw theres a mixup in the Rust API doc, OnItemSplit has the same description as OnItemUpgrade :
Code:OnItemSplit * Called right before an item is upgraded * No return behavior
Last edited by a moderator: Jul 17, 2016 -
Couldn't you just use OnItemRemovedFromContainer then use a NextTick to move it back to the container it was moved from? I think I have a code example of this still, if you need it.
-
Fixed !
Its not as easy as it sound because you have various cases that dont use the same mechanics :
- Take full stack
- Take full stack and put it in another stack
- Split a stack to an empty slot
- Split a stack to another stack
- Put full/partial stack onto belt empty slot/stack
Plus :
- Split event doesnt tell you if the split succeeded (if you're trying to split onto a full stack and such) so you dont actually know if/how much of something was removed
- Split event doesnt tell you where the result is dropped
- Split event doesnt trigger an AddToContainer event when the result is dropped on an existing stack
- There is no event (that i know of) for when a player add an ammount of item onto a stack
- You cant cancel a split event (with a return true)
And other fun particularities I dont remember right now.
In the end I had to rely on something rather dirty to manage the stack splits : I send a kind of "warning" to nearby players telling them "if in the next split second you get a bigger ammount of that item, that mean you took it from here and you werent supposed to, so discard it". -
Wulf Community Admin
-
Hey, just a little heads to Wulf.
on Oxide API docs for Rust OnItemSplit and OnItemUpgrade still have the same description
(Also mentioning it to make sure im looking at the right page with up-to-date info) -
Wulf Community Admin
-
My bad, didnt know there was a update process. Thanks for fixing it
I know im being a huge pain in the ass and I shouldnt ask about unrelated topics in a thread, but do you know how a server can spawn thousands of tress in a map in a couple seconds at startup ? And is it possible to do the same thing from a plugin ? Im stuck with that - it prevents my mod/plugin to be released on a public server (takes more than 15 minutes to plant the trees manually) which is a bummer after 2+ weeks of working on it ... Its a mod aiming to balance many aspects and players interactions of the game including resources. -
Wulf Community Admin