2023-12-08 00:30:31 -05:00
|
|
|
|
|
|
|
-- Predicted weapon switching
|
|
|
|
|
|
|
|
local dads = {
|
|
|
|
[KEY_1] = 1,
|
|
|
|
[KEY_2] = 2,
|
|
|
|
[KEY_3] = 3,
|
|
|
|
[KEY_4] = 4,
|
|
|
|
[KEY_5] = 5,
|
|
|
|
[KEY_6] = 6,
|
|
|
|
[KEY_7] = 7,
|
|
|
|
[KEY_8] = 8,
|
|
|
|
[KEY_9] = 9,
|
|
|
|
[KEY_0] = 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
local function beatup( ply, num )
|
|
|
|
local weighted = ply:INV_Weight()
|
|
|
|
local inv = ply:INV_Get()
|
2023-12-08 19:30:22 -05:00
|
|
|
local wep = ply:BennyCheck()
|
2023-12-08 00:30:31 -05:00
|
|
|
local iflip = table.Flip( inv )
|
2023-12-09 00:28:25 -05:00
|
|
|
local hand = ply:KeyDown(IN_ZOOM)
|
2023-12-08 00:30:31 -05:00
|
|
|
|
|
|
|
local invid = 0
|
2023-12-10 03:00:05 -05:00
|
|
|
if CLIENT and !IsFirstTimePredicted() then return end
|
2023-12-08 00:30:31 -05:00
|
|
|
for _, item in pairs( weighted ) do
|
|
|
|
local class = WeaponGet(item.Class)
|
2023-12-08 19:30:22 -05:00
|
|
|
local id = iflip[item]
|
2024-01-04 00:27:54 -05:00
|
|
|
if class.Features == "firearm" or class.Features == "grenade" or class.Features == "melee" then
|
2023-12-08 00:30:31 -05:00
|
|
|
invid = invid + 1
|
2023-12-08 19:55:04 -05:00
|
|
|
if num == 0 then num = 10 end
|
2023-12-08 00:30:31 -05:00
|
|
|
if num == invid then
|
2024-01-01 16:12:35 -05:00
|
|
|
if id == wep:bGetReqInvID( hand ) then
|
2023-12-09 00:28:25 -05:00
|
|
|
-- If we are selected our currently equipped weapon, holster it.
|
2024-01-01 16:12:35 -05:00
|
|
|
return wep:bSetReqInvID( hand, "" )
|
2023-12-08 00:30:31 -05:00
|
|
|
else
|
2024-01-01 16:12:35 -05:00
|
|
|
if wep:bGetReqInvID( hand ) != "" then
|
2023-12-09 22:47:27 -05:00
|
|
|
-- Something is in this hand
|
|
|
|
|
2024-01-01 16:12:35 -05:00
|
|
|
if wep:bGetReqInvID( !hand ) != "" then
|
2023-12-09 22:47:27 -05:00
|
|
|
-- Something in the other hand
|
2024-01-01 16:12:35 -05:00
|
|
|
wep:bSetReqInvID( !hand, wep:bGetReqInvID( hand ) )
|
|
|
|
wep:bSetReqInvID( hand, id )
|
2023-12-09 22:47:27 -05:00
|
|
|
return
|
|
|
|
else
|
|
|
|
-- Nothing in the other hand
|
2024-01-01 16:12:35 -05:00
|
|
|
wep:bSetReqInvID( !hand, "" )
|
|
|
|
wep:bSetReqInvID( hand, id )
|
2023-12-09 22:47:27 -05:00
|
|
|
return
|
|
|
|
end
|
|
|
|
else
|
|
|
|
-- Nothing in this hand.
|
2024-01-01 16:12:35 -05:00
|
|
|
if wep:bGetReqInvID( !hand ) == id then
|
2023-12-09 22:47:27 -05:00
|
|
|
-- Weapon we want is in the other hand.
|
2024-01-01 16:12:35 -05:00
|
|
|
wep:bSetReqInvID( !hand, "" )
|
|
|
|
wep:bSetReqInvID( hand, id )
|
2023-12-09 22:47:27 -05:00
|
|
|
return
|
|
|
|
end
|
2023-12-09 21:50:28 -05:00
|
|
|
end
|
2024-01-01 16:12:35 -05:00
|
|
|
return wep:bSetReqInvID( hand, id )
|
2023-12-08 00:30:31 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2024-01-01 16:12:35 -05:00
|
|
|
return wep:bSetReqInvID( hand, "" )
|
2023-12-08 00:30:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
hook.Add( "PlayerButtonDown", "Benny_PlayerButtonDown_Inv", function( ply, button )
|
|
|
|
local wep = ply:BennyCheck()
|
|
|
|
|
|
|
|
if dads[button] then
|
|
|
|
beatup( ply, dads[button] )
|
|
|
|
end
|
|
|
|
end)
|