Benny/gamemodes/benny/entities/weapons/benny/sh_firing.lua

153 lines
3.8 KiB
Lua
Raw Normal View History

2023-10-31 19:05:52 -04:00
2023-11-18 00:29:04 -05:00
function SWEP:PrimaryAttack()
2023-11-29 18:00:08 -05:00
local dual = self:C_DualCheck()
2023-11-29 02:45:36 -05:00
if dual then
self:BFire( true )
else
self:BFire( false )
end
2023-11-18 00:29:04 -05:00
return true
end
function SWEP:SecondaryAttack()
2023-11-29 18:00:08 -05:00
local dual = self:C_DualCheck()
2023-11-29 02:45:36 -05:00
if dual then
self:BFire( false )
else
self:BFire( true )
end
2023-11-18 00:29:04 -05:00
return true
end
function SWEP:BFire( hand )
if self:BTable( hand ) then
2023-11-18 00:29:04 -05:00
local p = self:GetOwner()
local wep_table = self:BTable( hand )
local wep_class = self:BClass( hand )
2023-11-18 00:29:04 -05:00
if wep_class.Custom_Fire then
if wep_class.Custom_Fire( self, wep_table, wep_class, hand ) then return end
end
if self:D_GetDelay( hand ) > CurTime() then
return
end
if self:D_GetClip( hand ) == 0 then
2023-11-29 02:54:21 -05:00
if self:D_GetBurst( hand ) >= 1 then
return
end
B_Sound( self, wep_class.Sound_DryFire )
2023-11-29 02:54:21 -05:00
self:D_SetBurst( hand, self:D_GetBurst( hand ) + 1 )
return
end
if self:D_GetBurst( hand ) >= self:B_Firemode( hand ).Mode then
return
end
self:B_Ammo( hand, self:D_GetClip( hand ) - 1 )
B_Sound( self, wep_class.Sound_Fire )
2023-11-29 02:45:36 -05:00
self:TPFire( hand )
self:CallFire( hand )
self:D_SetDelay( hand, CurTime() + wep_class.Delay )
self:D_SetBurst( hand, self:D_GetBurst( hand ) + 1 )
2023-11-18 00:29:04 -05:00
if CLIENT and IsFirstTimePredicted() then
2023-11-18 03:40:31 -05:00
if IsValid(self.CWM) then
local vStart = self.CWM:GetAttachment( 1 ).Pos
--local vPoint = p:GetEyeTrace().HitPos
--local effectdata = EffectData()
--effectdata:SetStart( vStart )
--effectdata:SetOrigin( vPoint )
--util.Effect( "ToolTracer", effectdata )
local ed = EffectData()
ed:SetOrigin( vStart )
--ed:SetAngles( Angle() )
ed:SetEntity( self )
ed:SetAttachment( 1 )
util.Effect( "benny_muzzleflash", ed )
end
2023-11-18 00:29:04 -05:00
end
end
end
function SWEP:CallFire( hand )
local p = self:GetOwner()
local class = self:BClass( hand )
2023-10-31 19:05:52 -04:00
local spread = class.Spread or 0
for i=1, class.Pellets or 1 do
local dir = self:GetOwner():EyeAngles()
2023-11-29 02:45:36 -05:00
local radius = util.SharedRandom("benny_distance_"..tostring(hand), 0, 1, i )
local circ = util.SharedRandom("benny_radius_"..tostring(hand), 0, math.rad(360), i )
2023-10-31 19:05:52 -04:00
dir:RotateAroundAxis( dir:Right(), spread * radius * math.sin( circ ) )
dir:RotateAroundAxis( dir:Up(), spread * radius * math.cos( circ ) )
dir:RotateAroundAxis( dir:Forward(), 0 )
local tr = util.TraceLine( {
start = p:EyePos(),
endpos = p:EyePos() + dir:Forward() * 8192,
filter = p
2023-10-31 19:05:52 -04:00
} )
self:FireBullets( {
Attacker = p,
Damage = class.Damage,
Force = class.Damage/10,
Src = p:EyePos(),
2023-10-31 19:05:52 -04:00
Dir = dir:Forward(),
IgnoreEntity = p,
2023-10-31 19:05:52 -04:00
Callback = self.BulletCallback,
} )
-- self:FireCL( tr )
-- self:FireSV( tr )
end
end
function SWEP:BulletCallback()
return true
end
function SWEP:FireCL( tr )
if CLIENT and IsFirstTimePredicted() then
do
local vStart = self.CWM:GetAttachment( 1 ).Pos
local vPoint = tr.HitPos
local effectdata = EffectData()
effectdata:SetStart( vStart )
effectdata:SetOrigin( vPoint )
effectdata:SetEntity( self )
effectdata:SetScale( 1025*12 )
effectdata:SetFlags( 1 )
util.Effect( "Tracer", effectdata )
end
-- util.DecalEx( Material( util.DecalMaterial( "Impact.Concrete" ) ), tr.Entity, tr.HitPos, tr.HitNormal, color_white, 1, 1 )
do
local effectdata = EffectData()
effectdata:SetOrigin( tr.HitPos )
effectdata:SetStart( tr.StartPos )
effectdata:SetSurfaceProp( tr.SurfaceProps )
effectdata:SetEntity( tr.Entity )
effectdata:SetDamageType( DMG_BULLET )
util.Effect( "Impact", effectdata )
end
end
end
function SWEP:FireSV( tr )
local class = self:BClass( false )
if SERVER and IsValid( tr.Entity ) then
local dmginfo = DamageInfo()
dmginfo:SetDamage( class.Damage )
dmginfo:SetAttacker( self:GetOwner() )
dmginfo:SetInflictor( self )
dmginfo:SetDamageType( DMG_BULLET )
dmginfo:SetDamagePosition( tr.HitPos )
tr.Entity:TakeDamageInfo( dmginfo )
end
end