1. What line of code will prevent any item from being placed into a container in the hook CanAcceptItem?

    Despite not knowing how to code in C#, I've been trying to figure this out on my own for a couple hours with zero previous plugin coding experience. Please help me out here.
     
  2. Wulf

    Wulf Community Admin

    From the docs: "Returning a CanAcceptResult enum value overrides default behavior"

    So you'd need to return CanAcceptResult.X (where X is the enum you want to return) from Rust.

    CanAccept,
    CannotAccept,
    CannotAcceptRightNow
     
  3. First of all, thank you Wulf.

    Here's my code. I'm getting the error: error CS0103: The name `CanAcceptResult' does not exist in the current context
    Code:
    ItemContainer.CanAcceptResult CanAcceptItem(ItemContainer container, Item item)
        {
            if (container != null && item != null){
            
                if (container.ShortPrefabName == "hopperoutput")
                {
                        return CanAcceptResult.CannotAccept;
                }
            }
            return CanAcceptResult.CanAccept;
        }
     
  4. Wulf

    Wulf Community Admin

    You'd need to add the appropriate using statement, else you may need to specify ItemContainer. in front of it as well.
     
  5. Is there a way I can find what using statement I need by using JustDecompile on Assembly-CSharp.dll?
     
  6. Wulf

    Wulf Community Admin

    Sure, open it and search.
     
  7. This might be easy for you, but for me I don't know what I'm looking for when the results come up.
     
  8. Wulf

    Wulf Community Admin

    Searching for CanAcceptResult would be where I'd start.
     
  9. As silly as it may sound, I didn't know that the containing class is what's used. But I figured it out:
    Code:
    using static ItemContainer;
    ItemContainer.CanAcceptResult CanAcceptItem(ItemContainer container, Item item)
        {
            if (container.entityOwner.ShortPrefabName == "hopperoutput"){
            
                
                return CanAcceptResult.CannotAccept;
                
            }
            return CanAcceptResult.CanAccept;
        }
    I appreciate your help!
     
  10. Wulf

    Wulf Community Admin

    Code:
    ItemContainer.CanAcceptResult CanAcceptItem(ItemContainer container, Item item)
    {
    return container.entityOwner.ShortPrefabName == "hopperoutput"
    ? ItemContainer.CanAcceptResult.CannotAccept
    : ItemContainer.CanAcceptResult.CanAccept;
    }
    That should work ^.

    Alternative in the way you had it formatted:
    Code:
    ItemContainer.CanAcceptResult CanAcceptItem(ItemContainer container, Item item)
    {
    if (container.entityOwner.ShortPrefabName == "hopperoutput")
        return ItemContainer.CanAcceptResult.CannotAccept
    else
        return ItemContainer.CanAcceptResult.CanAccept;
    }
     
  11. I just did a try/catch to get rid of all the NullReferenceException: Object reference not set to an instance of an object errors. Is there a better way?