I was hoping somebody could tell me how I can prevent all players from placing ANY items into a quarry hopper. I wanted to use a plugin which prevents players from opening hoppers when they don't have building permission, but I also didn't want the quarry owners exploiting that and using it as a storage location.
Thanks.
Preventing item placement in quarry hoppers?
Discussion in 'Rust Development' started by Abnormal Zombie, Nov 20, 2017.
-
Calytic Community Admin Community Mod
I don't know exactly, but something along these lines..
Detect when player opens a hopper, using OnLootEntity
Oxide API for Rust
Then, check if the opened entity is a quarry hopper, then check if the player has permission to open the hopper.
If they do have permission, do nothing.
If they don't, then..
Code:player.inventory.loot.Invoke("SendUpdate", 0.1f); storageContainer.SendMessage("PlayerStoppedLooting", player, SendMessageOptions.DontRequireReceiver); player.SendConsoleCommand("inventory.endloot", null);
-
Thanks for the reply Calytic. After doing A LOT of looking around, since I have no idea what I'm doing, I came up with the following code with the help of Wulf:
Code:ItemContainer.CanAcceptResult CanAcceptItem(ItemContainer container, Item item) { return container.entityOwner.ShortPrefabName == "hopperoutput" ? ItemContainer.CanAcceptResult.CannotAccept : ItemContainer.CanAcceptResult.CanAccept; }
-
Calytic Community Admin Community Mod
No, hooks are an all-or-nothing proposition.
-
Code:object CanAcceptItem(ItemContainer container, Item item) { if (container.entityOwner.ShortPrefabName == "hopperoutput") return ItemContainer.CanAcceptResult.CannotAccept; return null; }
-
I agree with shady, but the solution has a general problem: It prevents also the quarry itself from placing the stuff inside the hopper
The if clause would also need to check the item for coming from a player, like:Code:if (container.entityOwner.ShortPrefabName == "hopperoutput" && item.GetOwnerPlayer())
But this has again an issue: It does not prevent splitted stacks being put inside, cause the split stack is a new generated item with no owner at this time^^
Finally said, "CanAcceptItem" is useless for an 100% secure solution.
What really works for 100% is, to set the containers inventory flag NoItemInput, like:
Code:(hopper as StorageContainer).inventory.SetFlag(ItemContainer.Flag.NoItemInput, true)
-
-
After digging around blindly for a long-ass time, I've figured it out. It may not be the best way, but it works - even on existing quarries.
I did three things: Checked for when a quarry generates an item(OnQuarryGather) and set the text value for that item to "hopperitem". Then I used CanAcceptItem to check if items trying to be moved into a hopper included the "hopperitem" text property, otherwise the action would be denied. Lastly I did a check for when an item enters a hopper with OnItemAddedToContainer and setting the text back to "".
I've created a bond with my code after spending so many lonely hours with it... I'm not changing it.
I tried comparing ever single value of items entering quarries automatically and by a player to check for differences... to no avail. So I figured I could use one of the item values as a temporary placeholder to make it identifiable to tell the difference. I somewhat understand code, but I don't code at all - so this took me a realllly long time. -
you using this hook in your mod correct?
Oxide API for Rust
You could look at the container type to block adding items to it. -
Probably you should use type checking instead, using if(container.entityOwner is MiningQuarry) .
-