LLB Baseball: Support new AirShake parameter in util.ScreenShake

(cherry picked from commit 7ebd38618b2116a98291037137d73d962cb75e3b)
This commit is contained in:
Chev 2023-09-18 20:35:35 -07:00
parent 65135fc10e
commit 6a6db8fa01
Signed by: chev2
GPG key ID: BE0CFBD5DCBB2511
2 changed files with 29 additions and 5 deletions

View file

@ -80,3 +80,13 @@ net.Receive("llb_baseball.DrawInvertedColors", function()
end)
end
end)
net.Receive("llb_baseball.ScreenShake", function()
local pos = net.ReadVector()
local amplitude = net.ReadUInt(8)
local frequency = net.ReadUInt(8)
local duration = net.ReadFloat()
local radius = net.ReadFloat()
util.ScreenShake(pos, amplitude, frequency, duration, radius, true)
end)

View file

@ -11,6 +11,7 @@ ENT.ServingPitch = false
util.AddNetworkString("llb_baseball.DrawInvertedColors")
util.AddNetworkString("llb_baseball.ChangeBallColor")
util.AddNetworkString("llb_baseball.ScreenShake")
local NEW_VEL_VECTOR = Vector()
@ -80,7 +81,7 @@ function ENT:PhysicsCollide(data, physobj)
if data.DeltaTime > 0.02 then
sound.Play(self.BounceSound, self:GetPos(), 80, 100, 1)
util.ScreenShake(self:GetPos(), 2, 4, 0.2, 1500)
self:ScreenShake(2, 4, 0.2, 1500)
end
end
@ -162,13 +163,13 @@ function ENT:OnTakeDamage(dmginfo)
net.SendPVS(self:GetPos())
sound.Play(self.StrongHitSound, self:GetPos(), 80, 100, 1)
util.ScreenShake(self:GetPos(), 25, 4, ballPauseTime, 300)
self:ScreenShake(25, 4, ballPauseTime, 300)
elseif speed > 500 then
sound.Play(self.StrongHitSound, self:GetPos(), 80, 100, 1)
util.ScreenShake(self:GetPos(), 20, 4, ballPauseTime, 300)
self:ScreenShake(20, 4, ballPauseTime, 300)
else
sound.Play(self.HitSound, self:GetPos(), 80, speed * 0.0295 + 100, 1)
util.ScreenShake(self:GetPos(), 2, 4, ballPauseTime, 300)
self:ScreenShake(2, 4, ballPauseTime, 300)
end
-- Lock the player until ball unfreezes.
@ -214,7 +215,7 @@ function ENT:StartTouch(ent)
dmginf:SetDamageForce(Vector(0, 0, 1))
ent:TakeDamageInfo(dmginf)
util.ScreenShake(self:GetPos(), 2, 30, 0.5, 300)
self:ScreenShake(2, 30, 0.5, 300)
-- If player is still alive after taking damage
if ent:Health() > 0 then
@ -232,3 +233,16 @@ function ENT:StartTouch(ent)
end
end
end
function ENT:ScreenShake(amplitude, frequency, duration, radius)
--util.ScreenShake(self:GetPos(), amplitude, frequency, duration, radius, true)
-- New AirShake parameter only works on clientside at the moment, so we have to network it
net.Start("llb_baseball.ScreenShake")
net.WriteVector(self:GetPos())
net.WriteUInt(amplitude, 8)
net.WriteUInt(frequency, 8)
net.WriteFloat(duration)
net.WriteFloat(radius)
net.SendPVS(self:GetPos())
end