Skip to content

Commit 161bb23

Browse files
authored
Add Player.CrosshairCode() to pull players current crosshair code (#274)
1 parent 51e7026 commit 161bb23

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

pkg/demoinfocs/common/player.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,18 @@ func (p *Player) ClanTag() string {
375375
return getString(p.resourceEntity(), "m_szClan."+p.entityIDStr())
376376
}
377377

378+
// CrosshairCode returns the player's crosshair code or an empty string if there isn't one.
379+
func (p *Player) CrosshairCode() string {
380+
if p.resourceEntity() == nil {
381+
return ""
382+
}
383+
384+
// if the property doesn't exist we return empty string by default
385+
val, _ := p.resourceEntity().PropertyValue("m_szCrosshairCodes." + p.entityIDStr())
386+
387+
return val.StringVal
388+
}
389+
378390
// Ping returns the players latency to the game server.
379391
func (p *Player) Ping() int {
380392
return getInt(p.resourceEntity(), "m_iPing."+p.entityIDStr())

pkg/demoinfocs/common/player_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,18 @@ func TestPlayer_ClanTag(t *testing.T) {
377377
assert.Equal(t, "SuperClan", pl.ClanTag())
378378
}
379379

380+
func TestPlayer_CrosshairCode(t *testing.T) {
381+
pl := playerWithResourceProperty("m_szCrosshairCodes", st.PropertyValue{StringVal: "CSGO-jvnbx-S3xFK-iEJXD-Y27Nd-AO6FP"})
382+
383+
assert.Equal(t, "CSGO-jvnbx-S3xFK-iEJXD-Y27Nd-AO6FP", pl.CrosshairCode())
384+
}
385+
386+
func TestPlayer_WithoutCrosshairCode(t *testing.T) {
387+
pl := newPlayer(0)
388+
389+
assert.Equal(t, pl.CrosshairCode(), "")
390+
}
391+
380392
func TestPlayer_Ping(t *testing.T) {
381393
pl := playerWithResourceProperty("m_iPing", st.PropertyValue{IntVal: 45})
382394

0 commit comments

Comments
 (0)