Benny/gamemodes/benny/gamemode/items/firearms.lua

344 lines
8.7 KiB
Lua
Raw Permalink Normal View History

do -- Base Firearm
local AnimationLookup = {
["fire"] = {
["handgun"] = "handgun_fire",
["rifle"] = "rifle_fire",
},
["reload"] = {
["handgun"] = "handgun_reload",
["rifle"] = "rifle_reload",
},
["reload_rack"] = {
["handgun"] = "handgun_reload_rack",
["rifle"] = "rifle_reload_rack",
},
["reload_insert"] = {
["handgun"] = "handgun_reload_insert",
["rifle"] = "rifle_reload_insert",
},
["deploy"] = {
["handgun"] = "handgun_deploy",
["rifle"] = "rifle_deploy",
},
["holster"] = {
["handgun"] = "handgun_holster",
["rifle"] = "handgun_holster",
},
}
local ITEM, Base = CreateItem( "base_firearm", "base" )
ITEM.PrintName = "Firearm Base"
ITEM.Description = "Testing testing"
ITEM.Category = "base"
ITEM.Vars = {
["Bool"] = {
"Loaded",
},
["Int"] = {
"Clip",
"BurstCount",
"Firemode",
},
["Float"] = {
"Delay",
"DelayBurst",
"RefillTime",
"Accuracy_Reset",
"Accuracy_Amount",
"DelayReload",
},
2024-10-08 20:46:36 -04:00
["Entity"] = {
"Inventory"
},
}
ITEM.Delay = 0.2
ITEM.Pellets = 1
ITEM.Accuracy = 1
ITEM.ClipSize = 15
ITEM.BurstCount = math.huge
ITEM.BurstRunaway = false
ITEM.BurstAuto = false
ITEM.BurstDelay = 0
ITEM.FireSound = bSound("weapons/m16a2/01.ogg") -- can be an iterative table
ITEM.MagOutSound = bSound("weapons/m16a2/magout.ogg")
ITEM.MagInSound = bSound("weapons/m16a2/magin.ogg")
ITEM.BoltDropSound = bSound("weapons/m16a2/cock.ogg")
ITEM.BoltPullSound = bSound("weapons/fnc/cock.ogg")
function ITEM:EntInitialize()
Base.EntInitialize( self )
2024-10-08 20:46:36 -04:00
if SERVER then
local inv = self:SetupInventory()
inv:SetReservedSlots( 1 )
end
end
function ITEM:Attack()
if self:GetClip() <= 0 then return end
if self:GetDelay() > CurTime() then return end
if self:GetDelayBurst() > CurTime() then return end
if self:GetBurstCount() >= self.BurstCount then return end
if self:GetHolsterIn() != 0 then return end
self:SetDelay( CurTime() + self.Delay )
self:SetClip( self:GetClip() - 1 )
self:SetBurstCount( self:GetBurstCount() + 1 )
self:Sound( istable(self.FireSound) and TSelShared(self.FireSound, "FireSound") or self.FireSound )
local p = self:GetOwner()
local h = self:GetHandler()
if p:IsValid() then
self:PlayerAnimation( AnimationLookup["fire"][self.HoldType] )
end
self:PlayAnimation( self:LookupSequence("fire") )
p:LagCompensation(true)
h:FireBullets( {
Attacker = p,
Damage = 1,
Force = 5,
Tracer = 0,
Num = self.Pellets,
Dir = p:GetAimVector(),
Src = p:GetShootPos(),
Spread = Vector( acc, acc, 0 ),
} )
p:LagCompensation(false)
end
function ITEM:AttackAlt() end
function ITEM:Think()
local InProcess = self:GetBurstCount() > 0
local Topped = self:GetBurstCount() == self.BurstCount
local Runaway = self.BurstRunaway
local BAuto = self.BurstAuto
local Firedown = false
local p = self:GetOwner()
if IsValid(p) then
Firedown = p:KeyDown( IN_ATTACK )
end
if Runaway and InProcess and !Topped then
self:Attack()
else
if !Firedown then
if !Topped and InProcess then
self:SetDelayBurst( CurTime() + self.BurstDelay )
end
self:SetBurstCount( 0 )
end
if Topped and BAuto then
self:SetBurstCount( 0 )
self:SetDelayBurst( CurTime() + self.BurstDelay )
end
end
if self:GetRefillTime() != 0 and self:GetRefillTime() <= CurTime() then
2024-10-08 20:46:36 -04:00
self:SetClip( self.ClipSize )
self:SetRefillTime( 0 )
2024-10-08 20:46:36 -04:00
if SERVER then
local inv = self:GetInventory()
local ent = ents.Create("b-item_mag_m16a2")
if IsValid(ent) then
ent:AddEffects( EF_BONEMERGE + EF_BONEMERGE_FASTCULL )
ent:SetOwner( self )
ent:SetParent( self )
ent:SetLocalPos( vector_origin )
ent:SetLocalAngles( angle_zero )
ent:Spawn()
self:ReevalRecreate()
ent:ReevalRecreate()
ent:SetMoveType( MOVETYPE_NONE )
inv:SetItem1( ent )
end
end
end
Base.Think( self )
end
function ITEM:Deploy()
self:SetDelay( CurTime() + 0.5 )
self:PlayerAnimation( AnimationLookup["deploy"][self.HoldType] )
Base.Deploy( self )
end
function ITEM:Reload()
if self:GetDelay() > CurTime() then return end
if self:GetHolsterIn() != 0 then return end
local p = self:GetOwner()
local time = 0.4
2024-10-08 20:46:36 -04:00
if self:GetInventory():GetItem1():IsValid() then -- Mag loaded
-- Unload the mag
self:SetClip( 0 )
self:Sound( self.MagOutSound, 70, 100, 0.4 )
self:PlayerAnimation( AnimationLookup["reload"][self.HoldType] )
self:PlayAnimation( self:LookupSequence( "magout" ) )
time = 0.4
2024-10-08 20:46:36 -04:00
if CLIENT then
local inv = self:GetInventory()
local curr = inv:GetItem1()
if curr:IsValid() then
local bm = self:GetBoneMatrix( self:LookupBone("Weapon") )
debugoverlay.Cross( bm:GetTranslation(), 16, 0.5 )
local class = ITEMS["mag_m16a2"]
local ent = ents.CreateClientProp( class.Model ) --- TO BE A SHARED ENTITY IN THE FUTURE :3
ent:SetPos( bm:GetTranslation() )
ent:SetAngles( bm:GetAngles() + Angle( 0, -90, -90 ) )
ent:Spawn()
end
end
if SERVER then
local inv = self:GetInventory()
local curr = inv:GetItem1()
if curr:IsValid() then
inv:SetItem1( NULL )
curr:SetOwner( NULL )
curr:SetParent( NULL )
curr:Remove()
self:ReevalRecreate()
-- curr:SetMoveType( MOVETYPE_VPHYSICS )
-- curr:GetPhysicsObject():Wake()
end
end
else
-- Load it
2024-10-08 20:46:36 -04:00
self:SetRefillTime( CurTime() + 0.4 )
self:Sound( self.MagInSound, 70, 100, 0.4 )
self:PlayerAnimation( AnimationLookup["reload_insert"][self.HoldType] )
self:PlayAnimation( self:LookupSequence( "magin" ) )
end
2024-10-08 20:46:36 -04:00
time = 0.8
self:SetDelay( CurTime() + time )
end
function ITEM:StartHolster()
self:SetDelay( CurTime() + 0.25 )
self:PlayerAnimation( AnimationLookup["holster"][self.HoldType] )
Base.StartHolster( self )
end
function ITEM:FinishHolster()
Base.FinishHolster( self )
end
function ITEM:CancelHolster()
self:PlayerAnimation( AnimationLookup["deploy"][self.HoldType] )
Base.CancelHolster( self )
end
2024-10-08 20:46:36 -04:00
do -- Base Mag
local ITEM, Base = CreateItem( "base_mag", "base" )
ITEM.PrintName = "Magazine Base"
ITEM.Description = "Testing testing"
ITEM.Category = "base"
end
do -- Handguns
do -- G18
local ITEM, Base = CreateItem( "g18", "base_firearm" )
ITEM.PrintName = "#Item.g18.Name"
ITEM.Description = "#Item.g18.Description"
ITEM.Category = "pistol"
ITEM.Model = bModel("weapons/test_g18")
ITEM.HoldType = "handgun"
ITEM.BurstCount = math.huge
ITEM.Delay = (60/1000)
ITEM.ClipSize = 33
ITEM.FireSound = {
bSound("weapons/glock/01.ogg"),
bSound("weapons/glock/02.ogg"),
bSound("weapons/glock/03.ogg"),
}
ITEM.MagOutSound = bSound("weapons/glock/magout.ogg")
ITEM.MagInSound = bSound("weapons/glock/magin.ogg")
ITEM.BoltDropSound = bSound("weapons/glock/cock.ogg")
ITEM.BoltPullSound = bSound("weapons/glock/cock.ogg")
end
do -- MK23
local ITEM, Base = CreateItem( "mk23", "base_firearm" )
ITEM.PrintName = "#Item.mk23.Name"
ITEM.Description = "#Item.mk23.Description"
ITEM.Category = "pistol"
ITEM.Model = bModel("weapons/test_mk23")
ITEM.DefaultBodygroups = { false, false, 1 }
ITEM.HoldType = "handgun"
ITEM.BurstCount = 1
ITEM.Delay = (60/320)
ITEM.ClipSize = 12
ITEM.FireSound = {
bSound("weapons/usp/sup_01.ogg"),
bSound("weapons/usp/sup_02.ogg"),
bSound("weapons/usp/sup_03.ogg"),
}
ITEM.MagOutSound = bSound("weapons/usp/magout.ogg")
ITEM.MagInSound = bSound("weapons/usp/magin.ogg")
ITEM.BoltDropSound = bSound("weapons/usp/slidedrop.ogg")
ITEM.BoltPullSound = bSound("weapons/glock/cock.ogg")
end
end
do -- Rifles
do -- M16A2
local ITEM, Base = CreateItem( "m16a2", "base_firearm" )
ITEM.PrintName = "#Item.m16a2.Name"
ITEM.Description = "#Item.m16a2.Description"
ITEM.Category = "assaultrifle"
ITEM.Model = bModel("weapons/test_m16a2")
ITEM.DefaultBodygroups = { false, false, 1 }
ITEM.HoldType = "rifle"
ITEM.BurstCount = 3
ITEM.BurstRunaway = true
ITEM.BurstAuto = true
ITEM.BurstDelay = 0.2
ITEM.Delay = (60/1050)
ITEM.ClipSize = 30
ITEM.FireSound = {
bSound("weapons/m16a2/01.ogg"),
bSound("weapons/m16a2/02.ogg"),
bSound("weapons/m16a2/03.ogg"),
}
ITEM.MagOutSound = bSound("weapons/m16a2/magout.ogg")
ITEM.MagInSound = bSound("weapons/m16a2/magin.ogg")
ITEM.BoltDropSound = bSound("weapons/m16a2/cock.ogg")
ITEM.BoltPullSound = bSound("weapons/fnc/cock.ogg")
2024-10-08 20:46:36 -04:00
do
local ITEM, Base = CreateItem( "mag_m16a2", "base_mag" )
ITEM.PrintName = "#Item.mag_m16a2.Name"
ITEM.Description = "#Item.mag_m16a2.Description"
ITEM.Category = "magazine"
ITEM.Model = bModel("weapons/test_m16a2_mag")
ITEM.DefaultBodygroups = {}
ITEM.HoldType = "magazine"
ITEM.ClipSize = 30
end
end
end
end