Skip to content

Commit

Permalink
Added CallOnRemove on entity to stop emiting sound
Browse files Browse the repository at this point in the history
  • Loading branch information
cryx3001 committed Dec 22, 2023
1 parent 67e3cbc commit 0de76f1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lua/entities/gmod_wire_expression2/core/sound.lua
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,17 @@ local function EmitSound(e2, ent, snd, level, pitch, volume)
level = maxlevel
end

local emitting_sounds = ent:GetVar("E2_emitting_sounds", {})
table.insert(emitting_sounds, snd)
ent:SetVar("E2_emitting_sounds", emitting_sounds)

ent:CallOnRemove("E2_EmitSound_stop_all", function()
local emitting_sounds = ent:GetVar("E2_emitting_sounds", {})
for _, snd in pairs(emitting_sounds) do
ent:StopSound(snd)
end
end)

ent:EmitSound(snd, level, pitch, volume)
end

Expand Down

0 comments on commit 0de76f1

Please sign in to comment.