Skip to content

Commit c1e18e8

Browse files
authored
Merge pull request #535 from mateusmaia/master
feat: implement player_sound event
2 parents 3cd3eb4 + b12aa13 commit c1e18e8

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

pkg/demoinfocs/events/events.go

+7
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

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package demoinfocs
33
import (
44
"fmt"
55
"math"
6+
"time"
67

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

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

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

0 commit comments

Comments
 (0)