From 3f6f5464b9f6f7a2681a24040c3b124d31caccc0 Mon Sep 17 00:00:00 2001 From: Fesiug Date: Sat, 5 Oct 2024 17:41:47 -0400 Subject: [PATCH] Rewrite Benny Item System Stats can now be indexed by indexing the Entity Also fixes player animations in MP TP - Animations not being called on other players - Aim pitch poseparameter Category names are translated Handler getting is way better I think. --- .../benny/entities/entities/b-itembase.lua | 8 +- .../benny/entities/weapons/itemhandler.lua | 50 +- gamemodes/benny/gamemode/camera.lua | 11 +- gamemodes/benny/gamemode/debugmenu.lua | 4 +- gamemodes/benny/gamemode/inventory.lua | 5 - gamemodes/benny/gamemode/items.lua | 1255 ++--------------- gamemodes/benny/gamemode/items/base.lua | 81 ++ gamemodes/benny/gamemode/items/firearms.lua | 268 ++++ gamemodes/benny/gamemode/languages/en-us.lua | 19 + gamemodes/benny/gamemode/player.lua | 13 +- gamemodes/benny/gamemode/shared.lua | 12 + 11 files changed, 517 insertions(+), 1209 deletions(-) create mode 100644 gamemodes/benny/gamemode/items/base.lua create mode 100644 gamemodes/benny/gamemode/items/firearms.lua diff --git a/gamemodes/benny/entities/entities/b-itembase.lua b/gamemodes/benny/entities/entities/b-itembase.lua index 6166ee9..cd0eff8 100644 --- a/gamemodes/benny/entities/entities/b-itembase.lua +++ b/gamemodes/benny/entities/entities/b-itembase.lua @@ -11,14 +11,14 @@ ENT.BennyItem = true ENT.AutomaticFrameAdvance = true function ENT:Initialize() - self:SetModel( self.Class.Model or "models/weapons/w_357.mdl" ) + self:SetModel( self.Model or "models/weapons/w_357.mdl" ) if SERVER then self:PhysicsInit( SOLID_VPHYSICS ) self:SetCollisionGroup( COLLISION_GROUP_WEAPON ) - self:GetPhysicsObject():Wake() + --self:GetPhysicsObject():Wake() end - self.Class:Initialize( self ) + self:EntInitialize( self ) end if SERVER then @@ -103,7 +103,7 @@ local function recurse( modify, includer ) end function ENT:SetupDataTables() - local NWVars = { ["Float"] = { "AnimStartTime", "AnimEndTime" } } + local NWVars = { ["Entity"] = { "Handler" } } recurse( NWVars, self.ID ) for varname, varlist in pairs(NWVars) do --local numba = 0 diff --git a/gamemodes/benny/entities/weapons/itemhandler.lua b/gamemodes/benny/entities/weapons/itemhandler.lua index 99657f6..b241b00 100644 --- a/gamemodes/benny/entities/weapons/itemhandler.lua +++ b/gamemodes/benny/entities/weapons/itemhandler.lua @@ -29,22 +29,14 @@ function SWEP:SetupDataTables() self:NetworkVar( "Entity", "DesireL" ) end -function SWEP:ItemR( run ) +function SWEP:ItemR( key ) local active = self:GetActiveR() - if run and active:IsValid() then - return active.Class[run]( active.Class, active, self ) - else - return active:IsValid() and active or false - end + return active:IsValid() and active or false end -function SWEP:ItemL( run ) +function SWEP:ItemL( key ) local active = self:GetActiveL() - if run and active:IsValid() then - active.Class[run]( active.Class, active, self ) - else - return active:IsValid() and active or false - end + return active:IsValid() and active or false end function SWEP:Initialize() @@ -72,9 +64,9 @@ function SWEP:SetActive( ent ) if ent:GetOwner() != p then return false end --if self:GetActiveR():IsValid() then self:Deactive() end self:SetActiveR( ent ) - if self:ItemR() then - self:ItemR( "Deploy" ) - self:ItemR():SetNoDraw( false ) + if self:GetActiveR():IsValid() then + self:GetActiveR():Deploy() + self:GetActiveR():SetNoDraw( false ) end return true end @@ -84,21 +76,21 @@ end function SWEP:PrimaryAttack() local p = self:GetOwner() - if self:ItemR() then - self:ItemR("Attack") + if self:GetActiveR():IsValid() then + self:GetActiveR():Attack() end end function SWEP:Reload() - if self:ItemR() then - self:ItemR("Reload") + if self:GetActiveR():IsValid() then + self:GetActiveR():Reload() end end function SWEP:SecondaryAttack() local p = self:GetOwner() - if self:ItemR() then - self:ItemR("AttackAlt") + if self:GetActiveR():IsValid() then + self:GetActiveR():AttackAlt() end end @@ -138,6 +130,7 @@ function SWEP:EquipItem( ent ) ent:SetNoDraw( true ) ent:SetParent( p ) ent:SetOwner( p ) + ent:SetHandler( self ) ent:SetLocalPos( vector_origin ) ent:SetLocalAngles( angle_zero ) ent:SetAcquisition( CurTime() ) @@ -166,6 +159,7 @@ function SWEP:DropItem() ent:SetParent( NULL ) ent:SetOwner( NULL ) + ent:SetHandler( NULL ) ent:RemoveEFlags( EFL_KEEP_ON_RECREATE_ENTITIES ) ent:RemoveEffects( EF_BONEMERGE ) @@ -205,7 +199,7 @@ function SWEP:Think() if DesireR != ActiveR then if ActiveR_Valid then if ActiveR:GetHolsterIn() == 0 then - ActiveR.Class.Holster( ActiveR.Class, ActiveR, self ) + ActiveR:StartHolster() else -- Waiting for holster to finish end @@ -216,7 +210,7 @@ function SWEP:Think() end else if ActiveR_Valid and ActiveR:GetHolsterIn() != 0 then - ActiveR.Class.UndoHolster( ActiveR.Class, ActiveR, self ) + ActiveR:CancelHolster() end end @@ -228,7 +222,7 @@ function SWEP:Think() end else if self:GetActiveR() != NULL then - ActiveR.Class.Drop( ActiveR.Class, ActiveR, self ) + ActiveR:Drop() if SERVER then self:DropItem() end @@ -243,15 +237,15 @@ function SWEP:Think() if p:KeyPressed(IN_ALT2) then end if p:KeyPressed(IN_GRENADE1) then - if self:ItemR() and self:ItemR().Class.Alt then - self:ItemR("Alt") + if self:GetActiveR():IsValid() and self:GetActiveR().Alt then + self:GetActiveR():Alt() end end if p:KeyPressed(IN_GRENADE2) then end - if self:ItemR() then - self:ItemR("Think") + if self:GetActiveR():IsValid() then + self:GetActiveR():Think() end else print( self, "Thinking without an owner." ) diff --git a/gamemodes/benny/gamemode/camera.lua b/gamemodes/benny/gamemode/camera.lua index 4962732..3bf47b9 100644 --- a/gamemodes/benny/gamemode/camera.lua +++ b/gamemodes/benny/gamemode/camera.lua @@ -86,7 +86,7 @@ function GM:CalcView( ply, pos, ang, fov ) ply:SetupBones() local bm = ply:GetBoneMatrix(ply:LookupBone("DEF-spine.003")) view.origin = bm:GetTranslation() - view.origin:Add( vector_up*10 ) + view.origin:Add( vector_up*8 ) if ply:GetLayerSequence( GESTURE_SLOT_JUMP ) == ply:LookupSequence("dive_end_handgun") then local progress = ply:GetLayerCycle( GESTURE_SLOT_JUMP ) @@ -126,17 +126,20 @@ function GM:CalcView( ply, pos, ang, fov ) ply:ManipulateBoneScale( bid, Vector(1, 1, 1) ) local bid = ply:LookupBone("DEF-spine.005") ply:ManipulateBoneScale( bid, Vector(1, 1, 1) ) + --local bid = ply:LookupBone("Weapon") + --ply:ManipulateBonePosition( bid, vector_origin ) lastfp = fp - -- print("show") elseif !lastfp and fp then local bid = ply:LookupBone("DEF-spine.006") ply:ManipulateBoneScale( bid, vector_origin ) local bid = ply:LookupBone("DEF-spine.005") ply:ManipulateBoneScale( bid, vector_origin ) + --local bid = ply:LookupBone("Weapon") + --ply:ManipulateBonePosition( bid, Vector(-3, 1, 0) ) lastfp = fp - -- print("hide") end + return view end @@ -157,7 +160,6 @@ hook.Add( "OnRequestFullUpdate", "Benny_OnRequestFullUpdate_CameraFP", function( if !bid then return end ply:ManipulateBoneScale( bid, Vector(1, 1, 1) ) lastfp = fp - -- print("fullupdate: show") elseif fp then local bid = ply:LookupBone("DEF-spine.006") if !bid then return end @@ -166,7 +168,6 @@ hook.Add( "OnRequestFullUpdate", "Benny_OnRequestFullUpdate_CameraFP", function( if !bid then return end ply:ManipulateBoneScale( bid, vector_origin ) lastfp = fp - -- print("fullupdate: hide") end end) end diff --git a/gamemodes/benny/gamemode/debugmenu.lua b/gamemodes/benny/gamemode/debugmenu.lua index f11d75b..ff31486 100644 --- a/gamemodes/benny/gamemode/debugmenu.lua +++ b/gamemodes/benny/gamemode/debugmenu.lua @@ -260,7 +260,7 @@ local function OpenDebugMenu() if !categories[category] then local cate = opt:Add("DCollapsibleCategory") cate:Dock(TOP) - cate:SetLabel(category) + cate:SetLabel( l8( "#ItemCategory." .. category .. ".Name" ) ) local plist = vgui.Create("DPanelList") cate:SetContents(plist) categories[category] = plist @@ -272,7 +272,7 @@ local function OpenDebugMenu() if !categories[idata.Category] then local cate = opt:Add("DCollapsibleCategory") cate:Dock(TOP) - cate:SetLabel(idata.Category) + cate:SetLabel( l8( "#ItemCategory." .. idata.Category .. ".Name" ) ) local plist = vgui.Create("DPanelList") cate:SetContents(plist) categories[idata.Category] = plist diff --git a/gamemodes/benny/gamemode/inventory.lua b/gamemodes/benny/gamemode/inventory.lua index 554151b..b95cd2b 100644 --- a/gamemodes/benny/gamemode/inventory.lua +++ b/gamemodes/benny/gamemode/inventory.lua @@ -175,11 +175,6 @@ do end) end --- breaks GESTURE_SLOT_ATTACK_AND_RELOAD and I can't fucking have that -hook.Add("DoAnimationEvent", "Benny_DoAnimationEvent_FixAnimations", function( ply, event, data ) - return ACT_INVALID -end) - hook.Add( "PlayerSwitchWeapon", "Benny_PlayerSwitchWeapon_Goat", function( ply, old, ent ) if ent.BennyItemHandler then return true end -- what happened? local wep = ply:HandlerCheck() diff --git a/gamemodes/benny/gamemode/items.lua b/gamemodes/benny/gamemode/items.lua index 2683c27..b252e46 100644 --- a/gamemodes/benny/gamemode/items.lua +++ b/gamemodes/benny/gamemode/items.lua @@ -3,1184 +3,113 @@ -- Your Name is Benny --------------------- -ITEMS = {} +local Emeta = FindMetaTable("Entity") -local itemmeta = {} - -function itemmeta:__tostring() - return "ItemDef [" .. self.ClassName .. "]" +Emetaindex = Emetaindex or Emeta.__index +function Emeta:__index( key ) + local Etable = Emeta.GetTable(self) + if Etable and Etable["BennyItem"] then + local Class = Etable.Class + if !Class then + ErrorNoHalt( "[Emeta Index] " .. tostring(self) .. " missing Class key!!" ) + elseif Class[key] then + return Class[key] + end + end + return Emetaindex( self, key ) end -local ITEMHELPER = { - Get = function( self, key ) - return self.key - end, - GetRaw = function( self, key ) - return rawget( self, key ) - end, -} +local Itemmeta = {} -function itemmeta.__index( self, key ) - if ITEMHELPER[key] then return ITEMHELPER[key] end +function Itemmeta:__tostring() + return "ItemDef [" .. self.ClassName .. "]" +end +function Itemmeta:Get( key ) + return self.key +end +function Itemmeta:GetRaw( key ) + return rawget( self, key ) +end +function Itemmeta.__index( self, key ) + if Itemmeta[key] then return Itemmeta[key] end if rawget(self, "BaseClass") then return rawget(self, "BaseClass")[key] end end -function AddItem( itemname, item ) - if item then - ITEMS[itemname] = item - item.ClassName = itemname - item.BaseClass = ITEMS[item.Base] - setmetatable( item, itemmeta ) - else - return ITEMS[itemname] +ITEMS = {} + +local AC, IN = AddCSLuaFile, include +function InitializeItemFile( filename ) + print( "[InitializeItemFile] " .. filename ) + AC( "items/"..filename ) + + local xSuccess, xMessage = pcall(function() + IN( "items/"..filename ) + end) + if !xSuccess then + error("Error in initialization of " .. filename ) + print( xMessage ) end end -function BaseClassGet( item ) - -- TODO +InitPostEntity_Complete = InitPostEntity_Complete or false +function CreateItem( id, baseid ) + print( "[CreateItem] " .. id ) + local ITEM = {} + ITEMS[id] = ITEM + ITEM.ClassName = id + if baseid then + ITEM.Base = baseid + ITEM.BaseClass = ITEMS[baseid] + + if !ITEMS[baseid] then + ErrorNoHalt("[CreateItem] Undefined base " .. baseid .. " for item " .. id) + end + end + + setmetatable( ITEM, Itemmeta ) + + do -- Entity creation + local tent = {} + tent.Base = "b-itembase" + tent.PrintName = id + tent.ID = id + tent.Class = ITEM + tent.Spawnable = true + tent.AdminOnly = false + tent.Category = "Other" + + scripted_ents.Register( tent, "b-item_" .. id ) + end + + return ITEM, ITEMS[baseid] end -AddItem( "base", { - PrintName = "Base Item", - Description = "Beginning item base.", - Category = "base", - - Model = "models/benny/weapons/test_m16a2.mdl", - DefaultBodygroups = {}, - Vars = { - ["Float"] = { - "Acquisition", - "HolsterIn", - }, - }, - - ["Initialize"] = function( class, ent, handler ) - print( class, "Initialized base initialization" ) - - for k, v in ipairs(class.DefaultBodygroups) do - if v then - ent:SetBodygroup( k-1, v ) - end - end - end, - - ["Deploy"] = function( class, ent, handler ) - ent:SetNoDraw( false ) - end, - - ["Drop"] = function( class, ent, handler ) - end, - - ["Holster"] = function( class, ent, handler ) - ent:SetHolsterIn( CurTime() + 0.5 ) - end, - - ["FinishHolster"] = function( class, ent, handler ) - handler:SetActiveR( NULL ) - ent:SetNoDraw( true ) - end, - - ["UndoHolster"] = function( class, ent, handler ) - ent:SetHolsterIn( 0 ) - end, - - ["Attack"] = function( class, ent, handler ) - end, - - ["AttackAlt"] = function( class, ent, handler ) - end, - - ["Alt"] = function( class, ent, handler ) - end, - - ["Think"] = function( class, ent, handler ) - if ent:GetHolsterIn() != 0 and ent:GetHolsterIn() <= CurTime() then - class:FinishHolster( ent, handler ) - ent:SetHolsterIn( 0 ) - end - end, - - ["EntThink"] = function( class, ent, handler ) - end, - - ["EntPhysicsCollide"] = function( class, ent, data, collider ) - end, - - ["Reload"] = function( class, ent, handler ) - end, -}) - -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 BaseClass = ITEMS.base -AddItem( "base_firearm", { - PrintName = "Base Firearm", - Description = "Item base for firearms.", - Category = "base", - Base = "base", - - FirearmHelper = true, - - Vars = { - ["Bool"] = { - "Loaded", - }, - ["Int"] = { - "Clip", - "BurstCount", - "Firemode", - }, - ["Float"] = { - "Delay", - "DelayBurst", - "RefillTime", - "Accuracy_Reset", - "Accuracy_Amount", - "DelayReload", - }, - }, - HoldType = "rpg", - - Delay = 0.1, - Pellets = 1, - Accuracy = 1, - ClipSize = 15, - BurstCount = math.huge, - BurstRunaway = false, - BurstAuto = false, - BurstDelay = 0, - - FireSound = "benny/weapons/m16a2/01.ogg", - MagOutSound = "benny/weapons/m16a2/magout.ogg", - MagInSound = "benny/weapons/m16a2/magin.ogg", - BoltDropSound = "benny/weapons/m16a2/cock.ogg", - BoltPullSound = "benny/weapons/fnc/cock.ogg", - - ["Initialize"] = function( class, ent, handler ) - BaseClass.Initialize( class, ent, handler ) - - ent:SetClip( class.ClipSize ) - ent:SetLoaded(true) - - print( class, "Initialized a firearm" ) - end, - - ["Think"] = function( class, ent, handler ) - local InProcess = ent:GetBurstCount() > 0 - local Topped = ent:GetBurstCount() == class.BurstCount - local Runaway = class.BurstRunaway - local BAuto = class.BurstAuto - local Firedown = false - if IsValid(handler) then - Firedown = handler:GetOwner():KeyDown( IN_ATTACK ) - end - if Runaway and InProcess and !Topped then - class:Attack( ent, handler ) - else - if !Firedown then - if !Topped and InProcess then - ent:SetDelayBurst( CurTime() + class.BurstDelay ) - end - ent:SetBurstCount( 0 ) - end - if Topped and BAuto then - ent:SetBurstCount( 0 ) - ent:SetDelayBurst( CurTime() + class.BurstDelay ) - end - end - if ent:GetRefillTime() != 0 and ent:GetRefillTime() <= CurTime() then - ent:SetClip( class.ClipSize ) - ent:SetRefillTime( 0 ) - end - BaseClass.Think( class, ent, handler ) - end, - - ["EntThink"] = function( class, ent ) - if IsValid(ent:GetOwner()) then return end -- Only run this stuff when there's no owner in hand - if CLIENT then return end - - local Firedown = ((ent.ShootTime or 0) >= CurTime()) - if Firedown then class:Attack( ent ) end - - local InProcess = ent:GetBurstCount() > 0 - local Topped = ent:GetBurstCount() == class.BurstCount - local Runaway = class.BurstRunaway - local BAuto = class.BurstAuto - if Runaway and InProcess and !Topped then - class:Attack( ent, handler ) - else - if !Firedown then - if !Topped and InProcess then - ent:SetDelayBurst( CurTime() + class.BurstDelay ) - end - ent:SetBurstCount( 0 ) - end - if Topped and BAuto then - ent:SetBurstCount( 0 ) - ent:SetDelayBurst( CurTime() + class.BurstDelay ) - end - end - end, - - ["Attack"] = function( class, ent, handler ) - if ent:GetClip() <= 0 then return end - if ent:GetDelay() > CurTime() then return end - if ent:GetDelayBurst() > CurTime() then return end - if ent:GetBurstCount() >= class.BurstCount then return end - if ent:GetHolsterIn() != 0 then return end - - local HandlerValid = IsValid(handler) - local handlerorself = HandlerValid and handler or ent - - local Runaway = class.BurstRunaway - local BAuto = class.BurstAuto - ent:SetBurstCount( ent:GetBurstCount() + 1 ) - if ent:GetBurstCount() >= class.BurstCount then - ent:SetDelayBurst( CurTime() + class.BurstDelay ) - if BAuto then - ent:SetBurstCount( 0 ) - ent.ShootTime = 0 - end - end - - ent:SetClip( ent:GetClip() - 1 ) - if ent:GetClip() == 0 then - handlerorself:EmitSound( "benny/weapons/1911/slidedrop.ogg", 70, 100, 0.4, CHAN_STATIC ) - end - - ent:SetDelay( CurTime() + class.Delay ) - handlerorself:EmitSound( istable(class.FireSound) and TSelShared(class.FireSound, "FireSound") or class.FireSound, 100, 100, 0.5, CHAN_STATIC ) - - local acc = math.rad( class.Accuracy or 0 ) - if HandlerValid then - local p = handler:GetOwner() - p:LagCompensation(true) - handler:FireBullets( { - Attacker = p, - Damage = 1, - Force = 5, - Tracer = 0, - Num = class.Pellets, - Dir = p:GetAimVector(), - Src = p:GetShootPos(), - Spread = Vector( acc, acc, 0 ), - } ) - p:LagCompensation(false) - else - ent:FireBullets( { - Attacker = ent, - Damage = 1, - Force = 1, - Tracer = 0, - Num = class.Pellets, - Dir = ent:GetForward(), - Src = ent:GetPos(), - Spread = Vector( acc, acc, 0 ), - } ) - local physobj = ent:GetPhysicsObject() - if physobj:IsValid() then - physobj:AddVelocity( ent:GetForward() * -300 ) - physobj:AddAngleVelocity( VectorRand( -360*20, 360*20 ) ) - end - end - - local ply = handlerorself:GetOwner() - if HandlerValid and (SERVER or CLIENT and IsFirstTimePredicted()) then - ply:AddVCDSequenceToGestureSlot( GESTURE_SLOT_ATTACK_AND_RELOAD, ply:LookupSequence( AnimationLookup["fire"][class.HoldType] ), 0, true ) - end - - ent:PlayAnimation( ent:LookupSequence("fire") ) - end, - - ["Reload"] = function( class, ent, handler ) - if ent:GetDelay() > CurTime() then return end - if ent:GetHolsterIn() != 0 then return end - - local ply = handler:GetOwner() - local time = 0.6 - - if ent:GetLoaded() then - handler:EmitSound( class.MagOutSound, 70, 100, 0.4, CHAN_STATIC ) - ent:SetLoaded( false ) - ent:SetClip( 0 ) - if SERVER or CLIENT and IsFirstTimePredicted() then - ply:AddVCDSequenceToGestureSlot( GESTURE_SLOT_ATTACK_AND_RELOAD, ply:LookupSequence( AnimationLookup["reload"][class.HoldType] ), 0, true ) - end - time = 0.4 - ent:PlayAnimation( ent:LookupSequence("magout") ) - else - handler:EmitSound( class.MagInSound, 70, 100, 0.4, CHAN_STATIC ) - ent:SetLoaded( true ) - ent:SetRefillTime( CurTime() + 0.5 ) - if SERVER or CLIENT and IsFirstTimePredicted() then - ply:AddVCDSequenceToGestureSlot( GESTURE_SLOT_ATTACK_AND_RELOAD, ply:LookupSequence( AnimationLookup["reload_insert"][class.HoldType] ), 0, true ) - end - time = 0.8 - ent:PlayAnimation( ent:LookupSequence("magin") ) - end - ent:SetDelay( CurTime() + time ) - end, - - ["Deploy"] = function( class, ent, handler ) - handler:EmitSound( "weapons/usp/usp_slideback.wav", 70, 125, 0.4, CHAN_STATIC ) - ent:SetDelay( CurTime() + 0.5 ) - - local ply = handler:GetOwner() - if SERVER or CLIENT and IsFirstTimePredicted() then - ply:AddVCDSequenceToGestureSlot( GESTURE_SLOT_ATTACK_AND_RELOAD, ply:LookupSequence( AnimationLookup["deploy"][class.HoldType] ), 0, true ) - end - end, - - ["Drop"] = function( class, ent, handler ) - ent:SetRefillTime( 0 ) - BaseClass.Drop( class, ent, handler ) - end, - - ["Holster"] = function( class, ent, handler ) - ent:SetRefillTime( 0 ) - - handler:EmitSound( "weapons/elite/elite_deploy.wav", 70, 125, 0.4, CHAN_STATIC ) - ent:SetDelay( CurTime() + 0.25 ) - ent:SetHolsterIn( CurTime() + 0.25 ) - - local ply = handler:GetOwner() - if SERVER or CLIENT and IsFirstTimePredicted() then - ply:AddVCDSequenceToGestureSlot( GESTURE_SLOT_ATTACK_AND_RELOAD, ply:LookupSequence( AnimationLookup["holster"][class.HoldType] ), 0, true ) - end - end, - - ["EntPhysicsCollide"] = function( class, ent, data, collider ) - if ( data.DeltaTime > 0.1 and data.Speed > 200 ) then - ent.ShootTime = CurTime() + math.Rand( 0.1, 0.5 ) - end - end, - - ["FinishHolster"] = function( class, ent, handler ) - handler:EmitSound( "weapons/m4a1/m4a1_deploy.wav", 70, 125, 0.4, CHAN_STATIC ) - BaseClass.FinishHolster( class, ent, handler ) - end, - - ["UndoHolster"] = function( class, ent, handler ) - BaseClass.UndoHolster( class, ent, handler ) - handler:EmitSound( "weapons/elite/elite_deploy.wav", 70, 125, 0.4, CHAN_STATIC ) - local ply = handler:GetOwner() - if SERVER or CLIENT and IsFirstTimePredicted() then - ply:AddVCDSequenceToGestureSlot( GESTURE_SLOT_ATTACK_AND_RELOAD, ply:LookupSequence( AnimationLookup["deploy"][class.HoldType] ), 0.25, true ) - end - end, -}) - -local BaseClass = ITEMS.base_firearm -AddItem( "base_firearm_ubgl", { - PrintName = "Base Firearm w/ UBGL", - Description = "Item base for firearms that include grenade launchers.", - Category = "base", - Base = "base_firearm", - - Vars = { - ["Int"] = { - "Clip2", - }, - ["Float"] = { - "Delay2", - "DelayBurst2", - "RefillTime2", - "Accuracy_Reset2", - "Accuracy_Amount2", - }, - }, - - Delay2 = 0.25, - ClipSize2 = 4, - - ["Initialize"] = function( class, ent, handler ) - BaseClass.Initialize( class, ent, handler ) - - ent:SetClip2( class.ClipSize2 ) - end, - - ["Attack"] = function( class, ent, handler ) - if ent:GetFiremode() == 1 then - class:Attack2( ent, handler ) - else - BaseClass.Attack( class, ent, handler ) - end - end, - - ["Reload"] = function( class, ent, handler ) - if ent:GetFiremode() == 1 then - class:Reload2( ent, handler ) - else - BaseClass.Reload( class, ent, handler ) - end - end, - - ["Alt"] = function( class, ent, handler ) - ent:SetFiremode( ent:GetFiremode() == 1 and 0 or 1 ) - end, - - ["Think"] = function( class, ent, handler ) - BaseClass.Think( class, ent, handler ) - - if ent:GetRefillTime2() != 0 and ent:GetRefillTime2() <= CurTime() then - ent:SetClip2( class.ClipSize2 ) - ent:SetRefillTime2( 0 ) - end - end, - - ["Reload2"] = function( class, ent, handler ) - if ent:GetClip2() >= class.ClipSize2 then return end - if ent:GetDelay2() > CurTime() then return end - handler:EmitSound( "weapons/m4a1/m4a1_boltpull.wav", 70, 125, 0.4, CHAN_STATIC ) - ent:SetDelay2( CurTime() + 0.25 ) - ent:SetRefillTime2( CurTime() + 0.1 ) - end, - - ["Attack2"] = function( class, ent, handler ) - if ent:GetClip2() <= 0 then return end - if ent:GetDelay2() > CurTime() then return end - if ent:GetDelayBurst2() > CurTime() then return end - if ent:GetBurstCount() >= class.BurstCount then return end - - ent:SetClip2( ent:GetClip2() - 1 ) - ent:SetDelay2( CurTime() + class.Delay2 ) - handler:EmitSound( "weapons/ar2/ar2_altfire.wav", 140, 100, 0.4, CHAN_STATIC ) - end, -}) - -local BaseClass = ITEMS.base -AddItem( "satchels", { - PrintName = "#Item.satchels.Name", - Description = "#Item.satchels.Description", - Category = "utility", - Base = "base", - - Model = "models/benny/weapons/testgun.mdl", - HoldType = "handgun", - - Vars = { - ["Float"] = { - "Delay", - }, - }, - - ["Attack"] = function( class, ent, handler ) - if ent:GetDelay() > CurTime() then return end - ent:SetDelay( CurTime() + 0.5 ) - - if SERVER then - for k, v in ipairs( ents.FindByClass( "b-satchel" ) ) do - if v:GetOwner() == ent:GetOwner() then - v:Detonate() - end - end - end - end, - - ["AttackAlt"] = function( class, ent, handler ) - if ent:GetDelay() > CurTime() then return end - ent:SetDelay( CurTime() + 0.5 ) - - local ply = ent:GetOwner() - if SERVER then - local bomb = ents.Create("b-satchel") - bomb:SetPos( ply:EyePos() + (ply:GetAimVector() * 32) ) - bomb:SetAngles( ply:EyeAngles() ) - bomb:SetOwner( ply ) - bomb:Spawn() - - local phy = bomb:GetPhysicsObject() - phy:SetVelocity( ply:GetAimVector() * 400 ) - phy:SetAngleVelocity( Vector( 0, 360, 0 ) ) - end - end, -}) - -local BaseClass = ITEMS.base -AddItem( "toolgun", { - PrintName = "#Item.toolgun.Name", - Description = "#Item.toolgun.Description", - Category = "dev", - Base = "base", - - Model = "models/benny/weapons/testgun.mdl", - HoldType = "handgun", - - Vars = { - ["Float"] = { - "Delay", - }, - ["Int"] = { - "BurstCount", - }, - }, - - ["Attack"] = function( class, ent, handler ) - if ent:GetBurstCount() >= 1 then return end - if ent:GetDelay() > CurTime() then return end - ent:SetDelay( CurTime() + 0.1 ) - ent:SetBurstCount( ent:GetBurstCount() + 1 ) - - handler:EmitSound("weapons/airboat/airboat_gun_lastshot1.wav", 100, 100, 1, CHAN_STATIC) - - if SERVER then - local p = handler:GetOwner() - local tr = p:GetEyeTrace() - - if lol then - local summon = ents.Create( "b-npc_human" ) - summon:SetPos( tr.HitPos + tr.HitNormal ) - local ang = Angle( 0, p:EyeAngles().y+0, 0 ) - summon:SetAngles( ang ) - summon:Spawn() - else - local summon = ents.Create( "benny_domflag" ) - summon:SetPos( tr.HitPos ) - local ang = Angle( 0, 0, 0 ) - summon:SetAngles( ang ) - summon:Spawn() - end - end - end, - - ["AttackAlt"] = function( class, ent, handler ) - if ent:GetDelay() > CurTime() then return end - ent:SetDelay( CurTime() + 0.5 ) - end, - - ["Reload"] = function( class, ent, handler ) - - end, - - ["Think"] = function( class, ent, handler ) - if ent:GetBurstCount() > 0 and !handler:GetOwner():KeyDown( IN_ATTACK ) then - ent:SetBurstCount( 0 ) - end - end, - - ["Deploy"] = function( class, ent, handler ) - ent:SetDelay( CurTime() + 0.5 ) - - local ply = handler:GetOwner() - ply:AddVCDSequenceToGestureSlot( GESTURE_SLOT_ATTACK_AND_RELOAD, ply:LookupSequence( AnimationLookup["deploy"][class.HoldType] ), 0, true ) - end, - - ["Holster"] = function( class, ent, handler ) - ent:SetDelay( CurTime() + 0.25 ) - - local ply = handler:GetOwner() - ply:AddVCDSequenceToGestureSlot( GESTURE_SLOT_ATTACK_AND_RELOAD, ply:LookupSequence( AnimationLookup["holster"][class.HoldType] ), 0, true ) - end, -}) - -local BaseClass = ITEMS.base_firearm -do -- Handguns - - AddItem( "mk23", { - PrintName = "#Item.mk23.Name", - Description = "#Item.mk23.Description", - Category = "pistol", - Base = "base_firearm", - - Model = "models/benny/weapons/test_mk23.mdl", - HoldType = "handgun", - DefaultBodygroups = { false, false, 1 }, - - ClipSize = 12, - Delay = (60/320), - FireSound = { - "benny/weapons/usp/sup_01.ogg", - "benny/weapons/usp/sup_02.ogg", - "benny/weapons/usp/sup_03.ogg", - }, - MagOutSound = "benny/weapons/usp/magout.ogg", - MagInSound = "benny/weapons/usp/magin.ogg", - BoltDropSound = "benny/weapons/usp/slidedrop.ogg", - BoltPullSound = "benny/weapons/glock/cock.ogg", - - Accuracy = 5/60, - BurstCount = 1, - Accuracy_Add = 0.5, - Accuracy_Reset = 0.4, - Accuracy_Decay = 5, - }) - - AddItem( "cz75", { - PrintName = "#Item.cz75.Name", - Description = "#Item.cz75.Description", - Category = "pistol", - Base = "base_firearm", - - Model = "models/benny/weapons/test_cz75.mdl", - HoldType = "handgun", - - ClipSize = 17, - Delay = (60/480), - FireSound = { - "benny/weapons/m92/01.ogg", - "benny/weapons/m92/02.ogg", - "benny/weapons/m92/03.ogg", - }, - MagOutSound = "benny/weapons/m92/magout.ogg", - MagInSound = "benny/weapons/m92/magin.ogg", - BoltDropSound = "benny/weapons/m92/slidedrop.ogg", - BoltPullSound = "benny/weapons/glock/cock.ogg", - - Accuracy = 5/60, - BurstCount = 1, - Accuracy_Add = 0.5, - Accuracy_Reset = 0.4, - Accuracy_Decay = 5, - }) - - AddItem( "g18", { - PrintName = "#Item.g18.Name", - Description = "#Item.g18.Description", - Category = "pistol", - Base = "base_firearm", - - Model = "models/benny/weapons/test_g18.mdl", - HoldType = "handgun", - - ClipSize = 33, - Delay = (60/1000), - FireSound = { - "benny/weapons/glock/01.ogg", - "benny/weapons/glock/02.ogg", - "benny/weapons/glock/03.ogg", - }, - MagOutSound = "benny/weapons/glock/magout.ogg", - MagInSound = "benny/weapons/glock/magin.ogg", - BoltDropSound = "benny/weapons/glock/cock.ogg", - BoltPullSound = "benny/weapons/glock/cock.ogg", - - Accuracy = 5/60, - --BurstCount = 1, - Accuracy_Add = 0.5, - Accuracy_Reset = 0.4, - Accuracy_Decay = 5, - }) - +function FinalizeItem( id ) + print( "[FinalizeItem] " .. id ) end -do -- Rifles - - AddItem( "fnc", { - PrintName = "#Item.fnc.Name", - Description = "#Item.fnc.Description", - Category = "assaultrifle", - Base = "base_firearm", - - Model = "models/benny/weapons/test_fnc.mdl",--"models/weapons/w_rif_ar556.mdl", - HoldType = "rifle", - - ClipSize = 30, - Delay = (60/800), - FireSound = { - "benny/weapons/m16a2/01.ogg", - "benny/weapons/m16a2/02.ogg", - "benny/weapons/m16a2/03.ogg", - }, - - Accuracy = 1, - Accuracy_Add = 0.4, - Accuracy_Reset = 0.4, - Accuracy_Decay = 12, - }) - - AddItem( "oicw", { - PrintName = "#Item.oicw.Name", - Description = "#Item.oicw.Description", - Category = "assaultrifle", - Base = "base_firearm_ubgl", - - Model = "models/benny/weapons/test_oicw.mdl", - HoldType = "rifle", - - ClipSize = 30, - Delay = (60/800), - FireSound = { - "benny/weapons/stoner63/01.ogg", - "benny/weapons/stoner63/02.ogg", - "benny/weapons/stoner63/03.ogg", - }, - - Accuracy = 1, - Accuracy_Add = 0.4, - Accuracy_Reset = 0.4, - Accuracy_Decay = 12, - }) - - AddItem( "qbz", { - PrintName = "#Item.qbz.Name", - Description = "#Item.qbz.Description", - Category = "assaultrifle", - Base = "base_firearm", - - Model = "models/benny/weapons/test_qbz.mdl",--"models/weapons/w_rif_ar556.mdl", - HoldType = "rifle", - - ClipSize = 30, - Delay = (60/750), - FireSound = { - "benny/weapons/stoner63/01.ogg", - "benny/weapons/stoner63/02.ogg", - "benny/weapons/stoner63/03.ogg", - }, - - Accuracy = 1, - Accuracy_Add = 0.4, - Accuracy_Reset = 0.4, - Accuracy_Decay = 12, - }) - - AddItem( "m16a2", { - PrintName = "#Item.m16a2.Name", - Description = "#Item.m16a2.Description", - Category = "assaultrifle", - Base = "base_firearm", - - Model = "models/benny/weapons/test_m16a2.mdl",--"models/weapons/w_rif_m16a2.mdl", - HoldType = "rifle", - - ClipSize = 30, - Delay = (60/1050), - BurstCount = 3, - BurstRunaway = true, - BurstAuto = true, - BurstDelay = 0.2, - FireSound = { - "benny/weapons/m16a2/01.ogg", - "benny/weapons/m16a2/02.ogg", - "benny/weapons/m16a2/03.ogg", - }, - - Accuracy = 1, - Accuracy_Add = 0.4, - Accuracy_Reset = 0.4, - Accuracy_Decay = 12, - }) - +function SetupAllItems() + print( "[SetupAllItems]" ) + InitializeItemFile( "base.lua" ) + InitializeItemFile( "firearms.lua" ) + --local files, directories = file.Find("benny/gamemode/items/*", "LUA") + --for index, filename in ipairs(files) do + -- InitializeItemFile( filename ) + --end + + if InitPostEntity_Complete then + for i, ent in ents.Iterator() do + if !ent.BennyItem then continue end + -- Maybe make a proper refresh function in the future + ent.Class = ITEMS[ent.ID] + ent.BaseClass = ITEMS[ent.Base] + end + end end +SetupAllItems() -do -- MGs - - AddItem( "qbb", { - PrintName = "#Item.qbb.Name", - Description = "#Item.qbb.Description", - Category = "machinegun", - Base = "base_firearm", - - Model = "models/benny/weapons/test_qbb.mdl", - HoldType = "rifle", - - ClipSize = 75, - Delay = (60/750), - FireSound = { - "benny/weapons/stoner63/01.ogg", - "benny/weapons/stoner63/02.ogg", - "benny/weapons/stoner63/03.ogg", - }, - - Accuracy = 1, - Accuracy_Add = 0.4, - Accuracy_Reset = 0.4, - Accuracy_Decay = 12, - }) - - AddItem( "stoner", { - PrintName = "#Item.stoner.Name", - Description = "#Item.stoner.Description", - Category = "machinegun", - Base = "base_firearm", - - Model = "models/benny/weapons/test_stoner.mdl", - HoldType = "rifle", - - ClipSize = 100, - Delay = (60/880), - FireSound = { - "benny/weapons/stoner63/01.ogg", - "benny/weapons/stoner63/02.ogg", - "benny/weapons/stoner63/03.ogg", - }, - - Accuracy = 1, - Accuracy_Add = 0.4, - Accuracy_Reset = 0.4, - Accuracy_Decay = 12, - }) - - AddItem( "hk21", { - PrintName = "#Item.hk21.Name", - Description = "#Item.hk21.Description", - Category = "machinegun", - Base = "base_firearm", - - Model = "models/benny/weapons/test_hk21.mdl", - HoldType = "rifle", - - ClipSize = 70, - Delay = (60/640), - FireSound = { - "benny/weapons/hk21/39_01.ogg", - "benny/weapons/hk21/39_02.ogg", - "benny/weapons/hk21/39_03.ogg", - }, - - Accuracy = 1, - Accuracy_Add = 0.4, - Accuracy_Reset = 0.4, - Accuracy_Decay = 12, - }) - -end - -do -- SMGs - - AddItem( "tmp", { - PrintName = "#Item.tmp.Name", - Description = "#Item.tmp.Description", - Category = "smg", - Base = "base_firearm", - - Model = "models/benny/weapons/test_tmp.mdl",--"models/weapons/w_rif_ar556.mdl", - HoldType = "handgun", - - ClipSize = 25, - Delay = (60/850), - FireSound = { - "benny/weapons/tmp/01.ogg", - "benny/weapons/tmp/02.ogg", - "benny/weapons/tmp/03.ogg", - }, - }) - - AddItem( "mp7", { - PrintName = "#Item.mp7.Name", - Description = "#Item.mp7.Description", - Category = "smg", - Base = "base_firearm", - - Model = "models/benny/weapons/test_mp7.mdl",--"models/weapons/w_rif_ar556.mdl", - HoldType = "handgun", - - ClipSize = 20, - Delay = (60/950), - FireSound = { - "benny/weapons/mp7/01.ogg", - "benny/weapons/mp7/02.ogg", - "benny/weapons/mp7/03.ogg", - }, - }) - - AddItem( "mp5k", { - PrintName = "#Item.mp5k.Name", - Description = "#Item.mp5k.Description", - Category = "smg", - Base = "base_firearm", - - Model = "models/benny/weapons/test_mp5k.mdl",--"models/weapons/w_rif_ar556.mdl", - HoldType = "handgun", - - ClipSize = 30, - Delay = (60/750), - FireSound = { - "benny/weapons/mp5k/01.ogg", - "benny/weapons/mp5k/02.ogg", - "benny/weapons/mp5k/03.ogg", - }, - }) - - AddItem( "mac11", { - PrintName = "#Item.mac11.Name", - Description = "#Item.mac11.Description", - Category = "smg", - Base = "base_firearm", - - Model = "models/benny/weapons/test_mac10.mdl",--"models/weapons/w_rif_ar556.mdl", - HoldType = "handgun", - - ClipSize = 20, - Delay = (60/1000), - FireSound = { - "benny/weapons/mac11/01.ogg", - "benny/weapons/mac11/02.ogg", - "benny/weapons/mac11/03.ogg", - }, - }) - -end - -do -- Shotguns - - AddItem( "spas12", { - PrintName = "#Item.spas12.Name", - Description = "#Item.spas12.Description", - Category = "shotgun", - Base = "base_firearm", - - Model = "models/benny/weapons/test_spas12.mdl", - HoldType = "rifle", - - ClipSize = 8, - Pellets = 8, - Delay = 0.4, - BurstCount = 1, - FireSound = { - "benny/weapons/spas12/01.ogg", - "benny/weapons/spas12/02.ogg", - "benny/weapons/spas12/03.ogg", - }, - MagOutSound = "benny/weapons/spas12/magout-01.ogg", - MagInSound = "benny/weapons/spas12/magout-02.ogg", - BoltDropSound = "benny/weapons/spas12/magin.ogg", - BoltPullSound = "benny/weapons/glock/magin.ogg", - - Accuracy = 8, - Accuracy_Add = 0.4, - Accuracy_Reset = 0.4, - Accuracy_Decay = 12, - }) - - AddItem( "aa12", { - PrintName = "#Item.aa12.Name", - Description = "#Item.aa12.Description", - Category = "shotgun", - Base = "base_firearm", - - Model = "models/benny/weapons/test_aa12.mdl", - HoldType = "rifle", - - ClipSize = 8, - Pellets = 8, - Delay = 0.22, - BurstCount = 1, - FireSound = { - "benny/weapons/spas12/01.ogg", - "benny/weapons/spas12/02.ogg", - "benny/weapons/spas12/03.ogg", - }, - MagOutSound = "benny/weapons/spas12/magout-01.ogg", - MagInSound = "benny/weapons/spas12/magout-02.ogg", - BoltDropSound = "benny/weapons/spas12/magin.ogg", - BoltPullSound = "benny/weapons/glock/magin.ogg", - - Accuracy = 8, - Accuracy_Add = 0.4, - Accuracy_Reset = 0.4, - Accuracy_Decay = 12, - }) - - AddItem( "db", { - PrintName = "#Item.db.Name", - Description = "#Item.db.Description", - Category = "shotgun", - Base = "base_firearm", - - Model = "models/benny/weapons/test_db.mdl", - HoldType = "rifle", - - ClipSize = 2, - Pellets = 8, - Delay = 0.4, - BurstCount = 1, - FireSound = { - "benny/weapons/spas12/01.ogg", - "benny/weapons/spas12/02.ogg", - "benny/weapons/spas12/03.ogg", - }, - MagOutSound = "benny/weapons/spas12/magout-01.ogg", - MagInSound = "benny/weapons/spas12/magout-02.ogg", - BoltDropSound = "benny/weapons/spas12/magin.ogg", - BoltPullSound = "benny/weapons/glock/magin.ogg", - - Accuracy = 4, - Accuracy_Add = 0.4, - Accuracy_Reset = 0.4, - Accuracy_Decay = 12, - }) - - AddItem( "1887", { - PrintName = "#Item.1887.Name", - Description = "#Item.1887.Description", - Category = "shotgun", - Base = "base_firearm", - - Model = "models/benny/weapons/test_1887.mdl", - HoldType = "rifle", - - ClipSize = 5, - Pellets = 8, - Delay = 0.4, - BurstCount = 1, - FireSound = { - "benny/weapons/spas12/01.ogg", - "benny/weapons/spas12/02.ogg", - "benny/weapons/spas12/03.ogg", - }, - MagOutSound = "benny/weapons/spas12/magout-01.ogg", - MagInSound = "benny/weapons/spas12/magout-02.ogg", - BoltDropSound = "benny/weapons/spas12/magin.ogg", - BoltPullSound = "benny/weapons/glock/magin.ogg", - - Accuracy = 8, - Accuracy_Add = 0.4, - Accuracy_Reset = 0.4, - Accuracy_Decay = 12, - }) - - AddItem( "spas15", { - PrintName = "#Item.spas15.Name", - Description = "#Item.spas15.Description", - Category = "shotgun", - Base = "base_firearm", - - Model = "models/benny/weapons/test_spas15.mdl", - HoldType = "rifle", - - ClipSize = 6, - Pellets = 8, - Delay = 0.6, - BurstCount = 1, - FireSound = { - "benny/weapons/spas12/01.ogg", - "benny/weapons/spas12/02.ogg", - "benny/weapons/spas12/03.ogg", - }, - MagOutSound = "benny/weapons/spas12/magout-01.ogg", - MagInSound = "benny/weapons/spas12/magout-02.ogg", - BoltDropSound = "benny/weapons/spas12/magin.ogg", - BoltPullSound = "benny/weapons/glock/magin.ogg", - - Accuracy = 8, - Accuracy_Add = 0.4, - Accuracy_Reset = 0.4, - Accuracy_Decay = 12, - }) - - AddItem( "r870", { - PrintName = "#Item.r870.Name", - Description = "#Item.r870.Description", - Category = "shotgun", - Base = "base_firearm", - - Model = "models/benny/weapons/test_r870.mdl", - HoldType = "rifle", - - ClipSize = 4, - Pellets = 8, - Delay = 0.6, - BurstCount = 1, - FireSound = { - "benny/weapons/spas12/01.ogg", - "benny/weapons/spas12/02.ogg", - "benny/weapons/spas12/03.ogg", - }, - MagOutSound = "benny/weapons/spas12/magout-01.ogg", - MagInSound = "benny/weapons/spas12/magout-02.ogg", - BoltDropSound = "benny/weapons/spas12/magin.ogg", - BoltPullSound = "benny/weapons/glock/magin.ogg", - - Accuracy = 8, - Accuracy_Add = 0.4, - Accuracy_Reset = 0.4, - Accuracy_Decay = 12, - }) - - AddItem( "striker", { - PrintName = "#Item.striker.Name", - Description = "#Item.striker.Description", - Category = "shotgun", - Base = "base_firearm", - - Model = "models/benny/weapons/test_striker.mdl", - HoldType = "rifle", - - ClipSize = 12, - Pellets = 8, - Delay = 0.3, - BurstCount = 1, - FireSound = { - "benny/weapons/spas12/01.ogg", - "benny/weapons/spas12/02.ogg", - "benny/weapons/spas12/03.ogg", - }, - MagOutSound = "benny/weapons/spas12/magout-01.ogg", - MagInSound = "benny/weapons/spas12/magout-02.ogg", - BoltDropSound = "benny/weapons/spas12/magin.ogg", - BoltPullSound = "benny/weapons/glock/magin.ogg", - - Accuracy = 8, - Accuracy_Add = 0.4, - Accuracy_Reset = 0.4, - Accuracy_Decay = 12, - }) - -end - --- bat --- bat_wood --- machete --- kabar --- baton - --- deagle --- cz75a --- glock --- 1911 --- mk23 --- nambu --- anaconda - --- tmp --- mp7 --- mp5k --- mac11 --- bizon --- chicom - --- fnc --- qbz --- m16a2 - -for ID, Data in pairs(ITEMS) do - local tent = {} - tent.Base = "b-itembase" - tent.PrintName = Data.PrintName or ID - tent.ID = ID - tent.Class = ITEMS[ID] - tent.Spawnable = true - tent.AdminOnly = false - tent.Category = "Other" - - -- print("aei_" .. ID) - scripted_ents.Register( tent, "b-item_" .. ID ) -end \ No newline at end of file +hook.Add("InitPostEntity", "Benny_InitPostEntity_Refresh", function() + InitPostEntity_Complete = true +end) \ No newline at end of file diff --git a/gamemodes/benny/gamemode/items/base.lua b/gamemodes/benny/gamemode/items/base.lua new file mode 100644 index 0000000..43edeeb --- /dev/null +++ b/gamemodes/benny/gamemode/items/base.lua @@ -0,0 +1,81 @@ + +do -- Base + local ITEM, Base = CreateItem( "base" ) + + ITEM.PrintName = "Item Base" + ITEM.Description = "Testing testing" + ITEM.Category = "base" + + ITEM.Model = bModel("weapons/test_g18") + ITEM.DefaultBodygroups = {} + ITEM.HoldType = "handgun" + + ITEM.Vars = { + ["Float"] = { + "Acquisition", + "HolsterIn", + }, + } + + ITEM.DeploySound = bSound("dev/magpouch.ogg") + ITEM.StartHolsterSound = bSound("dev/magpouch_replace_small.ogg") + ITEM.FinishHolsterSound = bSound("dev/holster.ogg") + ITEM.CancelHolsterSound = bSound("dev/grab.ogg") + + function ITEM:EntInitialize() + print( self ) + for k, v in ipairs(self.DefaultBodygroups) do + if v then + self:SetBodygroup( k-1, v ) + end + end + end + + function ITEM:Sound( soundName, soundLevel, pitchPercent, volume, channel, soundFlags, dsp, filter ) + local emiton = self + if self:GetHandler():IsValid() then + emiton = self:GetHandler() + end + emiton:EmitSound( soundName, soundLevel, pitchPercent, volume, channel, soundFlags, dsp ) + end + + function ITEM:Attack() end + function ITEM:AttackAlt() end + + function ITEM:Think() + if self:GetHolsterIn() != 0 and self:GetHolsterIn() <= CurTime() then + self:FinishHolster() + self:SetHolsterIn( 0 ) + end + end + + function ITEM:PlayerAnimation( seqname ) + local p = self:GetOwner() + p:DoAnimationEvent( p:LookupSequence( seqname ) ) + end + + function ITEM:EntThink() end + function ITEM:EntPhysicsCollide() end + function ITEM:Reload() end + function ITEM:Drop() end + function ITEM:Deploy() + self:Sound( self.DeploySound, 70, 100, 0.4 ) + end + + function ITEM:StartHolster() + self:Sound( self.StartHolsterSound, 70, 100, 0.4 ) + self:SetHolsterIn( CurTime() + 0.25 ) + end + + function ITEM:FinishHolster() + self:Sound( self.FinishHolsterSound, 70, 100, 0.4, CHAN_STATIC ) + + self:GetHandler():SetActiveR( NULL ) + self:SetNoDraw( true ) + end + + function ITEM:CancelHolster() + self:SetHolsterIn( 0 ) + self:Sound( self.CancelHolsterSound, 70, 100, 0.4 ) + end +end \ No newline at end of file diff --git a/gamemodes/benny/gamemode/items/firearms.lua b/gamemodes/benny/gamemode/items/firearms.lua new file mode 100644 index 0000000..af08ee7 --- /dev/null +++ b/gamemodes/benny/gamemode/items/firearms.lua @@ -0,0 +1,268 @@ + + +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 + diff --git a/gamemodes/benny/gamemode/languages/en-us.lua b/gamemodes/benny/gamemode/languages/en-us.lua index 6fb86e7..f2087a1 100644 --- a/gamemodes/benny/gamemode/languages/en-us.lua +++ b/gamemodes/benny/gamemode/languages/en-us.lua @@ -134,6 +134,25 @@ L["Gamemode.dem.Description"] = "One half tries to destroy the other halves o L["Gamemode.hp.Name"] = "Hardpoint" L["Gamemode.hp.Description"] = "Several teams fight to hold a singular capture point for the longest amount of time." +-- Categories +L["ItemCategory.pistol.Name"] = "Handgun" +L["ItemCategory.pistol.Description"] = "Lightweight sidearm. Drawn and reloaded quickly." + +L["ItemCategory.smg.Name"] = "Sub-machine Gun" +L["ItemCategory.smg.Description"] = "Lightweight automatic weapon. Fires pistol cartridges." + +L["ItemCategory.assaultrifle.Name"] = "Assault Rifle" +L["ItemCategory.assaultrifle.Description"] = "High stopping power, but poor maneuverability." + +L["ItemCategory.machinegun.Name"] = "Machine Gun" +L["ItemCategory.machinegun.Description"] = "Automatic weapon designed for sustained fire." + +L["ItemCategory.shotgun.Name"] = "Shotgun" +L["ItemCategory.shotgun.Description"] = "Great in close-quarters combat." + +L["ItemCategory.utility.Name"] = "Utility" +L["ItemCategory.utility.Description"] = "Throwables and deployables." + -- Teams L["Team.cia.Name"] = "CIA" L["Team.cia.Description"] = "CIA black ops, coverup crew" diff --git a/gamemodes/benny/gamemode/player.lua b/gamemodes/benny/gamemode/player.lua index eb792c9..530571f 100644 --- a/gamemodes/benny/gamemode/player.lua +++ b/gamemodes/benny/gamemode/player.lua @@ -189,7 +189,13 @@ function PT:HandlerCheck() return ( wep:IsValid() and wep:GetClass() == "itemhandler" and wep.GetActiveR ) and wep or false end --- Temporary +-- breaks GESTURE_SLOT_ATTACK_AND_RELOAD and I can't fucking have that +hook.Add("DoAnimationEvent", "Benny_DoAnimationEvent_FixAnimations", function( p, event, data ) + if event == PLAYERANIMEVENT_CUSTOM_GESTURE then + p:AddVCDSequenceToGestureSlot( GESTURE_SLOT_ATTACK_AND_RELOAD, data, 0, true ) + end + return ACT_INVALID +end) function GM:UpdateAnimation( ply, vel, maxseqgroundspeed ) ply:SetPlaybackRate( 1 ) @@ -230,7 +236,10 @@ function GM:UpdateAnimation( ply, vel, maxseqgroundspeed ) magic = magic * 0.75 - ply:SetPoseParameter( "aim_p", -ply:EyeAngles().p/90 ) + local ea = ply:EyeAngles() + ea:Normalize() + + ply:SetPoseParameter( "aim_p", -ea.p/90 ) ply:SetPoseParameter( "aim_y", 0 )--magic/90 ) diff --git a/gamemodes/benny/gamemode/shared.lua b/gamemodes/benny/gamemode/shared.lua index c1c8575..6c240e3 100644 --- a/gamemodes/benny/gamemode/shared.lua +++ b/gamemodes/benny/gamemode/shared.lua @@ -42,6 +42,18 @@ function TSelShared( tbl, seed ) return tbl[math.Round( util.SharedRandom( seed, 1, #tbl ) )] end +function bModel( input ) + local str = "models/benny/" .. input .. ".mdl" + util.PrecacheModel( str ) + return str +end + +function bSound( input ) + local str = "benny/" .. input + util.PrecacheSound( str ) + return str +end + -- Language might want to be loaded first -- Otherwise things will fail to call 'l8' AC("language.lua")