From 43de9503eb04fbf6b8b5b1a4268a754b626d6b49 Mon Sep 17 00:00:00 2001 From: Fesiug Date: Fri, 8 Dec 2023 01:04:36 -0500 Subject: [PATCH] Holstering --- .../benny/entities/weapons/benny/sh_inv.lua | 20 ++++++++ .../benny/entities/weapons/benny/shared.lua | 49 +++++++++++-------- .../benny/gamemode/modules/player/cl_hud.lua | 9 +++- .../benny/gamemode/modules/player/sh_hud.lua | 5 +- 4 files changed, 59 insertions(+), 24 deletions(-) diff --git a/gamemodes/benny/entities/weapons/benny/sh_inv.lua b/gamemodes/benny/entities/weapons/benny/sh_inv.lua index 8925232..8df62bc 100644 --- a/gamemodes/benny/entities/weapons/benny/sh_inv.lua +++ b/gamemodes/benny/entities/weapons/benny/sh_inv.lua @@ -53,6 +53,26 @@ function SWEP:D_SetShotTime( hand, value ) return (hand == true) and self:SetWep2_ShotTime( value ) or (hand == false) and self:SetWep1_ShotTime( value ) end +-- Weapon Holstering Time +function SWEP:D_GetHolstering( hand ) + return (hand == true) and self:GetWep2_Holstering() or (hand == false) and self:GetWep1_Holstering() +end + +function SWEP:D_SetHolstering( hand, value ) + return (hand == true) and self:SetWep2_Holstering( value ) or (hand == false) and self:SetWep1_Holstering( value ) +end + +-- Weapon Player Requesting ID +function SWEP:D_GetReqID( hand ) + local p = self:GetOwner() + return (hand == true) and p:GetReqID2() or (hand == false) and p:GetReqID1() +end + +function SWEP:D_SetReqID( hand, value ) + local p = self:GetOwner() + return (hand == true) and p:SetReqID2( value ) or (hand == false) and p:SetReqID1( value ) +end + -- Internal SWEP Delay function SWEP:D_GetDelay( hand ) return (hand == true) and self:GetDelay2() or (hand == false) and self:GetDelay1() diff --git a/gamemodes/benny/entities/weapons/benny/shared.lua b/gamemodes/benny/entities/weapons/benny/shared.lua index 7a4a208..42757e1 100644 --- a/gamemodes/benny/entities/weapons/benny/shared.lua +++ b/gamemodes/benny/entities/weapons/benny/shared.lua @@ -42,6 +42,8 @@ function SWEP:SetupDataTables() self:NetworkVar( "Float", 5, "Wep2_Spread" ) self:NetworkVar( "Float", 6, "Wep1_ShotTime" ) self:NetworkVar( "Float", 7, "Wep2_ShotTime" ) + self:NetworkVar( "Float", 8, "Wep1_Holstering" ) + self:NetworkVar( "Float", 9, "Wep2_Holstering" ) self:NetworkVar( "String", 0, "Wep1" ) self:NetworkVar( "String", 1, "Wep2" ) self:NetworkVar( "String", 2, "Wep1_Clip" ) @@ -194,6 +196,23 @@ hook.Add( "PlayerButtonUp", "Benny_PlayerButtonUp_TempForAim", function( ply, bu end end) +function SWEP:BStartHolster( hand ) + if self:D_GetHolstering( hand ) == -1 then + self:D_SetHolstering( hand, 1 ) + end +end + +function SWEP:BThinkHolster( hand ) + if self:D_GetHolstering( hand ) > 0 then + self:D_SetHolstering( hand, math.Approach( self:D_GetHolstering( hand ), 0, FrameTime() / 0.2 ) ) + end + if self:D_GetHolstering( hand ) == 0 then + self:D_SetHolstering( hand, -1 ) + self:BHolster( hand ) + self:D_SetReqID( hand, "" ) + end +end + function SWEP:Think() local p = self:GetOwner() local inv = p:INV_Get() @@ -201,30 +220,18 @@ function SWEP:Think() local L, R = true, false local curr_l, curr_r = self:D_GetID( true ), self:D_GetID( false ) - if p:GetReqID1() != self:D_GetID( R ) then - if inv[p:GetReqID1()] and p:GetReqID1() != "" then - if curr_r != "" then - -- We already have something equipped here, move it to the offhand - self:BDeploy( L, curr_r ) - p:SetReqID2( curr_r ) + for i=1, 1 do + local hand = i==2 + if self:D_GetReqID( hand ) != self:D_GetID( hand ) then + if inv[self:D_GetReqID( hand )] and self:D_GetReqID( hand ) != "" then + self:BDeploy( hand, p:GetReqID1() ) + else + self:BStartHolster( hand ) end - self:BDeploy( R, p:GetReqID1() ) - else - self:BHolster( R ) end - end - if p:GetReqID2() != self:D_GetID( L ) then - if inv[p:GetReqID2()] and p:GetReqID2() != "" then - if curr_l != "" then - -- We already have something equipped here, move it to the offhand - self:BDeploy( R, curr_l ) - p:SetReqID1( curr_l ) - end - self:BDeploy( L, p:GetReqID2() ) - else - self:BHolster( L ) - end + self:BThinkHolster( R ) + -- print( self:D_GetReqID( hand ), self:D_GetID( hand ) ) end local wep1 = self:BTable( false ) diff --git a/gamemodes/benny/gamemode/modules/player/cl_hud.lua b/gamemodes/benny/gamemode/modules/player/cl_hud.lua index 95751f9..3cc741e 100644 --- a/gamemodes/benny/gamemode/modules/player/cl_hud.lua +++ b/gamemodes/benny/gamemode/modules/player/cl_hud.lua @@ -929,7 +929,7 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function() end end - if false and p:BennyCheck() then + if false and wep then local bx, by = sw/2, sh*(0.75) local mx = 50 @@ -955,6 +955,13 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function() end end end + + if wep then + surface.SetDrawColor( color_white ) + surface.DrawRect( sw/2 - ss(400)/2, sh/2 - ss(8)/2, ss(400*wep:GetWep1_Holstering()), ss(8) ) + + surface.DrawOutlinedRect( sw/2 - ss(400+2)/2, sh/2 - ss(8+2)/2, ss(400+2), ss(8+2), ss(0.5) ) + end end ) do diff --git a/gamemodes/benny/gamemode/modules/player/sh_hud.lua b/gamemodes/benny/gamemode/modules/player/sh_hud.lua index 1bbfa78..c2984a9 100644 --- a/gamemodes/benny/gamemode/modules/player/sh_hud.lua +++ b/gamemodes/benny/gamemode/modules/player/sh_hud.lua @@ -27,13 +27,14 @@ local function beatup( ply, num ) if num == invid then --RunConsoleCommand( "benny_inv_equip", iflip[item], "false", "false" ) if ply:KeyDown(IN_ZOOM) then - ply:SetReqID2(iflip[item]) + return ply:SetReqID2(iflip[item]) else - ply:SetReqID1(iflip[item]) + return ply:SetReqID1(iflip[item]) end end end end + return ply:SetReqID1( "" ) end hook.Add( "PlayerButtonDown", "Benny_PlayerButtonDown_Inv", function( ply, button )