Hello,
I'm having a problem where i am storing data connected to IPlayer, but using a hook that uses BaseEntity or BasePlayer. How do i go about getting the player information under IPlayer from BasePlayer/Entiy?
This results in:Code:private void OnPlayerAttack(BasePlayer player, HitInfo info) { var victim = info?.HitEntity as IPlayer; var attacker = info?.Initiator as BasePlayer; Puts("Victim: " + victim); Puts("Player: " + attacker); }
Code:[AngryJail] Victim: [AngryJail] Player: [AMob] Tori1157[13219/76561198025298808]
Solved Casting IPlayer within BaseEntity/Player?
Discussion in 'Rust Development' started by Tori1157, Sep 26, 2017.
-
victim.IPlayer
attacker.IPlayer -
...?? Really? It was that simple? Well, just goes to show overthinking is not the way to go. Thanks for the help Ryan!
-
Wulf Community Admin
The IPlayer is only available for BasePlayer, so make sure to cast and check that for null first.
-
Code:if (attacker == null) return; if (victim == null) return; if (attacker == victim) return;
-
Wulf Community Admin
-