63 lines
1.8 KiB
Lua
63 lines
1.8 KiB
Lua
if SERVER then return true end
|
|
|
|
include("hi-ui-render.lua")
|
|
-- this sorts the binds players press into specific hooks (for the inventory next and prev
|
|
-- functions aswell as slotN functions)
|
|
-- this is rather easily circumventable by aliasing something to e.g invnext and calling that instead
|
|
-- not much point in trying to catch that, we can't stop users from using unbindall either :) */
|
|
|
|
hook.Add("PlayerBindPress", "keypresssorter", function( player, command, _)
|
|
print(command)
|
|
if string.StartWith(command, "slot") then
|
|
return hook.Run("hi.slotevent", player, tonumber(string.sub(command, 5))) or false
|
|
// ASSUME: only slot0 to slotN are defined
|
|
end
|
|
if command == "invnext" then
|
|
return hook.Run("hi.slotnext", player) or false
|
|
end
|
|
if command == "invprev" then
|
|
return hook.Run("hi.slotprev", player) or false
|
|
end
|
|
return false
|
|
end)
|
|
|
|
local index = 0
|
|
local nexts = true
|
|
local prev = true
|
|
|
|
function bar_pos_x()
|
|
return (ScrW() - (64 * 10)) / 2
|
|
end
|
|
function bar_pos_y()
|
|
return ScrH() -64 -13
|
|
end
|
|
function hi.slotnext(player)
|
|
nexts = not nexts
|
|
if nexts then return true end
|
|
index = index + 1
|
|
if index >= 10 then index = 0 end
|
|
hi.gui.draw_bar(bar_pos_x(), bar_pos_y(), nil, index)
|
|
return true
|
|
end
|
|
|
|
function hi.slotprev(player)
|
|
prev = not prev
|
|
if prev then return true end
|
|
index = index - 1
|
|
if index <= -1 then index = 9 end
|
|
hi.gui.draw_bar(bar_pos_x(), bar_pos_y(), nil, index)
|
|
return true
|
|
end
|
|
|
|
function hi.slotevent(player, index_l)
|
|
index = index_l
|
|
if index >= 10 then index = 0 end
|
|
if index <= -1 then index = 9 end
|
|
hi.gui.draw_bar(bar_pos_x(), bar_pos_y(), nil, index)
|
|
return true
|
|
end
|
|
hook.Add("hi.slotevent", "slotN", hi.slotevent)
|
|
hook.Add("hi.slotnext", "slotnext", hi.slotnext)
|
|
hook.Add("hi.slotprev", "slotprev", hi.slotprev)
|
|
hi.gui.draw_bar(bar_pos_x(), bar_pos_y(), nil, index)
|