1. 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.
     
  2. Calytic

    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);
    [DOUBLEPOST=1511217584][/DOUBLEPOST]You will have to dig around the server-side code and oxide plugins to get the specifics, but that should get you started..
     
  3. 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;
    }
    I like your suggestion, but I still want players to open the hopper, just not place items into it. The code above does that, but I think it might be called too often. Is there a way I can cut down the amount of times my code is called?
     
  4. Calytic

    Calytic Community Admin Community Mod

    No, hooks are an all-or-nothing proposition.
     
  5. You should probably write it like this, so it's only overriding if it's a hopper, else it *may* result in allowing things into containers that aren't normally allowed:
    Code:
    object CanAcceptItem(ItemContainer container, Item item)
    {
    if (container.entityOwner.ShortPrefabName == "hopperoutput") return ItemContainer.CanAcceptResult.CannotAccept;
    return null;
    }
    
     
  6. I agree with shady, but the solution has a general problem: It prevents also the quarry itself from placing the stuff inside the hopper :p
    The if clause would also need to check the item for coming from a player, like:
    Code:
    if (container.entityOwner.ShortPrefabName == "hopperoutput" && item.GetOwnerPlayer())
    That would prevent placing items from the players inv.
    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)
    One time at spawn of the quarry, and for sure also generally for all hopperoutputs when the plugin loads :)
     
  7. That's interesting. I'm guessing NoItemInput only blocks player inputs, not ones originating from the server?
     
  8. I think you'd be right Shady.

    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.
     
  9. 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.
     
  10. Probably you should use type checking instead, using if(container.entityOwner is MiningQuarry) .
     
  11. If I remember correctly, the hoppers and the fuel storage are not part of the quarry itself, and will never be of type MiningQuarry.