Creating a container and opening?Solved
Hello everyone! I'm pretty new at modding for Rust, I'm trying to do something kinda simple, creating a container when I type /stash and inmediately open it, I have this code

namespace Oxide.Plugins
{
    [Info("StackBag", "Gonzo", "1.0")]
    public class StackBag : RustPlugin
    {
        [ChatCommand("stash")]
        private void StashCommand(BasePlayer player, string command, string[] args)
        {
            ItemContainer loot = new ItemContainer
            {
                capacity = 3,
                isServer = true,
                entityOwner = player,
                allowedContents = ItemContainer.ContentsType.Generic
            };
            loot.ServerInitialize(null, 3);
            loot.GiveUID();
            loot.MarkDirty();
            timer.Once(.25f, () =>
            {
                player.inventory.loot.Clear();
                player.inventory.loot.PositionChecks = false;
                player.inventory.loot.entitySource = loot.entityOwner ?? player;
                player.inventory.loot.itemSource = null;
                player.inventory.loot.MarkDirty();
                player.inventory.loot.AddContainer(loot);
                player.inventory.loot.SendImmediate();

                player.ClientRPCPlayer(null, player, "RPC_OpenLootPanel", "genericlarge");
            });
        }
    }
}
​


The problem is that right after that RPC, the containers UI gets deleted and suddenly shows normal quick craft menu
As you can see in this video (NSFW)

Anyone knows what's going on? It's such a small script that's giving me too many headaches!
need to create unity object first
he has property inventory with type ItemContainer
var storage = GameManager.server.CreateEntity("assets/prefabs/deployable/woodenbox/woodbox_deployed.prefab") as StorageContainer;
ItemContainer loot = storage.inventory;​
-- or --
storage.inventory = loot;
 
Thank you so much, i've solved it!
This is how it would look like after i've added something that removes the container once you're done with it to avoid GC

using System.Collections.Generic;

namespace Oxide.Plugins
{
    [Info("StackBag", "Gonzo", "1.0")]
    public class StackBag : RustPlugin
    {
        List<StorageContainer> containers = new List<StorageContainer>();
        [ChatCommand("stash")]
        private void StashCommand(BasePlayer player, string command, string[] args)
        {
            var storage = GameManager.server.CreateEntity("assets/prefabs/deployable/woodenbox/woodbox_deployed.prefab") as StorageContainer;
            storage.Spawn();
            ItemContainer loot = storage.inventory;
            loot.availableSlots = new List<ItemSlot>(3);
            loot.capacity = 3;
            loot.ServerInitialize(null, 3);

            containers.Add(storage);

            timer.Once(.25f, () =>
            {
                player.inventory.loot.Clear();
                player.inventory.loot.PositionChecks = false;
                player.inventory.loot.entitySource = loot.entityOwner ?? player;
                player.inventory.loot.itemSource = null;
                player.inventory.loot.MarkDirty();
                player.inventory.loot.AddContainer(loot);
                player.inventory.loot.SendImmediate();

                player.ClientRPCPlayer(null, player, "RPC_OpenLootPanel", "genericlarge");
            });
        }

        void OnLootEntityEnd(BasePlayer player, BaseCombatEntity entity)
        {
            int index = containers.IndexOf(entity as StorageContainer);
            if (index > 0)
            {
                entity.Kill();
                containers.RemoveAt(index);
            }
        }
    }
}
​
gonzalolog
Thank you so much, i've solved it!
This is how it would look like after i've added something that removes the container once you're done with it to avoid GC

simply use

entity.Kill();
 
Locked automatically