From 808ef129f1dae62000db3c793b64d8db6556f09f Mon Sep 17 00:00:00 2001 From: lukealford Date: Mon, 2 Oct 2023 00:29:48 +1100 Subject: [PATCH] fix(game/sounds): release sound ids --- apps/game/client/sounds/client-sound.class.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/game/client/sounds/client-sound.class.ts b/apps/game/client/sounds/client-sound.class.ts index c01165a35..8a9180b77 100644 --- a/apps/game/client/sounds/client-sound.class.ts +++ b/apps/game/client/sounds/client-sound.class.ts @@ -1,3 +1,4 @@ +const SoundIdsByName: { [k: string]: number } = {}; export class Sound { private readonly _soundName: string; private readonly _soundSetName: string; @@ -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]; } }