CopsNRobbers/gamemodes/copsnrobbers/entities/weapons/cnr/sh_think.lua

63 lines
2.0 KiB
Lua
Raw Permalink Normal View History

2023-12-21 13:58:05 -05:00
SWEP.RecoilTable = {}
function SWEP:Think()
local p = self:GetOwner()
if CLIENT and IsFirstTimePredicted() then
2023-12-21 16:15:25 -05:00
for i, data in pairs( self.RecoilTable ) do
local ft = FrameTime()
local diff = data.dist - math.Approach( data.dist, 0, ft * data.speed )
data.dist = math.Approach( data.dist, 0, ft * data.speed )
2023-12-21 16:15:25 -05:00
local m_p, m_y = math.cos(math.rad(data.up)), math.sin(math.rad(data.up))
local p_p, p_y = m_p * diff, m_y * diff
2023-12-21 16:15:25 -05:00
p:SetEyeAngles( p:EyeAngles() - Angle( p_p, p_y, 0 ) )
if data.up2 then
if data.dist == 0 then
local diff = data.dist2 - math.Approach( data.dist2, 0, ft * data.speed2 )
data.dist2 = math.Approach( data.dist2, 0, ft * data.speed2 )
local m_p, m_y = math.cos(math.rad(data.up2)), math.sin(math.rad(data.up2))
local p_p, p_y = m_p * diff, m_y * diff
p:SetEyeAngles( p:EyeAngles() - Angle( p_p, p_y, 0 ) )
end
if data.dist2 == 0 then
self.RecoilTable[i] = nil
end
else
if data.dist == 0 then
self.RecoilTable[i] = nil
end
2023-12-21 16:15:25 -05:00
end
2023-12-21 13:58:05 -05:00
end
end
if !p:KeyDown( IN_ATTACK ) then
self:SetBurstCount( 0 )
end
2023-12-21 16:15:25 -05:00
local up = self:GetDelay() > CurTime()-engine.TickInterval()
self:SetBubbleSpread( math.Approach( self:GetBubbleSpread(), up and 1 or 0, FrameTime()/(up and self.BubbleSpreadUp or self.BubbleSpreadDown) ) )
self:SetBubbleRecoil( math.Approach( self:GetBubbleRecoil(), up and 1 or 0, FrameTime()/(up and self.BubbleRecoilUp or self.BubbleRecoilDown) ) )
if self:GetRefillTime() != -1 and CurTime() >= self:GetRefillTime() then
2023-12-22 09:07:47 -05:00
self:SetClip1( self.ShotgunReloading and (self:Clip1() + 1) or self.Primary.ClipSize )
self:SetRefillTime( -1 )
end
2023-12-22 09:07:47 -05:00
if self:GetShotgunReloading() == 1 then
if p:KeyDown( IN_ATTACK ) or (self:GetDelayReload() <= CurTime() and self:Clip1() == self.Primary.ClipSize) then
2024-07-18 17:27:46 -04:00
self:SendAnim( "reload_start" )
2023-12-22 09:07:47 -05:00
self:SetRefillTime( -1 )
self:SetShotgunReloading( 0 )
else
if self:GetDelayReload() <= CurTime() then
2024-07-18 17:27:46 -04:00
self:SendAnim( "reload" )
2023-12-22 09:07:47 -05:00
end
end
end
2023-12-21 13:58:05 -05:00
end