NPC function adding to playerdataSolved
Hey!

This is my first time going into a plugin to edit so I can change it to function better cause it has not been updated for a good few months. The only problem is i'm not sure how the funtion is being called. So currently when you kill a player below a certain level you will lose XP but for some reason NPC are being classsed as players as well so when you kill the scientist you will also lose XP. I can see in the code below that NPCPlayerApex is suppose to return null but for some reason it's adding the NPC's to the playerData file. The results I trying to achieve is if you kill the NPC's you gain XP as normal like the Helicopter.

private object OnPlayerDie(BasePlayer player, HitInfo info)
        {
			if (player is NPCPlayerApex)
			{
				return null;
			}
			
            var playerData = GetPlayerData(player.userID);

            if (info?.InitiatorPlayer != null && player != info.InitiatorPlayer)
            {
                var killerData = GetPlayerData(info.InitiatorPlayer.userID);

                if (Math.Floor(playerData.Level) <= _config.NoobKill.MaxNoobLevel &&
                    Math.Floor(killerData.Level) > _config.NoobKill.MaxNoobLevel)
                {
                    MessagePlayer(Lang("XP_NOOB_KILL", info.InitiatorPlayer), info.InitiatorPlayer);
                    IncreaseXp(info.InitiatorPlayer, _config.NoobKill.XpPunishment);
                }
                else
                {
                    IncreaseXp(info.InitiatorPlayer, _config.LevelRates.PlayerKilled);
                }
            }

            return null;
        }​

 

private void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
            BasePlayer victum = entity as BasePlayer;
            
			if (victum != null)
            {
                InfiniteComponents(victum, true, false);
            }
			
            if (info?.InitiatorPlayer != null)
            {
                if (entity.PrefabName.Contains("npc"))
                {
                    if (entity.PrefabName.Contains("patrolhelicopter"))
                    {
                        IncreaseXp(info.InitiatorPlayer, _config.LevelRates.KilledHeli);
                    }
                }
                else if (entity.PrefabName.Contains("rust.ai") && !entity.PrefabName.Contains("corpse"))
                {
                    IncreaseXp(info.InitiatorPlayer, _config.LevelRates.KilledAnimal * (entity._maxHealth / 90.0f));
                }
                else if (entity.PrefabName.Contains("radtown") || entity.PrefabName.Contains("loot-barrel"))
                {
                    IncreaseXp(info.InitiatorPlayer, _config.LevelRates.BrokeBarrel);
                }
            }
        }

        private void OnCollectiblePickup(Item item, BasePlayer player)
        {
            IncreaseXp(player, _config.LevelRates.ItemPickup);
        }

        private void OnDispenserGather(ResourceDispenser dispenser, BaseEntity entity, Item item)
        {
            var player = entity.ToPlayer();

            if (player == null || player is NPCPlayer || dispenser == null)
            {
                return;
            }

            if (dispenser.gatherType == ResourceDispenser.GatherType.Tree)
            {
                IncreaseXp(player, _config.LevelRates.HitTree);
            }

            if (dispenser.gatherType == ResourceDispenser.GatherType.Ore)
            {
                IncreaseXp(player, _config.LevelRates.HitOre);
            }

            if (dispenser.gatherType == ResourceDispenser.GatherType.Flesh)
            {
                IncreaseXp(player, _config.LevelRates.HitFlesh);
            }
        }
Solved thank you.
Locked automatically