Desta forma:
Client-side:
local screenW, screenH = guiGetScreenSize()
local painel = false
-- Layout Fixo: (centralizado)
local layout = {
-- posX, posY, sizeX, sizeY, colorRGBA, text, textColorRGBA, fontSize, fontFamily, alignX, alignY
{-320, -180, 640, 360, tocolor(75, 75, 75, 255)}, -- Window
{-320, -190, 426, 20, tocolor(23, 209, 248, 255)}, -- Tittle Line
{-300, -160, 600, 60, tocolor(20, 20, 20, 255), "Arsenal", tocolor(255, 255, 255, 255), 3, "bankgothic", "center", "center"}, -- Tittle
{-300, -80, 186, 100, tocolor(43, 43, 43, 255), "M4", tocolor(255, 255, 255, 255), 2, "pricedown", "center", "center"}, -- Button 1
{-300, 40, 186, 100, tocolor(43, 43, 43, 255), "AK", tocolor(255, 255, 255, 255), 2, "pricedown", "center", "center"}, -- Button 2
{-93, -80, 186, 100, tocolor(43, 43, 43, 255), "GLOCK", tocolor(255, 255, 255, 255), 2, "pricedown", "center", "center"}, -- Button 3
{-93, 40, 186, 100, tocolor(43, 43, 43, 255), "Skin 1", tocolor(255, 255, 255, 255), 2, "pricedown", "center", "center"}, -- Button 4
{114, -80, 186, 100, tocolor(43, 43, 43, 255), "Skin 2", tocolor(255, 255, 255, 255), 2, "pricedown", "center", "center"}, -- Button 5
{114, 40, 186, 100, tocolor(43, 43, 43, 255), "VEICULO", tocolor(255, 255, 255, 255), 2, "pricedown", "center", "center"}, -- Button 6
{-320, 140, 640, 40, false, "Para fechar aperte 'Backspace'", tocolor(255, 255, 255, 255), 2, "default", "center", "center"}, -- Close info
}
function paineldx ()
for i, infos in ipairs (layout) do -- Para cada item da tabela layout, faça:
local posX, posY, sizeX, sizeY, colorRGBA, text, textColorRGBA, fontSize, fontFamily, alignX, alignY = unpack (infos) -- Separa as infos em variáveis.
-- Layout Fixo:
posX = (screenW / 2) + posX -- Faz com que o centro da tela seja a posição 0, 0. Centralizando as posições.
posY = (screenH / 2) + posY -- Converte as posições centralizadas da tabela para posições absolutas.
if colorRGBA then -- Só faz dxDrawRectangle se tiver o parâmetro colorRGBA. Se não tiver, é só um texto isolado.
if i >= 4 and i <= 9 then -- Se for um botão, então: (se for do item 4 até o 9)
if isMouseInPosition (posX, posY, sizeX, sizeY) then -- Se o mouse está em cima do botão, então:
colorRGBA = tocolor(0, 0, 0, 255) -- Torna a cor do botão preto.
end
end
dxDrawRectangle(posX, posY, sizeX, sizeY, colorRGBA, false)
end
if text then -- Só faz dxDrawText se tiver o parâmetro texto.
sizeX = posX + sizeX
sizeY = posY + sizeY
dxDrawText(text, posX, posY, sizeX, sizeY, textColorRGBA, fontSize, fontFamily, alignX, alignY)
end
end
end
addEvent("HitM", true)
addEventHandler("HitM", root, function() -- Função chamada pelo servidor quando este jogador colide no marker do server.
if not painel then
addEventHandler("onClientRender", root, paineldx)
painel = true
showCursor(true)
end
end)
bindKey("backSpace", "down", function() -- Tecla que fecha o painel.
if painel then
removeEventHandler("onClientRender", root, paineldx)
painel = false
showCursor(false)
end
end)
addEventHandler("onClientClick", root, function(button, state)
if button == "left" and state == "down" then
if painel then
for i, infos in pairs (layout) do -- Neste caso uso pairs pois a ordem dos itens não importa.
local posX, posY, sizeX, sizeY = unpack (infos) -- Separa as infos em variáveis.
-- Layout Fixo:
posX = (screenW / 2) + posX -- Converte a posição centralizada da tabela para posição absoluta.
posY = (screenH / 2) + posY
if isMouseInPosition(posX, posY, sizeX, sizeY) then
if i == 4 then -- Se for o botão de M4, então:
triggerServerEvent("setarAlgo", localPlayer, "weapon", 31, 9999)
-- giveWeapon (source, 31, 9999) -- Não funciona client-side.
elseif i == 5 then -- Se for o botão de AK, então:
triggerServerEvent("setarAlgo", localPlayer, "weapon", 30, 9999)
elseif i == 6 then -- Se for o botão de Glock, então:
triggerServerEvent("setarAlgo", localPlayer, "weapon", 24, 9999)
elseif i == 7 then -- Se for o botão de Skin 1, então:
triggerServerEvent("setarAlgo", localPlayer, "skin", 28)
elseif i == 8 then -- Se for o botão de Skin 2, então:
triggerServerEvent("setarAlgo", localPlayer, "skin", 29)
elseif i == 9 then -- Se for o botão de Vehicle, então:
triggerServerEvent("setarAlgo", localPlayer, "vehicle", 560)
end
end
end
end
end
end)
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
Server-side:
local m1 = createMarker(2027.903, 1545.603, 10.819 -1, "cylinder", 1.5, 0,195,255, 100)
local vehicles = {}
addEventHandler("onMarkerHit", m1, function(hit)
if getElementType(hit) == "player" then -- Se quem colidiu no marker for um jogador, então:
if isObjectInACLGroup ("user."..getAccountName (getPlayerAccount (hit)), aclGetGroup ("Admin")) then -- Se o jogador está na ACL Admin, então:
setTimer(triggerClientEvent, 250, 1, hit, "HitM", hit)
else
outputChatBox("Acesso negado.", hit, 255, 0, 0)
end
end
end)
addEvent("setarAlgo", true)
addEventHandler("setarAlgo", root, function (tipo, id, ammo) -- Função chamada pelo client. Seta algo no jogador.
if tipo == "weapon" then
giveWeapon(client, id, ammo, true)
elseif tipo == "skin" then
setElementModel (client, id)
elseif tipo == "vehicle" then
local x, y, z = getElementPosition(client)
if isElement (vehicles[client]) then -- Se já existe um veículo criado por este jogador, então:
destroyElement(vehicles[client]) -- Destrói esse veículo antes de criar outro.
end
vehicles[client] = createVehicle(id, x, y, z + 1) -- Cria o veículo em cima do jogador.
end
end)
function limpaVehicle() -- Destrói o veículo criado pelo jogador quando ele sair do servidor.
if isElement (vehicles[source]) then
destroyElement(vehicles[source])
vehicles[source] = nil
end
end
addEventHandler("onPlayerQuit", root, limpaVehicle)
addEventHandler("onPlayerDisconnect", root, limpaVehicle)