diff --git a/gamemodes/benny/entities/entities/benny_grenade/shared.lua b/gamemodes/benny/entities/entities/benny_grenade/shared.lua index 1306a06..1645ccb 100644 --- a/gamemodes/benny/entities/entities/benny_grenade/shared.lua +++ b/gamemodes/benny/entities/entities/benny_grenade/shared.lua @@ -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 diff --git a/gamemodes/benny/entities/weapons/benny/sh_inv.lua b/gamemodes/benny/entities/weapons/benny/sh_inv.lua index 83dd21d..7bb5c3c 100644 --- a/gamemodes/benny/entities/weapons/benny/sh_inv.lua +++ b/gamemodes/benny/entities/weapons/benny/sh_inv.lua @@ -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, "" ) diff --git a/gamemodes/benny/entities/weapons/benny/shared.lua b/gamemodes/benny/entities/weapons/benny/shared.lua index e9e3a5e..24fc127 100644 --- a/gamemodes/benny/entities/weapons/benny/shared.lua +++ b/gamemodes/benny/entities/weapons/benny/shared.lua @@ -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 diff --git a/gamemodes/benny/gamemode/modules/player/cl_hud.lua b/gamemodes/benny/gamemode/modules/player/cl_hud.lua index b525551..9358c89 100644 --- a/gamemodes/benny/gamemode/modules/player/cl_hud.lua +++ b/gamemodes/benny/gamemode/modules/player/cl_hud.lua @@ -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 "???" ) - 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 + 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" ) 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 diff --git a/gamemodes/benny/gamemode/modules/weapons/sh_weapons.lua b/gamemodes/benny/gamemode/modules/weapons/sh_weapons.lua index 645ace0..77820cb 100644 --- a/gamemodes/benny/gamemode/modules/weapons/sh_weapons.lua +++ b/gamemodes/benny/gamemode/modules/weapons/sh_weapons.lua @@ -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,41 +882,61 @@ 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 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:Spawn() + 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 = self:GetGrenadeDownStart() + class.GrenadeFuse + GENT:Spawn() - local velocity = ang:Forward() * 1500 - 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 ) ) + local velocity = ang:Forward() * 1500 + 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 ) ) - 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 - return true end - local function GrenadeReload( self, class ) - return true - end - - local function GrenadeThink( self, class ) + local function GrenadeHolster( self, data ) + if self:GetGrenadeDown() then + self:SetGrenadeDown( false ) + self:TPFire() + if SERVER then GrenadeThrow( self, data ) end + end 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,