1. I'm newbie. I try create console command but i always het the error:

    Code:
    [Oxide] 20:34 [Error] Failed to call hook 'RandomCommand' on plugin 'dezola v0.1.0' (NullReferenceException: Object reference not set to an instance of an object)
    [Oxide] 20:34 [Debug]   at Oxide.Plugins.Dezola.RandomCommand (.Arg arg) [0x00000] in <filename unknown>:0
      at Oxide.Plugins.Dezola.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
    My code:

    Code:
            [ConsoleCommand("random")]
            private void RandomCommand(ConsoleSystem.Arg arg)
            {
                BasePlayer player = (BasePlayer)arg?.connection?.player ?? null;
                int Range = Core.Random.Range(0, Weapons.Length);
                var item = ItemManager.CreateByName(Weapons[Range]);
                player.GiveItem(item);
    //            Puts("Yeah!");
            }
    What am i doing wrong??
     
  2. Wulf

    Wulf Community Admin

    One of the items you are trying to call is null, either the player, range, or item, but likely the player as you aren't checking if it is null before giving the item.