diff --git a/lua/entities/gmod_wire_expression2/core/sound.lua b/lua/entities/gmod_wire_expression2/core/sound.lua index feb189a8a4..2f0345e8ac 100644 --- a/lua/entities/gmod_wire_expression2/core/sound.lua +++ b/lua/entities/gmod_wire_expression2/core/sound.lua @@ -292,19 +292,23 @@ e2function number soundPlaying( string index ) = e2function number soundPlaying( -- EmitSound -local function EmitSound(e2, ent, snd, level, pitch, volume) +local function EmitSound(e2, ent, path, level, pitch, volume) if not isAllowed(e2) then return end - 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 - local maxlevel = wire_expression2_sound_level_max:GetInt() - if level ~= nil and level > maxlevel then - level = maxlevel + if level then + local max_level = wire_expression2_sound_level_max:GetInt() + + -- 0 = play sound throughout the map + if max_level ~= -1 and (level == 0 or level > max_level) then + level = max_level + end end - snd = string.sub(snd, 1, 260) - if snd:match('["?]') then return end + path = WireLib.SoundExists(path) + if not path then return end + ent:EmitSound(snd, level, pitch, volume) end diff --git a/lua/entities/gmod_wire_thruster.lua b/lua/entities/gmod_wire_thruster.lua index 6677931e8c..51130ab084 100644 --- a/lua/entities/gmod_wire_thruster.lua +++ b/lua/entities/gmod_wire_thruster.lua @@ -97,13 +97,13 @@ function ENT:Initialize() self.Inputs = Wire_CreateInputs(self, { "A" }) - self.soundname = Sound( "PhysicsCannister.ThrusterLoop" ) + self.soundname = "PhysicsCannister.ThrusterLoop" end function ENT:OnRemove() BaseClass.OnRemove(self) - if (self.soundname and self.soundname ~= "") then + if self.soundname then self:StopSound(self.soundname) end end @@ -180,22 +180,12 @@ function ENT:Setup(force, force_min, force_max, oweffect, uweffect, owater, uwat self.owater = owater self.uwater = uwater - if (not soundname) then soundname = "" end - - -- Preventing client crashes - local BlockedChars = '["?]' - if ( string.find(soundname, BlockedChars) ) then - self:StopSound( self.SoundName ) - soundname = "" - end - - if (soundname == "") then - self:StopSound( self.soundname ) + if soundname and soundname ~= "" then + self.soundname = WireLib.SoundExists(soundname) + else + self:StopSound( self.soundname or "" ) + self.soundname = nil end - - self.soundname = Sound( soundname ) - - --self:SetOverlayText( "Thrust = " .. 0 .. "\nMul: " .. math.Round(force*1000)/1000 ) end function ENT:TriggerInput(iname, value) @@ -252,7 +242,7 @@ function ENT:Switch( on, mul ) if (on) then - if (changed) and (self.soundname and self.soundname ~= "") then + if (changed) and self.soundname then self:StopSound( self.soundname ) self:EmitSound( self.soundname ) end @@ -261,7 +251,7 @@ function ENT:Switch( on, mul ) self:SetForce( nil, mul ) else - if (self.soundname and self.soundname ~= "") then + if self.soundname then self:StopSound( self.soundname ) end diff --git a/lua/entities/gmod_wire_turret.lua b/lua/entities/gmod_wire_turret.lua index f2805a55bc..fc93a4f3d7 100644 --- a/lua/entities/gmod_wire_turret.lua +++ b/lua/entities/gmod_wire_turret.lua @@ -114,10 +114,10 @@ local ValidTracers = { [""] = true } -function ENT:SetSound( sound ) - sound = string.Trim( tostring( sound or "" ) ) -- Remove whitespace ( manual ) - local check = string.find( sound, "[\"?]" ) -- Preventing client crashes - self.sound = check == nil and sound ~= "" and sound or nil -- Apply the pattern check +function ENT:SetSound( path ) + if path then + self.sound = WireLib.SoundExists(path) + end end function ENT:SetDelay( delay ) diff --git a/lua/entities/gmod_wire_vectorthruster.lua b/lua/entities/gmod_wire_vectorthruster.lua index 1ed9543778..523d2eaa61 100644 --- a/lua/entities/gmod_wire_vectorthruster.lua +++ b/lua/entities/gmod_wire_vectorthruster.lua @@ -15,12 +15,12 @@ end function ENT:SetOn( boolon ) if (self:IsOn() ~= boolon) then if (boolon) then - if (self.soundname and self.soundname ~= "") then + if self.soundname then self:StopSound( self.soundname ) self:EmitSound( self.soundname ) end else - if (self.soundname and self.soundname ~= "") then + if self.soundname then self:StopSound( self.soundname ) end end @@ -128,13 +128,13 @@ function ENT:Initialize() self.Inputs = Wire_CreateInputs(self, { "Mul" }) - self.soundname = Sound( "PhysicsCannister.ThrusterLoop" ) + self.soundname = "PhysicsCannister.ThrusterLoop" end function ENT:OnRemove() BaseClass.OnRemove(self) - if (self.soundname) then + if self.soundname then self:StopSound(self.soundname) end end @@ -195,18 +195,15 @@ function ENT:Setup(force, force_min, force_max, oweffect, uweffect, owater, uwat self.angleinputs = angleinputs self.lengthismul = lengthismul - -- Preventing client crashes - local BlockedChars = "[\"?]" - if ( string.find(soundname, BlockedChars) ) then - soundname = "" - end - - if (soundname and soundname == "" and self.soundname and self.soundname ~= "") then - self:StopSound(self.soundname) - end + if soundname and soundname ~= "" then + self.soundname = WireLib.SoundExists(soundname) - if (soundname) then - self.soundname = Sound(soundname) + if self.soundname then + self:StopSound(self.soundname) + end + else + self:StopSound( self.soundname or "" ) + self.soundname = nil end self.mode = mode or 0