Enhanced functionality for grenades

This commit is contained in:
Fesiug 2023-11-13 21:48:11 -05:00
parent 208a995d02
commit 6567777bcc
5 changed files with 78 additions and 37 deletions

View File

@ -22,6 +22,9 @@ function ENT:Initialize()
else else
self:SetModelScale( 2 ) self:SetModelScale( 2 )
end end
timer.Simple( 0, function()
self:Think()
end)
return return
end end
@ -29,7 +32,8 @@ function ENT:Think()
if SERVER and self.Fuse <= CurTime() then if SERVER and self.Fuse <= CurTime() then
self:Explode() self:Explode()
end end
return self:NextThink( CurTime() )
return true
end end
local explosionflags = 0x2 + 0x4 + 0x80 local explosionflags = 0x2 + 0x4 + 0x80

View File

@ -65,7 +65,7 @@ function SWEP:BHolster( hand )
local item = inv[hand and self:GetWep2() or self:GetWep1()] local item = inv[hand and self:GetWep2() or self:GetWep1()]
local class = WEAPONS[item.Class] local class = WEAPONS[item.Class]
if class.Holster then class.Holster( self ) end if class.Holster then class.Holster( self, self:BTable( false ) ) end
self:DSetWep( hand, "" ) self:DSetWep( hand, "" )

View File

@ -30,6 +30,7 @@ function SWEP:SetupDataTables()
self:NetworkVar( "Float", 0, "Aim" ) self:NetworkVar( "Float", 0, "Aim" )
self:NetworkVar( "Float", 1, "Delay1" ) self:NetworkVar( "Float", 1, "Delay1" )
self:NetworkVar( "Float", 2, "Delay2" ) self:NetworkVar( "Float", 2, "Delay2" )
self:NetworkVar( "Float", 3, "GrenadeDownStart" )
self:NetworkVar( "String", 0, "Wep1" ) self:NetworkVar( "String", 0, "Wep1" )
self:NetworkVar( "String", 1, "Wep2" ) self:NetworkVar( "String", 1, "Wep2" )
self:NetworkVar( "Int", 0, "Wep1Clip" ) self:NetworkVar( "Int", 0, "Wep1Clip" )
@ -37,6 +38,7 @@ function SWEP:SetupDataTables()
self:NetworkVar( "Int", 2, "Wep1Burst" ) self:NetworkVar( "Int", 2, "Wep1Burst" )
self:NetworkVar( "Int", 3, "Wep2Burst" ) self:NetworkVar( "Int", 3, "Wep2Burst" )
self:NetworkVar( "Bool", 0, "UserAim" ) self:NetworkVar( "Bool", 0, "UserAim" )
self:NetworkVar( "Bool", 1, "GrenadeDown" )
end end
function SWEP:PrimaryAttack() function SWEP:PrimaryAttack()
@ -44,7 +46,7 @@ function SWEP:PrimaryAttack()
return return
end end
if self:BClass().Fire then if self:BClass().Fire then
if self:BClass( false ).Fire( self, self:BClass( false ), self:BTable( false ) ) then return end if self:BClass( false ).Fire( self, self:BTable( false ) ) then return end
end end
if self:GetDelay1() > CurTime() then if self:GetDelay1() > CurTime() then
return return
@ -116,7 +118,7 @@ end
function SWEP:Reload() function SWEP:Reload()
if self:BTable( false ) and self:GetOwner():KeyPressed( IN_RELOAD ) then if self:BTable( false ) and self:GetOwner():KeyPressed( IN_RELOAD ) then
if self:BClass().Reload then if self:BClass().Reload then
if self:BClass( false ).Reload( self, self:BClass( false ), self:BTable( false ) ) then return end if self:BClass( false ).Reload( self, self:BTable( false ) ) then return end
end end
if self:GetDelay1() > CurTime() then if self:GetDelay1() > CurTime() then
return false return false
@ -176,7 +178,7 @@ function SWEP:Think()
if self:BClass( false ) then if self:BClass( false ) then
if self:BClass( false ).Think then if self:BClass( false ).Think then
self:BClass( false ).Think( self, self:BClass( false ), self:BTable( false ) ) self:BClass( false ).Think( self, self:BTable( false ) )
end end
end end

View File

