Code:OnEntityTakeDamage failed: Object reference not set to an instance of an objectIt is copied from FriendlyFire.cs (RustIO), problems shan't be, but they are.Code:void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info) { try { if(entity is BasePlayer && info.Initiator is BasePlayer) { OnAttackShared(info.Initiator as BasePlayer, entity as BasePlayer, info); } } catch(Exception ex) { PrintError("OnEntityTakeDamage failed: " + ex.Message); } }
Solved OnEntityTakeDamage NRE
Discussion in 'Rust Development' started by SwipoStyle, Sep 3, 2015.
-
What about
Code:void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info) { BasePlayer player = (BasePlayer) entity.ToPlayer(); BasePlayer victim = (BasePlayer) info.Initiator; }
-
Code:
void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info) { try { if(entity is BasePlayer && info.Initiator is BasePlayer) { BasePlayer player = (BasePlayer) entity.ToPlayer(); BasePlayer victim = (BasePlayer) info.Initiator; OnAttackShared(player, victim, info); } } catch(Exception ex) { PrintError("OnEntityTakeDamage failed: " + ex.Message); } }
-
Code:if(info.HitEntity != null && info.HitEntity.ToPlayer() != null)
-
-
Code:if(entity != null && entity.ToPlayer() != null && info != null && info.Initiator != null && info.Initiator.ToPlayer() != null) { BasePlayer victim = entity.ToPlayer(); BasePlayer attacker = info.Initiator.ToPlayer(); }
-
-
Code:
try { if(entity !=null&& entity.ToPlayer()!=null&& info !=null&& info.Initiator!=null&& info.Initiator.ToPlayer()!=null) { BasePlayer victim = entity.ToPlayer(); BasePlayer attacker = info.Initiator.ToPlayer(); } } catch(Exception ex) {Puts("Failed! Error: " + ex.ToString())}
-
Code:
OnEntityTakeDamage failed: System.NullReferenceException: Object reference not set to an instance of an object at Oxide.Plugins.Play4Free.OnAttackShared (.BasePlayer attacker, .BasePlayer victim, .HitInfo info) [0x00000] in <filename unknown>:0 at Oxide.Plugins.Play4Free.OnEntityTakeDamage (.BaseCombatEntity entity, .HitInfo info) [0x00000] in <filename unknown>:0
-
-
Code:
private void OnAttackShared(BasePlayer attacker, BasePlayer victim, HitInfo info) { if(attacker == victim) return; string bodypart = StringPool.Get(info.HitBone); if(Config["Bodyparts", bodypart] != null) bodypart = Config["Bodyparts", bodypart].ToString(); else { Config["Bodyparts", bodypart] = bodypart; SaveConfig(); } int distance = Convert.ToInt32(Vector3.Distance(victim.transform.position, attacker.transform.position)); PopupNotifications?.Call("CreatePopupNotification", "Попадание!\nИгрок: <color=#1e90ffff>"+victim.displayName+"</color>\nЧасть тела: <color=#1e90ffff>"+bodypart+"</color>\nРасстояние: <color=#1e90ffff>"+distance+"м</color>", attacker); }
Configuration file was not loaded.