Need help combining some codeSolved
So im kinda new to this stuff and i was wonder how to add this command into code. I don't want it to be command. When you equip item "glue" it uses it like consumable but i want to add these side effects to it but i just can't find way to add this. Also it seems like CuiHelper.DestroyUi(player, Layer); wont destroy the layers.
        private void OnActiveItemChanged(BasePlayer player, Item oldItem, Item newItem)
        {
            var item = player.GetActiveItem();
            if (item == null) return;
            if (item.info.shortname == "glue")
            {
                HeldEntity heldEntity = player.GetHeldEntity();
                if (heldEntity != null)
                {
                    heldEntity.SetHeld(false);
                    heldEntity.SendNetworkUpdate();

                }
                if (player.inventory.GetAmount(-1899491405) > amount)
                {
                    player.inventory.Take(null, -1899491405, 1);
                    player.metabolism.poison.value = 5;
                    player.health = 40;

                }
            }
        }


        [ChatCommand("cui")]
        private void cmdCui(BasePlayer player, string command, string[] args)
        {
            timer.Repeat(1f, 10, () =>
            {
                var elements = new CuiElementContainer();
                var mainName = elements.Add(new CuiPanel
                {
                    CursorEnabled = false,
                    RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0" },
                    Image = { Color = $"{RandomColor()}" },
                }, "Overlay", Layer);
                Puts(elements.ToString());
                CuiHelper.destroyUI(player, mainName);
                CuiHelper.AddUi(player, elements);
            });
           }
        string RandomColor()
        {
            var random = new System.Random();
            return $"{random.NextDouble()} {random.NextDouble()} {random.NextDouble()} {random.NextDouble()}";
        }
    }
}​
Looks like you can simply copy/paste it.
Locked automatically