I'm trying to get the attacker, not the victim's, Steam ID with the OnEntityDeath hook.
The following doesn't work: data.steamid = Convert.ToInt32(((BasePlayer)entity).userID);
Update: I'm using C#
Solved Getting player's Steam ID in OnEntityDeath
Discussion in 'Rust Development' started by Unum, Oct 11, 2015.
-
Wulf Community Admin
For C#, info.Initiator?.ToPlayer().userID should work.
-
Thank you. Would it be possible for you to provide an example usage of it, too?
data.steamid = Convert.ToInt32(hitInfo.Initiator.ToPlayer().userID);
[DOUBLEPOST=1444534714][/DOUBLEPOST]BasePlayer attacker = hitInfo.Initiator.ToPlayer()
data.steamid = Convert.ToInt32(attacker.userID);
This doesn't work either. -
Wulf Community Admin
It depends what you are passing in, you'd need to match the first variable. The below should work granted you are passing in hitInfo.
hitInfo.Initiator.ToPlayer().userID.ToString() -
Wulf, that worked. Thank you, sir.
[DOUBLEPOST=1444700127,1444536616][/DOUBLEPOST]Now that it's been discussed on how to retrieve the attacker's Steam ID, how would I retrieve the victim's Steam ID in OnEntityDeath? -
Wulf Community Admin
-
Thank you, Wulf, for that fast response.
-
Code:
void OnEntityDeath(BaseCombatEntity entity, HitInfo hitInfo) { BasePlayer player = entity as BasePlayer; if(player == null) return; BasePlayer killer = hitInfo.Initiator as BasePlayer; if(killer == null) return; ulong steamID = killer.userID; // code