NullReferenceException in OnPlayerDie in custom plugin
I tried multiple hours how i can fix that but im not sure where the null comes from..


void OnPlayerDie(BasePlayer player, HitInfo info)
        {
            BasePlayer killer = info.Initiator as BasePlayer;      
            var item = killer.GetActiveItem();
            var clanplayer = Clans.Call("GetClanOf", player.userID);
            var clanKiller = Clans.Call("GetClanOf", killer.userID);
            if (killer == null) {  return; }
            if (player == null) {  return; }
            if (killer == player) {  return; }
            if (info == null) {  return; }
            if (info.Initiator.IsNpc) {  return; }
            if (player.IsNpc) {  return; }
            if (killer.IsNpc) {  return; }
            if (info.Initiator.creatorEntity) { return; }
            if ((clanplayer == clanKiller) && !player.IsAdmin) { sendAdminMsg("Clan Kill", $"{killer.displayName} has killed <color=##8ff442>{player.displayName}</color>!"); log("clan_kill", $"Clan: [{clanKiller.ToString()}] [{killer.displayName} ({killer.userID})] killed [{player.displayName} ({player.userID})]", false); return; }
           
            PrintToChat($"<color=#1aff1a>{killer.displayName}</color> ({Math.Round(info.InitiatorPlayer.health, 1)} HP) -> <color=#ff3333>{player.displayName}</color>\n<size=13>{item.info.displayName.english} | <color=#1aff1a>{Math.Round(info.ProjectileDistance, 2)}</color>m | {info.boneName}</size>");
            PrintToChat(player, $"You were killed by <color=#1aff1a>{killer.displayName}</color>[<color=#1aff1a>{Math.Round(info.InitiatorPlayer.health, 1)}</color> HP] from <color=#1aff1a>{Math.Round(info.ProjectileDistance, 2)}</color>m using <color=#1aff1a>{item.info.displayName.english}</color> in the <color=#1aff1a>{info.boneName}</color>.");
        }​



 Failed to call hook 'OnPlayerDie' on plugin 'ParadiseRust v1.0.0' (NullReferenceException: Object reference not set to an instance of an object)
  at Oxide.Plugins.ParadiseRust.OnPlayerDie (BasePlayer player, HitInfo info) [0x00013] in <c4e54f04cbaa4f6e87ddc0ec57aed3cf>:0 
  at Oxide.Plugins.ParadiseRust.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x0135a] in <c4e54f04cbaa4f6e87ddc0ec57aed3cf>:0 
  at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <9affce1cd15c4ec183941adef8db1722>:0 
  at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <4452f821def6406d834e4149849fe7ea>:0 
  at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <4452f821def6406d834e4149849fe7ea>:0​
The error is coming from your very first line inside of the method by not checking if info is null before use. In many cases, there is no hit info inRust.
check for null:
  • info
  • info initiator
  • Clan plugin
  • clanPlayer
  • clanKiller
  • info.initiator creator entity
Still same errors happening on deaths like animals killed you / bullets / bleedout.

| Failed to call hook 'OnPlayerDie' on plugin 'ParadiseRust v1.0.0' (NullReferenceException: Object reference not set to an instance of an object)
  at Oxide.Plugins.ParadiseRust.OnPlayerDie (BasePlayer player, HitInfo info) [0x00000] in <194b8bc173fd45b2962e01ab3e2be33e>:0 
  at Oxide.Plugins.ParadiseRust.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x014bf] in <194b8bc173fd45b2962e01ab3e2be33e>:0 
  at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <9affce1cd15c4ec183941adef8db1722>:0 
  at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <4452f821def6406d834e4149849fe7ea>:0 
  at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <4452f821def6406d834e4149849fe7ea>:0​



 void OnPlayerDie(BasePlayer player, HitInfo info)
        {
            BasePlayer killer = info.Initiator as BasePlayer;
            var item = killer.GetActiveItem();
            var clanplayer = Clans.Call("GetClanOf", player.userID);
            var clanKiller = Clans.Call("GetClanOf", killer.userID);

            if (info == null) { sendAdminMsg("OnDie", "info"); return; }
            if (info.Initiator == null) { sendAdminMsg("OnDie", "Initiator"); return; }
            if (Clans == null) { sendAdminMsg("OnDie", "Clans"); return; }
            if (clanplayer == null) { sendAdminMsg("OnDie", "Clan Player"); return; }
            if (clanKiller == null) { sendAdminMsg("OnDie", "Clan Killer"); return; }
            if (info.Initiator.creatorEntity == null) { sendAdminMsg("OnDie", "Creator Entity"); return; }

            if ((clanplayer == clanKiller) && !player.IsAdmin) { sendAdminMsg("Clan Kill", $"{killer.displayName} has killed <color=##8ff442>{player.displayName}</color>!"); log("clan_kill", $"Clan: [{clanKiller.ToString()}] [{killer.displayName} ({killer.userID})] killed [{player.displayName} ({player.userID})]", false); return; }
        
            PrintToChat($"<color=#1aff1a>{killer.displayName}</color> ({Math.Round(info.InitiatorPlayer.health, 1)} HP) -> <color=#ff3333>{player.displayName}</color>\n<size=13>{item.info.displayName.english} | <color=#1aff1a>{Math.Round(info.ProjectileDistance, 2)}</color>m | {info.boneName}</size>");
            PrintToChat(player, $"You were killed by <color=#1aff1a>{killer.displayName}</color>[<color=#1aff1a>{Math.Round(info.InitiatorPlayer.health, 1)}</color> HP] from <color=#1aff1a>{Math.Round(info.ProjectileDistance, 2)}</color>m using <color=#1aff1a>{item.info.displayName.english}</color> in the <color=#1aff1a>{info.boneName}</color>.");
        }
   ​
You still aren't null checking info before using it in the first line. You check it later, but that's too late as you're already trying to use it to get Initiator.
In response to Wulf ():
You still aren't null checking info before using it in the first line. You check it later, but that'...
I posted the wrong one info is in first place
In response to TheReaper ():
I posted the wrong one info is in first place
 void OnPlayerDie(BasePlayer player, HitInfo info)
        {
            if (info == null) { sendAdminMsg("OnDie", "info"); return; }
            if (info.Initiator == null) { sendAdminMsg("OnDie", "Initiator"); return; }
            var killer = info.Initiator as BasePlayer;
            if (killer == null) {return;}
            var item = killer.GetActiveItem();
            if (item == null) {return;}
            if (Clans == null) { sendAdminMsg("OnDie", "Clans"); return; }
            var clanplayer = Clans?.Call("GetClanOf", player.userID);
            var clanKiller = Clans?.Call("GetClanOf", killer.userID);
            if (clanplayer == null) { sendAdminMsg("OnDie", "Clan Player"); return; }
            if (clanKiller == null) { sendAdminMsg("OnDie", "Clan Killer"); return; }
            if (info.Initiator.creatorEntity == null) { sendAdminMsg("OnDie", "Creator Entity"); return; }
        }

something like that