1. Hey,

    I was wondering if anyone knows how I would get the inventory of a wooden box when hit with a hammer using the HitInfo.
    Here is what I have so far:

    Code:
    using Rust;
    using System.Collections.Generic;
    using System;
    using System.Reflection;
    using System.Data;
    using System.Linq;
    using UnityEngine;
    using Oxide.Core;
    using Oxide.Core.Configuration;
    using Oxide.Core.Logging;
    using Oxide.Core.Plugins;
    namespace Oxide.Plugins
    {
        [Info("EasyTransfer", "Panda", 1.0)]
        class EasyTransfer : RustPlugin
        {
            void OnHammerHit(BasePlayer player, HitInfo info)
            {
                if(info.HitEntity.gameObject.name.ToString() == "assets/prefabs/deployable/woodenbox/woodbox_deployed.prefab")
                {
                    Puts("It is a wooden box!");
                }
            }
        }
    Not sure how I would go about this, any help would be appreciated.
    Thanks :)
     
  2. Code:
            void OnHammerHit(BasePlayer player, HitInfo info)
            {
                var name = info?.HitEntity?.LookupShortPrefabNameWithoutExtension() ?? string.Empty;
                if (!name.Contains("woodbox")) return;
                var container = info?.HitEntity?.GetComponent<StorageContainer>() ?? null;
                if (container == null) return;
              
            }
    From there, you can use container.inventory.
     
  3. Thanks for the reply, also it doesn't seem to work, unless I did something wrong heres what I got:

    Code:
    void OnHammerHit(BasePlayer player, HitInfo info)
            {
                if (info.HitEntity.GetType().ToString() == "StorageContainer")
                {
                    var container = info?.HitEntity?.GetComponent<StorageContainer>() ?? null;
                    if (container == null) return;                SendReply(player, "{0}", container.inventory);
                }
                else
                {
                    return;
                }
            }
    It justs says 'ItemContainer' in the console.

    Also may I ask what does the question marks do when after info? and HitEntity? .
     
  4. They are null operators, and they default to the value you supply at the end with ?? if it is null. Read more here:
    ?? Operator (C# Reference)


    As for your code, I assumed you knew what to do once you got the inventory. You're just sending a reply of the type of inventory to a string. If you're wanting to get a list of items, do this:

    Code:
    foreach(var item in container.inventory.itemList)
    {
    SendReply(player, item.info.displayName.english);
    }
    
    If you wish to modify any of the items in that foreach loop, you'll have to convert it to a new list/array, like this:
    Code:
    foreach(var item in container.inventory.itemlist.ToList())
    {
    //do things
    }