@ -318,12 +318,26 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
surface.SetTextPos( sw - b - ss(w-6), sh - b - ss(BOXHEIGHT-3) ) surface.SetTextPos( sw - b - ss(w-6), sh - b - ss(BOXHEIGHT-3) )
surface.DrawText( wep1c.Name or "???" ) surface.DrawText( wep1c.Name or "???" )
local fmpw = 30
surface.SetDrawColor( scheme["fg"] )
surface.DrawRect( sw - b - ss(w-4), sh - b + ss(16) - ss(BOXHEIGHT-4), ss(fmpw), ss(10) )
-- PROTO: Make grenade/melee/firearm logic way way better. -- PROTO: Make grenade/melee/firearm logic way way better.
if wep1c.Features == "firearm" then if wep1c.Features == "grenade" then
if wep:GetGrenadeDown() then
local perc = math.TimeFraction( wep:GetGrenadeDownStart(), wep:GetGrenadeDownStart()+wep1c.GrenadeFuse, CurTime() )
perc = 1-math.Clamp( perc, 0, 1 )
surface.SetDrawColor( scheme["fg"] )
local spruce = (w-127)
for i=0, math.Round(spruce) do
if (i/spruce) < perc then
surface.DrawRect( sw - b - ss(w-4) + ss(5*i), sh - b - ss(10+4), ss(3), ss(10) )
else
surface.DrawOutlinedRect( sw - b - ss(w-4) + ss(5*i), sh - b - ss(10+4), ss(3), ss(10), ss(0.5) )
end
end
end
elseif wep1c.Features == "firearm" then
local fmpw = 30
surface.SetDrawColor( scheme["fg"] )
surface.DrawRect( sw - b - ss(w-4), sh - b + ss(16) - ss(BOXHEIGHT-4), ss(fmpw), ss(10) )
surface.SetFont( "Benny_12" ) surface.SetFont( "Benny_12" )
local str = wep:B_FiremodeName( false ) local str = wep:B_FiremodeName( false )
local tw = surface.GetTextSize( str ) local tw = surface.GetTextSize( str )
@ -880,7 +894,7 @@ do
if bucket_selected > #buckets then bucket_selected = 1 item_selected = 1 end if bucket_selected > #buckets then bucket_selected = 1 item_selected = 1 end
if buckets[bucket_selected][item_selected] then if buckets[bucket_selected][item_selected] then
Equip() Equip()
break return
end end
end end
end, end,
@ -902,7 +916,7 @@ do
item_selected = #buckets[bucket_selected] item_selected = #buckets[bucket_selected]
if buckets[bucket_selected][item_selected] then if buckets[bucket_selected][item_selected] then
Equip() Equip()
break return
end end
end end
end end

View File

@ -201,7 +201,7 @@ do -- Toolgun
Ammo = 0, Ammo = 0,
Damage = 0, Damage = 0,
Fire = function( self, slot ) Fire = function( self, data )
if self:GetDelay1() > CurTime() then if self:GetDelay1() > CurTime() then
return true return true
end end
@ -226,7 +226,7 @@ do -- Toolgun
return true return true
end, end,
Reload = function( self, slot ) Reload = function( self, data )
if CLIENT and self:GetOwner():KeyPressed( IN_RELOAD ) then if CLIENT and self:GetOwner():KeyPressed( IN_RELOAD ) then
CreateSelect() CreateSelect()
end end
@ -882,41 +882,61 @@ end
do -- Grenades, nothing here is guaranteed. do -- Grenades, nothing here is guaranteed.
local function GrenadeFire( self, class, table ) local function GrenadeFire( self, data )
local p = self:GetOwner() local p = self:GetOwner()
if self:GetDelay1() > CurTime() then if self:GetGrenadeDown() then
return true return true
end end
self:SetDelay1( CurTime() + 0.1 )
self:TPFire() self:SetGrenadeDown( true )
self:SetGrenadeDownStart( CurTime() )
return true
end
local function GrenadeReload( self, data )
return true
end
local function GrenadeThrow( 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?
if SERVER then local p = self:GetOwner()
local GENT = ents.Create( class.GrenadeEnt ) local class = WEAPONS[data.Class]
GENT:SetOwner( p ) local GENT = ents.Create( class.GrenadeEnt )
local ang = p:EyeAngles() GENT:SetOwner( p )
ang.p = ang.p - 5 local ang = p:EyeAngles()
GENT:SetPos( p:EyePos() + (ang:Forward()*16) ) ang.p = ang.p - 5
GENT:SetAngles( ang + Angle( 0, 0, -90 ) ) GENT:SetPos( p:EyePos() + (ang:Forward()*16) )
GENT.Fuse = CurTime() + class.GrenadeFuse GENT:SetAngles( ang + Angle( 0, 0, -90 ) )
GENT:Spawn() GENT.Fuse = self:GetGrenadeDownStart() + class.GrenadeFuse
GENT:Spawn()
local velocity = ang:Forward() * 1500 local velocity = ang:Forward() * 1500
velocity:Mul( Lerp( math.TimeFraction( 90, 0, ang.p ), 0, 1 ) ) velocity:Mul( Lerp( math.TimeFraction( 90, 0, ang.p ), 0, 1 ) )
-- velocity:Add( p:EyeAngles():Up() * 500 * Lerp( math.TimeFraction( 0, -90, p:EyeAngles().p ), 0, 1 ) ) -- velocity:Add( p:EyeAngles():Up() * 500 * Lerp( math.TimeFraction( 0, -90, p:EyeAngles().p ), 0, 1 ) )
GENT:GetPhysicsObject():SetVelocity( velocity ) GENT:GetPhysicsObject():SetVelocity( velocity )
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 )
self:TPFire()
if SERVER then GrenadeThrow( self, data ) end
end
end end
return true return true
end end
local function GrenadeReload( self, class ) local function GrenadeHolster( self, data )
return true if self:GetGrenadeDown() then
end self:SetGrenadeDown( false )
self:TPFire()
local function GrenadeThink( self, class ) if SERVER then GrenadeThrow( self, data ) end
end
return true return true
end end
@ -928,6 +948,7 @@ do -- Grenades, nothing here is guaranteed.
Fire = GrenadeFire, Fire = GrenadeFire,
Reload = GrenadeReload, Reload = GrenadeReload,
Think = GrenadeThink, Think = GrenadeThink,
Holster = GrenadeHolster,
GrenadeEnt = "benny_grenade_frag", GrenadeEnt = "benny_grenade_frag",
GrenadeFuse = 4, GrenadeFuse = 4,
GrenadeCharge = true, GrenadeCharge = true,