From 76d6f63350ffbe4058364adc230ab2854427a5ea Mon Sep 17 00:00:00 2001 From: Fesiug Date: Sat, 9 Dec 2023 00:28:25 -0500 Subject: [PATCH] Holstering fixes, don't equip both of same wep! --- .../benny/entities/weapons/benny/sh_inv.lua | 2 +- .../benny/entities/weapons/benny/shared.lua | 11 ++++++++- .../benny/gamemode/modules/player/sh_hud.lua | 24 +++++++------------ 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/gamemodes/benny/entities/weapons/benny/sh_inv.lua b/gamemodes/benny/entities/weapons/benny/sh_inv.lua index f43281a..df3e39c 100644 --- a/gamemodes/benny/entities/weapons/benny/sh_inv.lua +++ b/gamemodes/benny/entities/weapons/benny/sh_inv.lua @@ -153,7 +153,7 @@ function SWEP:BHolster( hand ) end local p = self:GetOwner() - B_Sound( self, "Common.Holster" ) + --B_Sound( self, "Common.Holster" ) local item = self:BTable( hand ) if item then local class = WeaponGet(item.Class) diff --git a/gamemodes/benny/entities/weapons/benny/shared.lua b/gamemodes/benny/entities/weapons/benny/shared.lua index 05c76f4..ab366f2 100644 --- a/gamemodes/benny/entities/weapons/benny/shared.lua +++ b/gamemodes/benny/entities/weapons/benny/shared.lua @@ -198,6 +198,8 @@ end) function SWEP:BStartHolster( hand ) if self:D_GetHolstering( hand ) == -1 then + B_Sound( self, "Common.Holster" ) + -- print( "Holstering the " .. (hand and "LEFT" or "RIGHT") ) self:D_SetHolstering( hand, 1 ) end end @@ -225,14 +227,21 @@ function SWEP:Think() for i=1, 2 do local hand = i==2 local req = self:D_GetReqID( hand ) + local req_o = self:D_GetReqID( !hand ) local curr = self:D_GetID( hand ) + local curr_o = self:D_GetID( !hand ) if req != curr then if curr != "" then -- require holster first self:BStartHolster( hand ) else + local otherhasthis = curr_o == req if req != "" and inv[req] then - self:BDeploy( hand, req ) + if otherhasthis then + self:BStartHolster( !hand ) + else + self:BDeploy( hand, req ) + end else self:BStartHolster( hand ) end diff --git a/gamemodes/benny/gamemode/modules/player/sh_hud.lua b/gamemodes/benny/gamemode/modules/player/sh_hud.lua index 1d0315f..5fc4545 100644 --- a/gamemodes/benny/gamemode/modules/player/sh_hud.lua +++ b/gamemodes/benny/gamemode/modules/player/sh_hud.lua @@ -19,6 +19,7 @@ local function beatup( ply, num ) local inv = ply:INV_Get() local wep = ply:BennyCheck() local iflip = table.Flip( inv ) + local hand = ply:KeyDown(IN_ZOOM) local invid = 0 for _, item in pairs( weighted ) do @@ -28,27 +29,20 @@ local function beatup( ply, num ) invid = invid + 1 if num == 0 then num = 10 end if num == invid then - if ply:KeyDown(IN_ZOOM) then - if id == wep:D_GetID( true ) then - return ply:SetReqID2("") - else - return ply:SetReqID2(id) - end + if id == wep:D_GetID( hand ) then + -- If we are selected our currently equipped weapon, holster it. + return wep:D_SetReqID( hand, "" ) else - if id == wep:D_GetID( false ) then - return ply:SetReqID1("") - else - return ply:SetReqID1(id) + if id == wep:D_GetID( !hand ) then + -- If the wanted weapon is in the other hand, request to holster it. + wep:D_SetReqID( !hand, "" ) end + return wep:D_SetReqID( hand, id ) end end end end - if ply:KeyDown(IN_ZOOM) then - return ply:SetReqID2( "" ) - else - return ply:SetReqID1( "" ) - end + return wep:D_SetReqID( hand, "" ) end hook.Add( "PlayerButtonDown", "Benny_PlayerButtonDown_Inv", function( ply, button )