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", "ReloadStage", }, ["Float"] = { "Delay", "DelayBurst", "RefillTime", "Accuracy_Reset", "Accuracy_Amount", "DelayReload", }, } 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 ) 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 self:SetClip( class.ClipSize ) self:SetRefillTime( 0 ) 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 if self:GetReloadStage() == 0 then -- Mag loaded -- Unload the mag self:SetReloadStage(1) 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 else -- Load it self:SetReloadStage(0) self:SetClip( self.ClipSize ) self:Sound( self.MagInSound, 70, 100, 0.4 ) self:PlayerAnimation( AnimationLookup["reload_insert"][self.HoldType] ) self:PlayAnimation( self:LookupSequence( "magin" ) ) time = 0.8 end 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 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") end end end