Grenades can now select more of their own class

This commit is contained in:
Fesiug 2023-11-14 01:32:08 -05:00
parent 8ed9ad5ab2
commit 787d9aacbd
2 changed files with 34 additions and 15 deletions

View File

@ -48,6 +48,18 @@ function PT:INV_Discard( id )
end end
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 do
local translat = { local translat = {
["melee"] = { 1, 1 }, ["melee"] = { 1, 1 },

View File

@ -898,7 +898,7 @@ do -- Grenades, nothing here is guaranteed.
return true return true
end 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? -- 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 p = self:GetOwner()
local class = WEAPONS[data.Class] local class = WEAPONS[data.Class]
@ -918,19 +918,31 @@ do -- Grenades, nothing here is guaranteed.
GENT:GetPhysicsObject():SetVelocity( velocity ) GENT:GetPhysicsObject():SetVelocity( velocity )
end 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 function GrenadeThink( self, data )
local p = self:GetOwner() local p = self:GetOwner()
local class = WEAPONS[data.Class] local class = WEAPONS[data.Class]
if self:GetGrenadeDown() then if self:GetGrenadeDown() then
if !p:KeyDown( IN_ATTACK ) or ( CurTime() >= (self:GetGrenadeDownStart() + class.GrenadeFuse) ) then if !p:KeyDown( IN_ATTACK ) or ( CurTime() >= (self:GetGrenadeDownStart() + class.GrenadeFuse) ) then
self:SetGrenadeDown( false ) GrenadeThrow( self, data )
-- 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 )
end end
end end
return true return true
@ -938,12 +950,7 @@ do -- Grenades, nothing here is guaranteed.
local function GrenadeHolster( self, data ) local function GrenadeHolster( self, data )
if self:GetGrenadeDown() then if self:GetGrenadeDown() then
self:SetGrenadeDown( false ) GrenadeThrow( self, data )
self:TPFire()
if SERVER then GrenadeThrow( self, data ) end
local id = self:D_GetID( false )
self:BHolster( false )
p:INV_Discard( id )
end end
return true return true
end end