2023-09-13 22:15:43 -04:00
|
|
|
|
2023-09-23 22:51:35 -04:00
|
|
|
-- The benny weapon handles the weapon pickups you find throughout the game.
|
|
|
|
|
2023-09-24 01:19:23 -04:00
|
|
|
SWEP.Base = "weapon_base"
|
2023-09-13 22:15:43 -04:00
|
|
|
|
2023-09-24 01:19:23 -04:00
|
|
|
SWEP.PrintName = "Benny Weapon Handler"
|
2023-09-13 22:15:43 -04:00
|
|
|
|
2023-09-24 01:19:23 -04:00
|
|
|
SWEP.ViewModel = "models/weapons/c_pistol.mdl"
|
|
|
|
SWEP.ViewModelFOV = 10
|
|
|
|
SWEP.WorldModel = "models/weapons/w_pistol.mdl"
|
|
|
|
|
|
|
|
SWEP.Primary.ClipSize = 0
|
|
|
|
SWEP.Primary.DefaultClip = 0
|
|
|
|
SWEP.Primary.Automatic = true
|
|
|
|
SWEP.Primary.Ammo = "none"
|
|
|
|
|
|
|
|
SWEP.Secondary.ClipSize = 0
|
|
|
|
SWEP.Secondary.DefaultClip = 0
|
|
|
|
SWEP.Secondary.Automatic = true
|
|
|
|
SWEP.Secondary.Ammo = "none"
|
2023-09-13 22:15:43 -04:00
|
|
|
|
2023-09-23 22:51:35 -04:00
|
|
|
function SWEP:SetupDataTables()
|
|
|
|
self:NetworkVar( "Float", 0, "Aim" )
|
2023-09-24 01:19:23 -04:00
|
|
|
self:NetworkVar( "Float", 1, "Delay1" )
|
|
|
|
self:NetworkVar( "Float", 2, "Delay2" )
|
|
|
|
self:NetworkVar( "String", 0, "Wep1" )
|
|
|
|
self:NetworkVar( "String", 1, "Wep2" )
|
2023-09-25 17:26:52 -04:00
|
|
|
self:NetworkVar( "Int", 0, "Wep1Clip" )
|
|
|
|
self:NetworkVar( "Int", 1, "Wep2Clip" )
|
2023-09-23 22:51:35 -04:00
|
|
|
end
|
|
|
|
|
2023-09-13 22:15:43 -04:00
|
|
|
function SWEP:PrimaryAttack()
|
2023-09-25 20:42:13 -04:00
|
|
|
if !self:BTable() then
|
2023-09-24 03:36:32 -04:00
|
|
|
return
|
|
|
|
end
|
2023-09-24 01:19:23 -04:00
|
|
|
if self:GetDelay1() > CurTime() then
|
|
|
|
return
|
|
|
|
end
|
2023-09-23 22:51:35 -04:00
|
|
|
if self:Clip1() == 0 then
|
2023-09-25 20:42:13 -04:00
|
|
|
B_Sound( self, self:BClass( false ).Sound_DryFire )
|
2023-09-24 01:19:23 -04:00
|
|
|
self:SetDelay1( CurTime() + 0.2 )
|
|
|
|
return
|
|
|
|
end
|
2023-09-23 22:51:35 -04:00
|
|
|
|
2023-09-25 20:42:13 -04:00
|
|
|
B_Sound( self, self:BClass( false ).Sound_Fire )
|
2023-09-23 22:51:35 -04:00
|
|
|
|
2023-09-25 20:42:13 -04:00
|
|
|
self:B_Ammo( false, self:Clip1() - 1 )
|
|
|
|
self:SetDelay1( CurTime() + self:BClass( false ).Delay )
|
2023-09-13 22:15:43 -04:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2023-09-24 01:19:23 -04:00
|
|
|
-- BENNY shit
|
2023-09-25 20:42:13 -04:00
|
|
|
function SWEP:BTable( alt )
|
|
|
|
return self:GetOwner():INV_Get()[ alt and self:GetWep2() or self:GetWep1() ]
|
2023-09-24 01:19:23 -04:00
|
|
|
end
|
|
|
|
|
2023-09-25 20:42:13 -04:00
|
|
|
function SWEP:BClass( alt )
|
|
|
|
local ta = self:BTable( alt )
|
|
|
|
if ta then
|
|
|
|
return WEAPONS[ ta.Class ]
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
2023-09-24 01:19:23 -04:00
|
|
|
end
|
|
|
|
|
2023-09-25 20:42:13 -04:00
|
|
|
function SWEP:B_Ammo( alt, value )
|
|
|
|
local clip = (alt and self:GetWep2Clip() or self:GetWep1Clip())
|
|
|
|
assert( clip > 0, "You cannot mess with an EMPTY magazine!")
|
|
|
|
if alt then
|
|
|
|
self:SetClip2( value )
|
|
|
|
else
|
|
|
|
self:SetClip1( value )
|
|
|
|
end
|
|
|
|
self:BTable( alt )["Ammo" .. clip] = value
|
2023-09-24 01:19:23 -04:00
|
|
|
end
|
|
|
|
|
2023-09-13 22:15:43 -04:00
|
|
|
function SWEP:SecondaryAttack()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function SWEP:Reload()
|
2023-09-25 20:42:13 -04:00
|
|
|
if self:BTable( false ) then
|
2023-09-25 17:26:52 -04:00
|
|
|
if self:GetDelay1() > CurTime() then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
self:SetDelay1( CurTime() + 0.2 )
|
|
|
|
|
|
|
|
if self:GetWep1Clip() != 0 then
|
2023-09-25 20:42:13 -04:00
|
|
|
B_Sound( self, self:BClass().Sound_MagOut )
|
2023-09-25 17:26:52 -04:00
|
|
|
self:SetClip1( 0 )
|
|
|
|
self:SetWep1Clip( 0 )
|
2023-09-25 20:42:13 -04:00
|
|
|
self:BTable().Loaded = 0
|
2023-09-25 17:26:52 -04:00
|
|
|
else
|
2023-09-25 20:42:13 -04:00
|
|
|
local maglist = { self:BTable( false ).Ammo1, self:BTable( false ).Ammo2, self:BTable( false ).Ammo3 }
|
2023-09-25 17:26:52 -04:00
|
|
|
for i, v in SortedPairsByValue( maglist, true ) do
|
|
|
|
if v == 0 then B_Sound( self, "Common.NoAmmo" ) return end
|
2023-09-25 20:42:13 -04:00
|
|
|
self:BTable().Loaded = i
|
2023-09-25 17:26:52 -04:00
|
|
|
self:SetWep1Clip( i )
|
|
|
|
self:SetClip1( v )
|
|
|
|
break
|
|
|
|
end
|
2023-09-25 20:42:13 -04:00
|
|
|
B_Sound( self, self:BClass().Sound_MagIn )
|
2023-09-25 17:26:52 -04:00
|
|
|
end
|
2023-09-24 01:19:23 -04:00
|
|
|
end
|
2023-09-13 22:15:43 -04:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function SWEP:Think()
|
2023-09-23 22:51:35 -04:00
|
|
|
local p = self:GetOwner()
|
|
|
|
|
|
|
|
self:SetAim( math.Approach( self:GetAim(), p:KeyDown(IN_ATTACK2) and 1 or 0, FrameTime()/0.05 ) )
|
|
|
|
|
|
|
|
local ht = "normal"
|
|
|
|
if self:GetAim() > 0 then
|
|
|
|
ht = "revolver"
|
|
|
|
end
|
|
|
|
|
|
|
|
self:SetWeaponHoldType(ht)
|
|
|
|
self:SetHoldType(ht)
|
|
|
|
|
2023-09-13 22:15:43 -04:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function SWEP:Deploy()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function SWEP:Holster()
|
|
|
|
return true
|
|
|
|
end
|