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
18 changes: 11 additions & 7 deletions lua/entities/gmod_wire_expression2/core/sound.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 9 additions & 19 deletions lua/entities/gmod_wire_thruster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
function ENT:Think()
BaseClass.Think(self)

self.ShouldDraw = GetConVarNumber("cl_drawthrusterseffects")

Check warning on line 53 in lua/entities/gmod_wire_thruster.lua

View workflow job for this annotation

GitHub Actions / lint

"Deprecated"

Deprecated: Use ConVar objects instead

if self.ShouldDraw == 0 or not self:IsOn() then return end

Expand Down Expand Up @@ -97,13 +97,13 @@

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
Expand Down Expand Up @@ -180,27 +180,17 @@
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)
if (iname == "A") then
if ( (self.bidir) and (math.abs(value) > 0.01) and (math.abs(value) > self.force_min) ) or ( (value > 0.01) and (value > self.force_min) ) then

Check warning on line 193 in lua/entities/gmod_wire_thruster.lua

View workflow job for this annotation

GitHub Actions / lint

"Unnecessary parentheses"

Unnecessary parentheses
self:Switch(true, math.min(value, self.force_max))
else
self:Switch(false, 0)
Expand Down Expand Up @@ -252,7 +242,7 @@


if (on) then
if (changed) and (self.soundname and self.soundname ~= "") then
if (changed) and self.soundname then

Check warning on line 245 in lua/entities/gmod_wire_thruster.lua

View workflow job for this annotation

GitHub Actions / lint

"Unnecessary parentheses"

Unnecessary parentheses
self:StopSound( self.soundname )
self:EmitSound( self.soundname )
end
Expand All @@ -261,7 +251,7 @@

self:SetForce( nil, mul )
else
if (self.soundname and self.soundname ~= "") then
if self.soundname then
self:StopSound( self.soundname )
end

Expand Down
8 changes: 4 additions & 4 deletions lua/entities/gmod_wire_turret.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
27 changes: 12 additions & 15 deletions lua/entities/gmod_wire_vectorthruster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
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
Expand Down Expand Up @@ -71,7 +71,7 @@
function ENT:Think()
BaseClass.Think(self)

self.ShouldDraw = GetConVarNumber("cl_drawthrusterseffects")

Check warning on line 74 in lua/entities/gmod_wire_vectorthruster.lua

View workflow job for this annotation

GitHub Actions / lint

"Deprecated"

Deprecated: Use ConVar objects instead

if self.ShouldDraw == 0 or not self:IsOn() then return end

Expand Down Expand Up @@ -128,13 +128,13 @@

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
Expand Down Expand Up @@ -195,18 +195,15 @@
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
Expand Down
Loading