Tipo assim:
local screen = Vector2(guiGetScreenSize()) -- Obtém a resolução do jogador.
retangulos = { -- posX, posY, tamanhoX, tamanhoY
{screen.x/2 - 100, screen.y/2 - 100, 200, 20},
{screen.x/2 - 100, screen.y/2 - 60, 200, 20},
{screen.x/2 - 100, screen.y/2 - 20, 200, 20},
{screen.x/2 - 100, screen.y/2 + 20, 200, 20},
{screen.x/2 - 100, screen.y/2 + 60, 200, 20},
{screen.x/2 - 100, screen.y/2 + 100, 200, 20},
}
function isMouseInPosition (x, y, width, height) -- Função útil.
if (not isCursorShowing()) then
return false
end
local sx, sy = guiGetScreenSize()
local cx, cy = getCursorPosition()
local cx, cy = (cx * sx), (cy * sy)
return ((cx >= x and cx <= x + width) and (cy >= y and cy <= y + height))
end
function renderPanel() -- Renderiza o painel.
local cx, cy = getCursorPosition()
for _, infos in pairs(retangulos) do -- Para cada item da tabela retangulos, faça:
local x, y, sizeX, sizeY = unpack(infos) -- Obtém cada valor desse item e separa numa variável.
if isMouseInPosition (x, y, sizeX, sizeY) then -- Se o mouse está em cima deste retângulo, então:
dxDrawRectangle (x, y, sizeX, sizeY, 0xFFFFFFFF, true) -- Retângulo selecionado branco.
else
dxDrawRectangle (x, y, sizeX, sizeY, 0xFF0000FF, true) -- Retângulo normal azul.
end
end
end
addCommandHandler("eae", function(cmd) -- Mostra/oculta o painel.
showCursor(not isCursorShowing())
if isCursorShowing() then
addEventHandler("onClientRender", root, renderPanel)
else
removeEventHandler("onClientRender", root, renderPanel)
end
end)
addEventHandler("onClientClick", root, function(button, state) -- Função que mostra qual botão foi clicado.
if button == "left" and state == "down" then
for i, infos in pairs(retangulos) do
local x, y, sizeX, sizeY = unpack(infos)
if isMouseInPosition (x, y, sizeX, sizeY) then
outputChatBox("Você clicou no botão "..i)
break -- Não precisa verificar os demais botões, pois já achou o que foi clicado.
end
end
end
end)