Can't find cause of NullReferenceException in my pluginSolved
 void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        { 
            BasePlayer killer = info?.Initiator as BasePlayer;

            if (killer.userID.IsSteamId())
            {
                if (!Cachedplayerstats.ContainsKey(killer.userID)) PVEStatsData.TryLoad(killer.userID);
            }

            if (!killer.userID.IsSteamId()) return;
            if (entity == null | info == null) return;
            if (killer == null || killer == entity) return;
            
            if (killer.userID.IsSteamId())
            {
                if (entity.ShortPrefabName == "heavyscientist")
                {
                    if ((bool)Config["Count Heavy Scientists"] == true)
                    {
                        if (Cachedplayerstats.ContainsKey(killer.userID)) Cachedplayerstats[killer.userID].heavyKills++;
                        int newheavypoints = Cachedplayerstats[killer.userID].points + heavypoints;
                        Cachedplayerstats[killer.userID].points = newheavypoints;
                    }
                }
            }
            if (killer.userID.IsSteamId())
            {
                if (entity.ShortPrefabName == "scientistnpc")
                {
                    if ((bool)Config["Count Scientists"] == true)
                    {
                        if (Cachedplayerstats.ContainsKey(killer.userID)) Cachedplayerstats[killer.userID].scientistkills++;
                        int newscientistpoints = Cachedplayerstats[killer.userID].points + scientistpoints;
                        Cachedplayerstats[killer.userID].points = newscientistpoints;
                    }

                }
            }
            if (killer.userID.IsSteamId())
            {
                if (entity.ShortPrefabName == "murderer")
                {
                    if ((bool)Config["Count Murderers"] == true)
                    {
                        if (Cachedplayerstats.ContainsKey(killer.userID)) Cachedplayerstats[killer.userID].murdererkills++;
                        int newmurdererpoints = Cachedplayerstats[killer.userID].points + murdererpoints;
                        Cachedplayerstats[killer.userID].points = newmurdererpoints;
                    }
                }
            }

            if (killer.userID.IsSteamId())
            {
                if (entity.ShortPrefabName == "scarecrow")
                {
                    if ((bool)Config["Count Scarecrow"] == true)
                    {
                        if (Cachedplayerstats.ContainsKey(killer.userID)) Cachedplayerstats[killer.userID].scarecrowkills++;
                        int newscarecrowpoints = Cachedplayerstats[killer.userID].points + scarecrowpoints;
                        Cachedplayerstats[killer.userID].points = newscarecrowpoints;
                    }
               }
            }

            if (entity is HTNPlayer)
            {
                if (entity.ShortPrefabName == "scarecrow")
                {
                }
                else
                {
                    if ((bool)Config["Count Scientists"] == true)
                    {
                        if (Cachedplayerstats.ContainsKey(killer.userID)) Cachedplayerstats[killer.userID].scientistkills++;
                        int newscientistallpoints = Cachedplayerstats[killer.userID].points + scientistpoints;
                        Cachedplayerstats[killer.userID].points = newscientistallpoints;
                    }
                }
            }
           
            foreach (var data in Cachedplayerstats) data.Value.Save(data.Key);
            checkrankalreadyhad(killer);
            CheckRank(killer, info);
            GUIUpdateSkill(killer);
            CreateGUI(killer);
            return;
        }

Hey, I am using on entity death to count certain ai kills. However i noticed that on my server, i keep getting these null referance exceptionns. how do i make it so it returns everything except what i want to count. Thanks.

You again have variables with a null reference, you can see them in the code. Or you can't..
If the patrol helicopter or a car dies, i get a null referance expection. But it still happens if i put this:
if (entity is BaseVehicleModule) return;​

 

5df88d179ce26.jpg AVOCoder
You again have variables with a null reference, you can see them in the code. Or you can't..
Thanks for the help.
My guess: There are some variables that don't seem to be defined.

Merged post

scientistpoints, scarecrowpoints, heavypoints

heavyKills has a capital K and the others do not. maybe the other's should?

Merged post

or maybe it's those returns

Merged post

You said you were using Visual Studio, right?

Don't wory, i fixed it. It was the config failing to cast

Locked automatically