Can i check if entiy that dies is an animal?
Code:void OnEntityDeath(BaseCombatEntity entity, HitInfo info) { if (entity is BaseNPC) { var attacker = info.Initiator as BasePlayer; if (info.Initiator is BasePlayer) if (entity != "null") { DO WEIRD THINGS; } } }
Solved Checking when an animal dies?
Discussion in 'Rust Development' started by TheMechanical97, Jan 13, 2016.
-
While this might not be the right way, i did it like this and it works.
Code:void OnEntityDeath(BaseCombatEntity entity, HitInfo info) { if ( entity == null ) return; //If entity name contains "corpse", do not fire this event. //I do this because the OnEntityDeath gets called when a player finishes skinning a dead animal as well as when it's initially killed. if (entity.name.Contains("corpse", CompareOptions.IgnoreCase)) return; if (entity.name.Contains("animals", CompareOptions.IgnoreCase)) { //Do stuff } }
-
error CS1501: No overload for method `Contains' takes `2' arguments :S
-
Code:
using UnityEngine;
-
I have that already
-
Would you mind PM'ing me the whole .cs script?
Adding UnityEngine in my project is what gives the ability to have a 2nd argument on the "Contains" field.
Feel free to take the 2nd argument out though. -
I've been cheking config but I cant get the person who killed that animak anyway...
Code:void OnEntityDeath(BaseCombatEntity entity, HitInfo info) { var attacker = info.Initiator as BasePlayer; if (entity == null) { SendReply(attacker, "ENTITY NULL!!"); return; } if (entity.name.Contains("corpse")) { SendReply(attacker, "CORPSE!!"); return; } if (entity.name.Contains("animals")) { SendReply(attacker, "WORKS!! DO WEIRD THINGS"); return; } }
[DOUBLEPOST=1452901189][/DOUBLEPOST]No messages shown on ingame screen
[DOUBLEPOST=1452902240][/DOUBLEPOST]Done Now Thankss XD