Adding kill XP for animalsSolved

After messing around a bit I was able to get kills for animals to add XP to players, Although I do get random errors in the console it works. Any help getting rid of the random erros would be greatly appreciated!

		void OnEntityDeath(BaseCombatEntity victimEntity, HitInfo hitInfo, BasePlayer player)
		{
		
            // Ignore - there is no victim for some reason
            if (victimEntity == null)
                return;

            // Try to avoid error when entity was destroyed
            if (victimEntity.gameObject == null)
                return;
				
            //var attacker = hitInfo.Initiator as BasePlayer;
            //var victim = hitInfo.Initiator;	
			
			var Animal = victimEntity?.GetType().Name;	
			var KillerEntity = victimEntity.lastAttacker ?? hitInfo?.Initiator;
			var Killername = KillerEntity?.GetType().Name;
			var Killernameother = KillerEntity?.ShortPrefabName;
			var attacker = hitInfo.Initiator as BasePlayer;
			 
			if (attacker is BasePlayer)
			{
				var rpgInfo = FindRpgInfo(attacker);
				
					if (Animal == "Chicken")
					{
						ExpGain(rpgInfo, (int) Math.Ceiling(100.0 * 1.0), attacker);
					}
					if (Animal == "Boar")
					{
						ExpGain(rpgInfo, (int) Math.Ceiling(200.0 * 1.0), attacker);
					}
					if (Animal == "Wolf")
					{
						ExpGain(rpgInfo, (int) Math.Ceiling(300.0 * 1.0), attacker);
					}
					if (Animal == "Stag")
					{
						ExpGain(rpgInfo, (int) Math.Ceiling(400.0 * 1.0), attacker);
					}
					if (Animal == "Bear")
					{
						ExpGain(rpgInfo, (int) Math.Ceiling(500.0 * 1.0), attacker);
					}
				
			}
		}​

the errors that appear randomly are:
(05:31:53) | Failed to call hook 'OnEntityDeath' on plugin 'HuntRPG v1.7.9' (NullReferenceException: Object reference not set to an instance of an object)
  at Oxide.Plugins.HuntRPG.OnEntityDeath (BaseCombatEntity victimEntity, HitInfo hitInfo, BasePlayer player) [0x00076] in <6787da09da1e4ee6b6444d62184244b6>:0 
  at Oxide.Plugins.HuntRPG.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00486] in <6787da09da1e4ee6b6444d62184244b6>:0 
  at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <3606d2af539c45e4b5c61658e6a8b307>:0 
  at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <c2afd8354b8b4f3ca451cf5a1aa111c3>:0 
  at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <c2afd8354b8b4f3ca451cf5a1aa111c3>:0​

I believe it has something to do with other deaths around the world.

Ok i figured out the error and fixed it. I also added XP for scientist and loot objects when destroyed. If anyone else wants to add in the code to their copy I have it below. Added to lines 201 - 261

You can change the amount of XP given for each by changing the values in (int) Math.Ceiling(100.0 * 1.0)

//----------------------- XP On Damage Start -------------------------------------------------------+	
            
		
		void OnEntityDeath(BaseCombatEntity victimEntity, HitInfo hitInfo, BasePlayer player)
		{
		
            //Ignore - there is no victim or attacker for some reason
            if (victimEntity == null)
				return;
			if (hitInfo == null)
				return;
			if (hitInfo.Initiator == null)
				return;
			
            //Try to avoid error when entity was destroyed
            if (victimEntity.gameObject == null)
                return;
				
			var attacker = hitInfo.Initiator as BasePlayer;
			
			// Give XP to player on kill
			if (attacker is BasePlayer)
			{
				var Animal = victimEntity?.GetType().Name;
				var rpgInfo = FindRpgInfo(attacker);
				
					if (Animal == "Chicken")
					{
						ExpGain(rpgInfo, (int) Math.Ceiling(100.0 * 1.0), attacker);
					}
					if (Animal == "Boar")
					{
						ExpGain(rpgInfo, (int) Math.Ceiling(200.0 * 1.0), attacker);
					}
					if (Animal == "Wolf")
					{
						ExpGain(rpgInfo, (int) Math.Ceiling(300.0 * 1.0), attacker);
					}
					if (Animal == "Stag")
					{
						ExpGain(rpgInfo, (int) Math.Ceiling(400.0 * 1.0), attacker);
					}
					if (Animal == "Bear")
					{
						ExpGain(rpgInfo, (int) Math.Ceiling(500.0 * 1.0), attacker);
					}
					if (Animal == "Scientist")
					{
						ExpGain(rpgInfo, (int) Math.Ceiling(2500.0 * 1.0), attacker);
					}
					if (Animal == "LootContainer")
					{
						ExpGain(rpgInfo, (int) Math.Ceiling(50.0 * 1.0), attacker);
					}	
					//Puts(Animal);				
			}			
			
		}
		
				
//----------------------- XP On Damage End ---------------------------------------------------------+​
Locked automatically