@@ -35,6 +35,18 @@ type Player struct {
3535 IsUnknown bool // Used to identify unknown/broken players. see https://github.com/markus-wa/demoinfocs-golang/issues/162
3636}
3737
38+ func (p * Player ) PlayerPawnEntity () st.Entity {
39+ return p .demoInfoProvider .FindEntityByHandle (p .Entity .PropertyValueMust ("m_hPlayerPawn" ).Handle ())
40+ }
41+
42+ func (p * Player ) GetTeam () Team {
43+ return Team (p .PlayerPawnEntity ().PropertyValueMust ("m_iTeamNum" ).S2UInt64 ())
44+ }
45+
46+ func (p * Player ) GetFlashDuration () float32 {
47+ return p .PlayerPawnEntity ().PropertyValueMust ("m_flFlashDuration" ).Float ()
48+ }
49+
3850// String returns the player's name.
3951// Implements fmt.Stringer.
4052func (p * Player ) String () string {
@@ -53,6 +65,12 @@ func (p *Player) SteamID32() uint32 {
5365
5466// IsAlive returns true if the player is alive.
5567func (p * Player ) IsAlive () bool {
68+ s2IsAlive := p .Entity .Property ("m_bPawnIsAlive" )
69+
70+ if s2IsAlive != nil {
71+ return s2IsAlive .Value ().BoolVal ()
72+ }
73+
5674 return p .Health () > 0 || getInt (p .Entity , "m_lifeState" ) == 0
5775}
5876
@@ -245,6 +263,12 @@ func (p *Player) ControlledBot() *Player {
245263
246264// Health returns the player's health points, normally 0-100.
247265func (p * Player ) Health () int {
266+ s2Prop := p .Entity .Property ("m_iPawnHealth" )
267+
268+ if s2Prop != nil {
269+ return int (s2Prop .Value ().S2UInt64 ())
270+ }
271+
248272 return getInt (p .Entity , "m_iHealth" )
249273}
250274
@@ -501,6 +525,7 @@ type demoInfoProvider interface {
501525 FindPlayerByHandle (handle int ) * Player
502526 PlayerResourceEntity () st.Entity
503527 FindWeaponByEntityID (id int ) * Equipment
528+ FindEntityByHandle (handle uint64 ) st.Entity
504529}
505530
506531// NewPlayer creates a *Player with an initialized equipment map.
0 commit comments