Skip to content
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

Added CallOnRemove on entity to stop emitting sound on entity deletion #2952

Closed
wants to merge 4 commits into from
Closed
Changes from 2 commits
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
12 changes: 12 additions & 0 deletions lua/entities/gmod_wire_expression2/core/sound.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
end

local function soundCreate(self, entity, index, time, path, fade)
if path:match('["?]') then return end

Check warning on line 74 in lua/entities/gmod_wire_expression2/core/sound.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of 'single quoted strings' and 'double quoted strings'
local data = self.data.sound_data
if not isAllowed( self ) then return end

Expand Down Expand Up @@ -303,6 +303,18 @@
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")
if not emitting_sounds then return end
for _, snd in ipairs(emitting_sounds) do
ent:StopSound(snd)
end
end)

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

Expand Down
Loading