diff --git a/lua/entities/gmod_wire_expression2/core/sound.lua b/lua/entities/gmod_wire_expression2/core/sound.lua index 4b38944c3c..19554eb09e 100644 --- a/lua/entities/gmod_wire_expression2/core/sound.lua +++ b/lua/entities/gmod_wire_expression2/core/sound.lua @@ -303,6 +303,20 @@ local function EmitSound(e2, ent, snd, level, pitch, volume) level = maxlevel end + local emitting_sounds = ent:GetVar("E2_emitting_sounds", {}) + emitting_sounds[snd] = math.min((emitting_sounds[snd] or 0) + 1, 32) + ent:SetVar("E2_emitting_sounds", emitting_sounds) + + ent:CallOnRemove("E2_EmitSound_stop_all", function() + local emitting_sounds = ent:GetVar("E2_emitting_sounds") + if not emitting_sounds then return end + for snd, count in pairs(emitting_sounds) do + for i = 1, count do + ent:StopSound(snd) + end + end + end) + ent:EmitSound(snd, level, pitch, volume) end