1. How to assign CUI command to console command? I've done smth like this, but Im gettin error over and over again.
    Button part:
    Code:
     Button =
                        {  
                            Command = $"cui1" ,
                            Color = "0.8 0.8 0.8 0.2"
                        },
    Command part:
    Code:
    [ConsoleCommand("cui1")]
            void TestCommand(IPlayer player)
            {
                var item = ItemManager.FindItemDefinition("hammer");
                BasePlayer player1 = new BasePlayer();
                Puts("Test successful!");
                player1.inventory.GiveItem(ItemManager.CreateByItemID(item.itemid, 1, 0), player1.inventory.containerBelt);
            }
    And error:
    Code:
    [Error] Failed to call hook 'TestCommand' on plugin 'Example v1.0.0' (InvalidCastException: Cannot cast from source type to destination type.)
    (19:29:18) | [Oxide] 19:28 [Debug]   at Oxide.Plugins.Example.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Plugins.CSharpPlugin.InvokeMethod (HookMethod method, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Core.Plugins.Plugin.CallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0
     
  2. Wulf

    Wulf Community Admin

    IPlayer is for the Covalence API only, not for use with normal Rust console commands and the ConsoleCommand attribute.

    void TestCommand(ConsoleSystem.Arg arg) is what you'd use for Rust.
     
  3. Well I changed this line, but Im still getin error, difrent this time.
    Command:
    Code:
    void TestCommand(ConsoleSystem.Arg argr)
            {
               
                var item = ItemManager.FindItemDefinition("hammer");
                BasePlayer player1 = new BasePlayer();
                Puts("Test successful!");
                player1.inventory.GiveItem(ItemManager.CreateByItemID(item.itemid, 1, 0), player1.inventory.containerBelt);
            }
    Error:

    Code:
    Failed to call hook 'TestCommand' on plugin 'Example v1.0.0' (NullReferenceException: Object reference not set to an instance of an object)
    (19:47:18) | [Oxide] 19:46 [Debug]   at Oxide.Plugins.Example.TestCommand (.Arg argr) [0x00000] in <filename unknown>:0
      at Oxide.Plugins.Example.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Plugins.CSharpPlugin.InvokeMethod (HookMethod method, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Core.Plugins.Plugin.CallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0
     
  4. Wulf

    Wulf Community Admin

    Don't try making a new player, you need a valid player which you can get from arg.connection.player as BasePlayer.
     
  5. Example:
    Code:
                [ConsoleCommand("namehere")]
                void TestCommand(ConsoleSystem.Arg arg){
                    var player = arg.connection.player as BasePlayer;
                    if (player == null)
                        return;
                }
     
  6. You can also use
    Code:
    arg.Player()
    -which is a lot simpler. ;)