From 4347c8a48bd2910c1a461a9423848c11ab053ae0 Mon Sep 17 00:00:00 2001 From: thecraftianman <64441307+thecraftianman@users.noreply.github.com> Date: Fri, 19 Jan 2024 17:51:47 -0500 Subject: [PATCH] Attempt at ratelimiting certain spammy sounds --- lua/acf/core/utilities/sounds/sounds_sv.lua | 22 +++++++++++------ lua/weapons/acf_torch/shared.lua | 27 +++++++++++++++++++-- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/lua/acf/core/utilities/sounds/sounds_sv.lua b/lua/acf/core/utilities/sounds/sounds_sv.lua index 1099045a5..5ef5d67b9 100644 --- a/lua/acf/core/utilities/sounds/sounds_sv.lua +++ b/lua/acf/core/utilities/sounds/sounds_sv.lua @@ -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 \ No newline at end of file diff --git a/lua/weapons/acf_torch/shared.lua b/lua/weapons/acf_torch/shared.lua index 68e251749..f82d9216f 100644 --- a/lua/weapons/acf_torch/shared.lua +++ b/lua/weapons/acf_torch/shared.lua @@ -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 @@ -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 @@ -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