Enhanced functionality for grenades
This commit is contained in:
parent
208a995d02
commit
6567777bcc
|
@ -22,6 +22,9 @@ function ENT:Initialize()
|
|||
else
|
||||
self:SetModelScale( 2 )
|
||||
end
|
||||
timer.Simple( 0, function()
|
||||
self:Think()
|
||||
end)
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -29,7 +32,8 @@ function ENT:Think()
|
|||
if SERVER and self.Fuse <= CurTime() then
|
||||
self:Explode()
|
||||
end
|
||||
return
|
||||
self:NextThink( CurTime() )
|
||||
return true
|
||||
end
|
||||
|
||||
local explosionflags = 0x2 + 0x4 + 0x80
|
||||
|
|
|
@ -65,7 +65,7 @@ function SWEP:BHolster( hand )
|
|||
local item = inv[hand and self:GetWep2() or self:GetWep1()]
|
||||
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, "" )
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ function SWEP:SetupDataTables()
|
|||
self:NetworkVar( "Float", 0, "Aim" )
|
||||
self:NetworkVar( "Float", 1, "Delay1" )
|
||||
self:NetworkVar( "Float", 2, "Delay2" )
|
||||
self:NetworkVar( "Float", 3, "GrenadeDownStart" )
|
||||
self:NetworkVar( "String", 0, "Wep1" )
|
||||
self:NetworkVar( "String", 1, "Wep2" )
|
||||
self:NetworkVar( "Int", 0, "Wep1Clip" )
|
||||
|
@ -37,6 +38,7 @@ function SWEP:SetupDataTables()
|
|||
self:NetworkVar( "Int", 2, "Wep1Burst" )
|
||||
self:NetworkVar( "Int", 3, "Wep2Burst" )
|
||||
self:NetworkVar( "Bool", 0, "UserAim" )
|
||||
self:NetworkVar( "Bool", 1, "GrenadeDown" )
|
||||
end
|
||||
|
||||
function SWEP:PrimaryAttack()
|
||||
|
@ -44,7 +46,7 @@ function SWEP:PrimaryAttack()
|
|||
return
|
||||
end
|
||||
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
|
||||
if self:GetDelay1() > CurTime() then
|
||||
return
|
||||
|
@ -116,7 +118,7 @@ end
|
|||
function SWEP:Reload()
|
||||
if self:BTable( false ) and self:GetOwner():KeyPressed( IN_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
|
||||
if self:GetDelay1() > CurTime() then
|
||||
return false
|
||||
|
@ -176,7 +178,7 @@ function SWEP:Think()
|
|||
|
||||
if self:BClass( false ) 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
|
||||
|
||||
|
|
|
@ -318,12 +318,26 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
|
|||
surface.SetTextPos( sw - b - ss(w-6), sh - b - ss(BOXHEIGHT-3) )
|
||||
surface.DrawText( wep1c.Name or "???" )
|
||||
|
||||
-- PROTO: Make grenade/melee/firearm logic way way better.
|
||||
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) )
|
||||
|
||||
-- PROTO: Make grenade/melee/firearm logic way way better.
|
||||
if wep1c.Features == "firearm" then
|
||||
surface.SetFont( "Benny_12" )
|
||||
local str = wep:B_FiremodeName( false )
|
||||
local tw = surface.GetTextSize( str )
|
||||
|
@ -880,7 +894,7 @@ do
|
|||
if bucket_selected > #buckets then bucket_selected = 1 item_selected = 1 end
|
||||
if buckets[bucket_selected][item_selected] then
|
||||
Equip()
|
||||
break
|
||||
return
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
@ -902,7 +916,7 @@ do
|
|||
item_selected = #buckets[bucket_selected]
|
||||
if buckets[bucket_selected][item_selected] then
|
||||
Equip()
|
||||
break
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -201,7 +201,7 @@ do -- Toolgun
|
|||
Ammo = 0,
|
||||
Damage = 0,
|
||||
|
||||
Fire = function( self, slot )
|
||||
Fire = function( self, data )
|
||||
if self:GetDelay1() > CurTime() then
|
||||
return true
|
||||
end
|
||||
|
@ -226,7 +226,7 @@ do -- Toolgun
|
|||
return true
|
||||
end,
|
||||
|
||||
Reload = function( self, slot )
|
||||
Reload = function( self, data )
|
||||
if CLIENT and self:GetOwner():KeyPressed( IN_RELOAD ) then
|
||||
CreateSelect()
|
||||
end
|
||||
|
@ -882,24 +882,33 @@ end
|
|||
|
||||
do -- Grenades, nothing here is guaranteed.
|
||||
|
||||
local function GrenadeFire( self, class, table )
|
||||
local function GrenadeFire( self, data )
|
||||
local p = self:GetOwner()
|
||||
if self:GetDelay1() > CurTime() then
|
||||
if self:GetGrenadeDown() then
|
||||
return true
|
||||
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?
|
||||
if SERVER then
|
||||
local p = self:GetOwner()
|
||||
local class = WEAPONS[data.Class]
|
||||
local GENT = ents.Create( class.GrenadeEnt )
|
||||
GENT:SetOwner( p )
|
||||
local ang = p:EyeAngles()
|
||||
ang.p = ang.p - 5
|
||||
GENT:SetPos( p:EyePos() + (ang:Forward()*16) )
|
||||
GENT:SetAngles( ang + Angle( 0, 0, -90 ) )
|
||||
GENT.Fuse = CurTime() + class.GrenadeFuse
|
||||
GENT.Fuse = self:GetGrenadeDownStart() + class.GrenadeFuse
|
||||
GENT:Spawn()
|
||||
|
||||
local velocity = ang:Forward() * 1500
|
||||
|
@ -909,14 +918,25 @@ do -- Grenades, nothing here is guaranteed.
|
|||
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
|
||||
return true
|
||||
end
|
||||
|
||||
local function GrenadeReload( self, class )
|
||||
return true
|
||||
local function GrenadeHolster( self, data )
|
||||
if self:GetGrenadeDown() then
|
||||
self:SetGrenadeDown( false )
|
||||
self:TPFire()
|
||||
if SERVER then GrenadeThrow( self, data ) end
|
||||
end
|
||||
|
||||
local function GrenadeThink( self, class )
|
||||
return true
|
||||
end
|
||||
|
||||
|
@ -928,6 +948,7 @@ do -- Grenades, nothing here is guaranteed.
|
|||
Fire = GrenadeFire,
|
||||
Reload = GrenadeReload,
|
||||
Think = GrenadeThink,
|
||||
Holster = GrenadeHolster,
|
||||
GrenadeEnt = "benny_grenade_frag",
|
||||
GrenadeFuse = 4,
|
||||
GrenadeCharge = true,
|
||||
|
|
Loading…
Reference in New Issue