Skip to content

Commit

Permalink
Attempt at ratelimiting certain spammy sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
thecraftianman committed Jan 19, 2024
1 parent 001e193 commit 4347c8a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
22 changes: 14 additions & 8 deletions lua/acf/core/utilities/sounds/sounds_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,19 @@ function Sounds.SendAdjustableSound(Origin, ShouldStop, Pitch, Volume)
if not IsValid(Origin) then return end

ShouldStop = ShouldStop or false

net.Start("ACF_Sounds_Adjustable")
net.WriteEntity(Origin)
net.WriteBool(ShouldStop)
if not ShouldStop then
net.WriteUInt(Pitch, 8)
net.WriteFloat(Volume)
local Time = CurTime()
Origin.ACF.SoundTimer = Origin.ACF.SoundTimer or Time

-- Slowing down the rate of sending a bit
if Origin.ACF.SoundTimer <= Time or ShouldStop then
net.Start("ACF_Sounds_Adjustable")
net.WriteEntity(Origin)
net.WriteBool(ShouldStop)
if not ShouldStop then
net.WriteUInt(Pitch, 8)
net.WriteFloat(Volume)
end
net.SendPAS(Origin:GetPos())
Origin.ACF.SoundTimer = Time + 0.1
end
net.SendPAS(Origin:GetPos())
end
27 changes: 25 additions & 2 deletions lua/weapons/acf_torch/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,14 @@ function SWEP:PrimaryAttack()
Effect:SetEntity(self)
util.Effect("thruster_ring", Effect, true, true)

Sounds.SendSound(self, "items/medshot4.wav", nil, nil, 1)
-- Sound ratelimiting
local Time = CurTime()
self.SoundTimer = self.SoundTimer or Time

if self.SoundTimer <= Time then
Sounds.SendSound(self, "items/medshot4.wav", nil, nil, 1)
self.SoundTimer = Time + 0.1
end
else
local OldHealth = Entity.ACF.Health
local MaxHealth = Entity.ACF.MaxHealth
Expand All @@ -269,6 +276,15 @@ function SWEP:PrimaryAttack()

Sounds.SendSound(self, Spark:format(math.random(3, 5)), nil, nil, 1)
TeslaSpark(Trace.HitPos, 1)

-- Sound ratelimiting
local Time = CurTime()
self.SoundTimer = self.SoundTimer or Time

if self.SoundTimer <= Time then
Sounds.SendSound(self, Spark:format(math.random(3, 5)), nil, nil, 1)
self.SoundTimer = Time + 0.1
end
end
end

Expand Down Expand Up @@ -334,7 +350,14 @@ function SWEP:SecondaryAttack()

util.Effect("Sparks", Effect, true, true)

Sounds.SendSound(Entity, Zap:format(math.random(1, 4)), nil, nil, 1)
-- Sound ratelimiting
local Time = CurTime()
self.SoundTimer = self.SoundTimer or Time

if self.SoundTimer <= Time then
Sounds.SendSound(Entity, Zap:format(math.random(1, 4)), nil, nil, 1)
self.SoundTimer = Time + 0.1
end
end
end
end

0 comments on commit 4347c8a

Please sign in to comment.