Skip to content

Commit 414eb7a

Browse files
committed
feat: implement support for player_sound event
1 parent 059aadc commit 414eb7a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

pkg/demoinfocs/events/events.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ type PlayerJump struct {
148148
Player *common.Player // May be nil if the demo is partially corrupt (player is 'unconnected', see #156 and #172).
149149
}
150150

151+
// PlayerSound signals that a player emitted a sound.
152+
type PlayerSound struct {
153+
Player *common.Player
154+
Radius int
155+
Duration time.Duration
156+
}
157+
151158
// Kill signals that a player has been killed.
152159
type Kill struct {
153160
Weapon *common.Equipment

pkg/demoinfocs/game_events.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package demoinfocs
22

33
import (
44
"fmt"
5+
"time"
56

67
"github.com/golang/geo/r3"
78
"github.com/markus-wa/go-unassert"
@@ -256,7 +257,7 @@ func newGameEventHandler(parser *parser, ignoreBombsiteIndexNotFound bool) gameE
256257
"player_given_c4": nil, // Dunno, only present in locally recorded (POV) demos
257258
"player_ping": nil, // When a player uses the "ping system" added with the operation Broken Fang, only present in locally recorded (POV) demos
258259
"player_ping_stop": nil, // When a player's ping expired, only present in locally recorded (POV) demos
259-
"player_sound": nil, // When a player makes a sound. TODO: implement player_sound
260+
"player_sound": delayIfNoPlayers(geh.playerSound), // When a player makes a sound
260261

261262
// Player changed team. Delayed for two reasons
262263
// - team IDs of other players changing teams in the same tick might not have changed yet
@@ -419,6 +420,14 @@ func (geh gameEventHandler) playerJump(data map[string]*msg.CSVCMsg_GameEventKey
419420
})
420421
}
421422

423+
func (geh gameEventHandler) playerSound(data map[string]*msg.CSVCMsg_GameEventKeyT) {
424+
geh.dispatch(events.PlayerSound{
425+
Player: geh.playerByUserID32(data["userid"].GetValShort()),
426+
Radius: int(data["radius"].GetValLong()),
427+
Duration: time.Duration(data["duration"].GetValFloat() * float32(time.Second)),
428+
})
429+
}
430+
422431
func (geh gameEventHandler) weaponFire(data map[string]*msg.CSVCMsg_GameEventKeyT) {
423432
if geh.parser.isSource2() && !geh.parser.disableMimicSource1GameEvents {
424433
return

0 commit comments

Comments
 (0)