From 787d9aacbd5a7a5918ecb9a3ca4dfcae39916edc Mon Sep 17 00:00:00 2001 From: Fesiug Date: Tue, 14 Nov 2023 01:32:08 -0500 Subject: [PATCH] Grenades can now select more of their own class --- .../gamemode/modules/player/sh_player.lua | 12 ++++++ .../gamemode/modules/weapons/sh_weapons.lua | 37 +++++++++++-------- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/gamemodes/benny/gamemode/modules/player/sh_player.lua b/gamemodes/benny/gamemode/modules/player/sh_player.lua index a1f60f8..54f3117 100644 --- a/gamemodes/benny/gamemode/modules/player/sh_player.lua +++ b/gamemodes/benny/gamemode/modules/player/sh_player.lua @@ -48,6 +48,18 @@ function PT:INV_Discard( id ) end end +function PT:INV_Find( class ) + local inv = self:INV_Get() + local results = {} + for i, v in pairs( inv ) do + if v.Class == class then + table.insert( results, i ) + end + end + table.sort( results, function( a, b ) return inv[b]["Acquisition"] > inv[a]["Acquisition"] end) + return results +end + do local translat = { ["melee"] = { 1, 1 }, diff --git a/gamemodes/benny/gamemode/modules/weapons/sh_weapons.lua b/gamemodes/benny/gamemode/modules/weapons/sh_weapons.lua index 584f28e..be83b8e 100644 --- a/gamemodes/benny/gamemode/modules/weapons/sh_weapons.lua +++ b/gamemodes/benny/gamemode/modules/weapons/sh_weapons.lua @@ -898,7 +898,7 @@ do -- Grenades, nothing here is guaranteed. return true end - local function GrenadeThrow( self, data ) + local function GrenadeCreate( self, data ) -- PROTO: See to getting this done better. Maybe it's spawned while priming the nade for low CL-SV/phys delay? local p = self:GetOwner() local class = WEAPONS[data.Class] @@ -918,19 +918,31 @@ do -- Grenades, nothing here is guaranteed. GENT:GetPhysicsObject():SetVelocity( velocity ) end + local function GrenadeThrow( self, data ) + local p = self:GetOwner() + local class = WEAPONS[data.Class] + self:SetGrenadeDown( false ) + -- TEMP: Do this right! + if !class.GrenadeCharge then self:SetGrenadeDownStart( CurTime() ) end + -- + self:TPFire() + if SERVER then GrenadeCreate( self, data ) end + local id = self:D_GetID( false ) + self:BHolster( false ) + p:INV_Discard( id ) + + local subsequent = p:INV_Find( data.Class )[1] + if subsequent then + self:BDeploy( false, subsequent ) + end + end + local function GrenadeThink( self, data ) local p = self:GetOwner() local class = WEAPONS[data.Class] if self:GetGrenadeDown() then if !p:KeyDown( IN_ATTACK ) or ( CurTime() >= (self:GetGrenadeDownStart() + class.GrenadeFuse) ) then - self:SetGrenadeDown( false ) - -- TEMP: Do this right! - if !class.GrenadeCharge then self:SetGrenadeDownStart( CurTime() ) end - self:TPFire() - if SERVER then GrenadeThrow( self, data ) end - local id = self:D_GetID( false ) - self:BHolster( false ) - p:INV_Discard( id ) + GrenadeThrow( self, data ) end end return true @@ -938,12 +950,7 @@ do -- Grenades, nothing here is guaranteed. local function GrenadeHolster( self, data ) if self:GetGrenadeDown() then - self:SetGrenadeDown( false ) - self:TPFire() - if SERVER then GrenadeThrow( self, data ) end - local id = self:D_GetID( false ) - self:BHolster( false ) - p:INV_Discard( id ) + GrenadeThrow( self, data ) end return true end