Hello.
I want to prevent players from picking some (not all) items from a container.
My first approach is to use OnItemRemovedFromContainer, if item is 'protected' dont allow the transfert.
That works ... for full stacks.
For splits I then use OnItemSplit, but since you cant check who is doing the spliting I just do a dirty thing telling any nearby players to send back to the container any item of the same kind they just received.
That kinda works ... for spliting items to an empty slot.
For split from a stack to another stack I tried to work arround that but ... its really not reliable.
Right now im with a system that randomly works and has quite some weird glitches which I suspect arent all because of my code.
So Im looking for a better way to allow / prevent a player to pick/split/dropt one or more specific items/stacks of a container. I was thinking about :
- Intercepting 'raw player command' that the client sends to the server asking to 'pick x from container' and cancel it before it is actually managed by the item system.
- Hooking something on the Item.OnChanged() method, but my C# knowledge is not enough to figure out how to do that.
Any help / idea appreciated![]()
Solved Need coding advice on Item control
Discussion in 'Rust Development' started by Yatta, Jul 24, 2016.
-
Haven't done any testing or anything but have you tried using the hook `CanAcceptItem(ItemContainer container, Item item)` and returning `ItemContainer.CanAcceptResult.CannotAccept;`?
-
Thanks a lot for your suggestion, it was a good idea. It didnt prevent every 'steal' case but gave me a solid base and I just had to manage the rest (splits & drops). My system feels rather solid now thanks to you.
How did you figure out you could return ItemContainer.CanAcceptResult values ? -
I was looking at the Assembly-CSharp.dll and not at the docs at the time, the docs are actually wrong regarding the return behavior of the hook, basically returning true won't change anything, returning a value from the CanAcceptResult enum will chang the return behavior
-
If I may ask, how do you explore that kind of information in Visual Studio ? I can use the object browser to see a bunch of info, but the search feature doesnt seem to work. For instance if I search for "CanAcceptItem" I get no results. I understand this must be quite a novice question ... :s
-
CanAcceptItem is a hook that we provide, all available hooks can (normally) be found in our docs: Oxide API for Rust
You won't be able to actually search for CanAcceptItem unless you have a decompiler for Assembly-CSharp.dll that includes the values of variables/methods in the search, or if you fully decompile the dll file and create a VS project out of it, and at that point you are able to look it up in VS. -
Thanks for the information. Ill try to figure out how to decompile that, I think I saw info about that arround here.
-
Some posts where using a decompiler was discussed:
Understanding "namespaces" in Assembly-CSharp and how to use them | Oxide
Solved - Modify Assembly-CSharp | Oxide
Nullify damage with OnPlayerAttack | Oxide
