Skip to content

feat: implement player_sound event #535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/demoinfocs/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ type PlayerJump struct {
Player *common.Player // May be nil if the demo is partially corrupt (player is 'unconnected', see #156 and #172).
}

// PlayerSound signals that a player emitted a sound.
type PlayerSound struct {
Player *common.Player
Radius int
Duration time.Duration
}

// Kill signals that a player has been killed.
type Kill struct {
Weapon *common.Equipment
Expand Down
11 changes: 10 additions & 1 deletion pkg/demoinfocs/game_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package demoinfocs

import (
"fmt"
"time"

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

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

func (geh gameEventHandler) playerSound(data map[string]*msg.CSVCMsg_GameEventKeyT) {
geh.dispatch(events.PlayerSound{
Player: geh.playerByUserID32(data["userid"].GetValShort()),
Radius: int(data["radius"].GetValLong()),
Duration: time.Duration(data["duration"].GetValFloat() * float32(time.Second)),
})
}

func (geh gameEventHandler) weaponFire(data map[string]*msg.CSVCMsg_GameEventKeyT) {
if geh.parser.isSource2() && !geh.parser.disableMimicSource1GameEvents {
return
Expand Down
Loading