1. Heyo!
    One man that use my plugin has run into the NRE, wich I thought impossible. So - the problem is, that in this cycle SendConsoleCommand crashes with NRE.
    Here is the cycle itself:

    Code:
                foreach (var player in BasePlayer.activePlayerList)
                {
                    player?.SendConsoleCommand("chat.add", userId,
                    string.IsNullOrEmpty(name) ? $"{msg}" : $"{name}: {msg}");
                }
    This function called SendChat, and here is the error:

    Code:
    11:50 [Error] Failed to call hook 'OnUserChat' on plugin 'ChatPlus v1.3.4' (NullReferenceException: Object reference not set to an instance of an object)
    11:50 [Stacktrace] at BasePlayer.SendConsoleCommand (System.String command, System.Object[] obj) [0x00000] in <filename unknown>:0
    at Oxide.Plugins.ChatPlus.SendChat (System.String name, System.String message, System.String censorMessage, System.String userId) [0x00000] in <filename unknown>:0
    at Oxide.Plugins.ChatPlus.OnUserChat (IPlayer sender, System.String message) [0x00000] in <filename unknown>:0
    at Oxide.Plugins.ChatPlus.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00000] in <filename unknown>:0
    at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.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 hook, System.Object[] args) [0x00000] in <filename unknown>:0
    I didn't think that it's possible, but.... Can it be that while iterating activePlayerList some of the players went offline? Cos overwise, I'm out of ideas....
     
  2. Wulf

    Wulf Community Admin

    Yes, it's likely that a player went offline. It'd be good to check if the player is connected before trying to send to them.
     
  3. oh, I see. Thanks. Would do it next time.