Benny/gamemodes/benny/gamemode/modules/player/sh_hud.lua

57 lines
1.4 KiB
Lua
Raw Normal View History

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 )
local hand = ply:KeyDown(IN_ZOOM)
2023-12-08 00:30:31 -05:00
local invid = 0
for _, item in pairs( weighted ) do
local class = WeaponGet(item.Class)
2023-12-08 19:30:22 -05:00
local id = iflip[item]
2023-12-08 00:30:31 -05:00
if class.Features == "firearm" or class.Features == "grenade" then
invid = invid + 1
if num == 0 then num = 10 end
2023-12-08 00:30:31 -05:00
if num == invid then
2023-12-09 22:27:28 -05:00
if id == wep:D_GetReqID( hand ) then
-- If we are selected our currently equipped weapon, holster it.
return wep:D_SetReqID( hand, "" )
2023-12-08 00:30:31 -05:00
else
if id == wep:D_GetID( !hand ) then
-- If the wanted weapon is in the other hand, request to holster it.
wep:D_SetReqID( !hand, "" )
2023-12-08 19:30:22 -05:00
end
2023-12-09 21:55:36 -05:00
if wep:D_GetID( !hand ) != "" and wep:D_GetID( hand ) != "" then -- If we have something in this hand, swap it with the other
2023-12-09 21:50:28 -05:00
wep:D_SetReqID( !hand, wep:D_GetID( hand ) )
end
return wep:D_SetReqID( hand, id )
2023-12-08 00:30:31 -05:00
end
end
end
end
return wep:D_SetReqID( 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)