void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
{
BasePlayer killer = info?.Initiator as BasePlayer;
if (entity == null | info == null) return;
if (killer == null || killer == entity) return;
if (entity.ShortPrefabName == "heavyscientist")
{
if ((bool)Config["Count Heavy Scientists"] == true)
if (Cachedplayerstats.ContainsKey(killer.userID)) Cachedplayerstats[killer.userID].heavyKills++;
HeavyCount(killer);
}
if (entity.ShortPrefabName == "scientistnpc")
{
if ((bool)Config["Count Scientists"] == true)
if (Cachedplayerstats.ContainsKey(killer.userID)) Cachedplayerstats[killer.userID].scientistkills++;
ScientistCount(killer);
}
if (entity.ShortPrefabName == "murderer")
{
if ((bool)Config["Count Murderers"] == true)
if (Cachedplayerstats.ContainsKey(killer.userID)) Cachedplayerstats[killer.userID].murdererkills++;
MurdererCount(killer);
}
if (entity.ShortPrefabName == "scarecrow")
{
if ((bool)Config["Count Scarecrow"] == true)
if (Cachedplayerstats.ContainsKey(killer.userID)) Cachedplayerstats[killer.userID].scarecrowkills++;
ScarecrowCount(killer);
}
foreach (var data in Cachedplayerstats) data.Value.Save(data.Key);
return;
public void HeavyCount(BasePlayer player)
{
if (!Cachedplayerstats.ContainsKey(player.userID)) PVEStatsData.TryLoad(player.userID);
if (Cachedplayerstats[player.userID].heavyKills == (int)Config["first heavy scientist threshold"])
{
player.IPlayer.AddToGroup((string)Config["first heavy scientist threshold oxide group"]);
}
else if (Cachedplayerstats[player.userID].scientistkills == (int)Config["second heavy scientist threshold"])
{
player.IPlayer.AddToGroup((string)Config["second heavy scientist threshold oxide group"]);
}
}I have a function that i made that will check if a player has reached a certain amount of ai kills and then reward them by adding them to a custom oxide group. However when its called, i get these errors:
Failed to call hook 'OnEntityDeath' on plugin 'NPCKillCounter v1.0.0' (NullReferenceException: Object reference not set to an instance of an object)
at Oxide.Plugins.NPCKillCounter.HeavyCount (BasePlayer player) [0x00045] in <2121e22bd2c04704a123578c5a0db5be>:0
at Oxide.Plugins.NPCKillCounter.OnEntityDeath (BaseCombatEntity entity, HitInfo info) [0x000a1] in <2121e22bd2c04704a123578c5a0db5be>:0
at Oxide.Plugins.NPCKillCounter.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00177] in <2121e22bd2c04704a123578c5a0db5be>:0
at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <d09a1f46ca2f4432811bcfe45ad13c7b>:0
at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <cf88a28c7fb44d36890d85a78331cc9d>:0
at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <cf88a28c7fb44d36890d85a78331cc9d>:0Can someone help me fix it?