Skip to content

Commit

Permalink
fix(game/sounds): release sound ids (#1078)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukealford authored Oct 22, 2023
1 parent 7c96bec commit c24374e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion apps/game/client/sounds/client-sound.class.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const SoundIdsByName: { [k: string]: number } = {};
export class Sound {
private readonly _soundName: string;
private readonly _soundSetName: string;
Expand All @@ -7,15 +8,22 @@ export class Sound {
this._soundName = soundName;
this._soundSetName = soundSetName;

if (SoundIdsByName[this._soundName]) {
ReleaseSoundId(SoundIdsByName[this._soundName]);
delete SoundIdsByName[this._soundName];
}

this._soundId = GetSoundId();
SoundIdsByName[this._soundName] = this._soundId;
}

play() {
PlaySoundFrontend(this._soundId, this._soundName, this._soundSetName, false);
PlaySoundFromEntity(this._soundId, this._soundName, PlayerPedId(), this._soundSetName, true, 0);
}

stop() {
StopSound(this._soundId);
ReleaseSoundId(this._soundId);
if (SoundIdsByName[this._soundName]) delete SoundIdsByName[this._soundName];
}
}

0 comments on commit c24374e

Please sign in to comment.