Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 2 additions & 20 deletions lua/entities/gmod_wire_expression2/core/sound.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ E2Lib.RegisterExtension("sound", true, "Allows E2s to play sounds.", "Sounds can
local wire_expression2_maxsounds = CreateConVar( "wire_expression2_maxsounds", 16, {FCVAR_ARCHIVE} )
local wire_expression2_sound_burst_max = CreateConVar( "wire_expression2_sound_burst_max", 8, {FCVAR_ARCHIVE} )
local wire_expression2_sound_burst_rate = CreateConVar( "wire_expression2_sound_burst_rate", 0.1, {FCVAR_ARCHIVE} )
local wire_sound_max_level = GetConVar( "wire_sound_max_level" )

---------------------------------------------------------------
-- Helper functions
Expand Down Expand Up @@ -239,15 +238,7 @@ e2function void soundLevel( index, level )

-- We need to set the level while the sound is stopped
sound:Stop()

local max_level = wire_sound_max_level:GetInt()

-- 0 = play sound throughout the map
if max_level ~= -1 and (level == 0 or level > max_level) then
level = max_level
end

sound:SetSoundLevel(level)
sound:SetSoundLevel(WireLib.ClampSoundLevel(level))
sound:Play()
end
e2function void soundLevel( string index, level ) = e2function void soundLevel( index, level )
Expand Down Expand Up @@ -304,19 +295,10 @@ local function EmitSound(e2, ent, path, level, pitch, volume)
if not IsValid(ent) then return e2:throw("Invalid entity!", nil) end
if not isOwner(e2, ent) then return e2:throw("You do not own this entity!", nil) end

if level then
local max_level = wire_sound_max_level:GetInt()

-- 0 = play sound throughout the map
if max_level ~= -1 and (level == 0 or level > max_level) then
level = max_level
end
end

path = WireLib.SoundExists(path)
if not path then return end

ent:EmitSound(path, level, pitch, volume)
ent:EmitSound(path, WireLib.ClampSoundLevel(level or SNDLVL_75dB), pitch, volume)
end

__e2setcost(20)
Expand Down
3 changes: 2 additions & 1 deletion lua/entities/gmod_wire_soundemitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,10 @@ function ENT:UpdateSound()

if self.Active then self:StartSounds() end
end

self.SoundObj:ChangePitch(math.Clamp(self.Pitch, 0, 255), 0)
self.SoundObj:ChangeVolume(math.Clamp(self.Volume / 100, 0, 1), 0)
self.SoundObj:SetSoundLevel(math.Clamp(self.Level, 55, 165))
self.SoundObj:SetSoundLevel(WireLib.ClampSoundLevel(self.Level))
end

function ENT:SetSound(soundName)
Expand Down
20 changes: 15 additions & 5 deletions lua/wire/server/wirelib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1581,8 +1581,18 @@ if not WireLib.PatchedDuplicator then
end

local uniqueSoundsTbl = setmetatable({}, {__index=function(t,k) local r={[1]=0} t[k]=r return r end})
local maxUniqueSounds = CreateConVar("wire_sounds_unique_max", "200", FCVAR_ARCHIVE, "The maximum number of sound paths a player is allowed to cache")
local maxSoundLevel = CreateConVar("wire_sound_max_level", "180", FCVAR_ARCHIVE, "The maximum sounds volume (-1 disable)")
local maxUniqueSounds = CreateConVar("wire_sounds_unique_max", "200", FCVAR_ARCHIVE, "The maximum number of sound paths a player is allowed to cache", 0)
local maxSoundLevel = CreateConVar("wire_sound_max_level", "255", FCVAR_ARCHIVE, "The maximum sounds volume (0 to disable)", 0, 255)

function WireLib.ClampSoundLevel(level)
local max_level = maxSoundLevel:GetInt()

if max_level > 0 then
return level <= 0 and max_level or math.min(level, max_level)
else
return level
end
end

function WireLib.SoundExists(path, ply)
-- Limit length and remove invalid chars
Expand All @@ -1598,14 +1608,14 @@ function WireLib.SoundExists(path, ply)
-- Disallow too loud sounds
local max_level = maxSoundLevel:GetInt()

if max_level ~= -1 then
if max_level > 0 then
local sound_data = sound.GetProperties(checkpath)

if sound_data then
local sound_level = sound_data.level

-- 0 = play sound throughout the map
if sound_level <= 0 then
-- We can't clamp soundlevel of soundscript, take it's sound directly
if sound_level <= 0 or sound_level > max_level then
local sounds = sound_data.sound
path = istable(sounds) and sounds[math.random(#sounds)] or sounds
end
Expand Down
Loading