Hello,
I am trying to figure out what is causing the NullReference Exception in this part of code -
I see Null checks at the start but it still occasionally calls NullReferences, It's probably 1 in 50 deaths.Code:void OnEntityDeath(BaseCombatEntity entity, HitInfo hitInfo) { if(entity.lastAttacker != null && entity.lastAttacker is BasePlayer) { Vector3 pos = entity.lastAttacker.GetEstimatedWorldPosition(); if(entity is BuildingBlock) { executeQuery("INSERT INTO player_destroy_building (player, building, pos_x, pos_y, pos_z, date) VALUES (@0,@1,@2,@3,@4,@5)", ((BasePlayer)entity.lastAttacker).userID, ((BuildingBlock)entity).blockDefinition.info.name.english, pos.x, pos.y, pos.z, getDateTime()); } else if(entity is BaseNPC) { executeQuery("INSERT INTO player_animal_kill (player, animal, pos_x, pos_y, pos_z, date) VALUES (@0,@1,@2,@3,@4,@5)", ((BasePlayer)entity.lastAttacker).userID, UppercaseFirst(entity.ShortPrefabName), pos.x, pos.y, pos.z, getDateTime()); } else if(entity is BasePlayer && entity != entity.lastAttacker) { executeQuery("INSERT INTO player_kill (killer, victim, pos_x, pos_y, pos_z, weapon, date) VALUES (@0,@1,@2,@3,@4,@5,@6)", ((BasePlayer)entity.lastAttacker).userID, ((BasePlayer)entity).userID, pos.x, pos.y, pos.z, ((BasePlayer)entity.lastAttacker).GetActiveItem().info.displayName.english, getDateTime()); } } if(entity is BasePlayer) { Vector3 pos = entity.GetEstimatedWorldPosition(); string cause = entity.lastDamage.ToString(); executeQuery("INSERT INTO player_death (player, cause, pos_x, pos_y, pos_z, date) VALUES (@0,@1,@2,@3,@4,@5)", ((BasePlayer)entity).userID, cause, pos.x, pos.y, pos.z, getDateTime()); } }
NullReferenceException in my MStats
Discussion in 'Rust Development' started by Nathan 3, Jan 10, 2017.
-
Wulf Community Admin
Most likely the info you are checking for is null in that 1 case, so I'd check info for null.
-
Did you ever figure it out? I'm using MStats and I'm getting this sometimes
Failed to call hook 'OnEntityDeath' on plugin 'MStats v1.2.1' (NullReferenceException: Object reference not set to an instance of an object) -