Jump to content

AJUDA PAINEL DX GIVEWEPON!!!


Recommended Posts

então to criando um painel dx de arsenal corp e fac e queria pedir ajuda para givar uma arma e um carro obs: se alguem me manda o script arrumado agradeço

 

Client:

 

 

 
local screenW, screenH = guiGetScreenSize()
painel = false
    function paineldx ()
        dxDrawRectangle(screenW * 0.2484, screenH * 0.3154, screenW * 0.5547, screenH * 0.4707, tocolor(75, 75, 75, 255), false)
        dxDrawRectangle(319, 323, 709, 21, tocolor(23, 209, 248, 255), false)
        dxDrawRectangle(screenW * 0.2953, screenH * 0.3379, screenW * 0.4578, screenH * 0.0508, tocolor(20, 20, 20, 255), false)
        dxDrawRectangle(screenW * 0.2734, screenH * 0.4209, screenW * 0.1266, screenH * 0.1221, tocolor(43, 43, 43, 255), false)
        dxDrawRectangle(screenW * 0.2734, screenH * 0.5752, screenW * 0.1266, screenH * 0.1221, tocolor(43, 43, 43, 255), false)
        dxDrawRectangle(screenW * 0.4250, screenH * 0.4209, screenW * 0.1266, screenH * 0.1221, tocolor(43, 43, 43, 255), false)
        dxDrawRectangle(screenW * 0.4250, screenH * 0.5752, screenW * 0.1266, screenH * 0.1221, tocolor(43, 43, 43, 255), false)
        dxDrawRectangle(screenW * 0.5938, screenH * 0.4209, screenW * 0.1266, screenH * 0.1221, tocolor(43, 43, 43, 255), false)
        dxDrawRectangle(screenW * 0.5938, screenH * 0.5752, screenW * 0.1266, screenH * 0.1221, tocolor(43, 43, 43, 255), false)
        dxDrawText("Arsenal ", screenW * 0.3664, screenH * 0.3154, screenW * 0.7727, screenH * 0.3516, tocolor(255, 255, 255, 255), 3.00, "bankgothic", "left", "top", false, false, false, false, false)
        dxDrawText("M4", screenW * 0.2953, screenH * 0.4346, screenW * 0.3875, screenH * 0.5244, tocolor(255, 255, 255, 255), 3.00, "pricedown", "left", "top", false, false, false, false, false)
        dxDrawText("AK", screenW * 0.4516, screenH * 0.4307, screenW * 0.5437, screenH * 0.5205, tocolor(255, 255, 255, 255), 3.00, "pricedown", "left", "top", false, false, false, false, false)
        dxDrawText("GLOCK", screenW * 0.6141, screenH * 0.4434, screenW * 0.7063, screenH * 0.5332, tocolor(255, 255, 255, 255), 2.00, "pricedown", "left", "top", false, false, false, false, false)
        dxDrawText("Skin 1", screenW * 0.2914, screenH * 0.6074, screenW * 0.3836, screenH * 0.6973, tocolor(255, 255, 255, 255), 2.00, "pricedown", "left", "top", false, false, false, false, false)
        dxDrawText("Skin 2", screenW * 0.4414, screenH * 0.6074, screenW * 0.5336, screenH * 0.6973, tocolor(255, 255, 255, 255), 2.00, "pricedown", "left", "top", false, false, false, false, false)
        dxDrawText("Veiculo", screenW * 0.5938, screenH * 0.6074, screenW * 0.6859, screenH * 0.6973, tocolor(255, 255, 255, 255), 2.00, "pricedown", "left", "top", false, false, false, false, false)
        dxDrawText("Para fechar aperta BackSpace", 328, 818, 1054, 928, tocolor(255, 255, 255, 255), 3.00, "default", "left", "top", false, false, false, false, false)
    end
     

    addEvent("HitM", true)
    addEventHandler("HitM", root, function()
          if painel then
            removeEventHandler("onClientRender", getRootElement(), paineldx)
              painel = false
              showCursor( false )
          else
            addEventHandler("onClientRender", getRootElement(), paineldx)
               painel = true
               showCursor( true )
          end
    end)

      bindKey("backSpace", "down", function()
         removeEventHandler("onClientRender", getRootElement(), paineldx)
         painel = false
         showCursor( false )
      end)

      addEventHandler("onClientClick", getRootElement(), function(button, state)
        if button=="left" and state=="down" then
            if painel == true then
                if isMouseInPosition(screenW * 0.4516, screenH * 0.4307, screenW * 0.5437, screenH * 0.5205) then
                  giveWeapon ( source, 31, 9999 )

                end
                end
                end
                end)

 

 

Server:

 

 

m1 = createMarker(2027.903, 1545.603, 10.819 -1, "cylinder", 1.5, 0,195,255, 100)

 addEventHandler("onMarkerHit", m1, function(hit)
    if getElementType(hit) == "player" then
        triggerClientEvent(hit, "HitM", hit)
    end
 end)
 
 
Link to comment
  • Scripting Moderators

Hi, welcome to the forums! 👋

Your topic has been moved to the Portuguese scripting section.
Please make sure to always use English when posting outside this language-specific section.

Link to comment
  • Other Languages Moderators
Posted (edited)

@JPzin comece fazendo o seguinte:

  1. Corrija a indentação dos seus códigos para que eles fiquem legíveis.
    Para aprender a indentar código, veja este tópico.
  2. Troque todos os getRootElement() por root.

Depois de fazer o básico, aí sim você pode começar a corrigir o painel.

  1. De cara, a função giveWeapon é server-side. Portanto não vai funcionar no seu script client-side.
  2. Vi que seu painel foi feito usando escala relativa para tentar manter o painel no mesmo tamanho em qualquer resolução, porém isso dará problema com os textos pois eles não acompanham a escala da tela e precisam que você declare tamanhos diferentes na fonte.
    1. Ou você faz um painel de tamanho fixo (no máximo 640x480), evitando problemas com os textos e evitando trabalho.
    2. Ou você calcula a resolução do jogador e aplica no tamanho da fonte junto, o que dará mais trabalho.
    3. Ao usar escala relativa, você também precisa se preocupar com a proporção da tela, algumas resoluções são mais quadradas (4:3), outras são mais retangulares (16:9), causando distorções no painel e deixando ele mais esticado ou comprimido na horizontal. Nestes casos, você precisa definir tamanhos de fonte diferente na horizontal também, saiba mais em dxDrawText.
  3. Evite repetição de código. Crie uma tabela com todas as posições e tamanhos de cada botão junto com os textos. Então dentro da função do onClientRender você apenas faz um "loop ipairs" entre os itens dessa tabela, gerando os botões com as propriedades da tabela.
  4. Na função do onClientClick, você usa a mesma tabela para verificar qual botão foi clicado, criando uma condição para cada índice da tabela. Ex: Se clicou no item 1 da tabela, faz tal coisa. Senão, se clicou no item 2 da tabela, faz outra coisa e assim por diante.
  5. Para facilitar na hora de fazer manutenção no painel, deixe cada dxDraw com comentários no final da linha dizendo o que é cada item. Por exemplo, no final da linha do primeiro dxDrawRectangle, adicione o comentário: -- Janela

Só então, depois do painel pronto, você deve criar feedback visual ao passar o mouse pelas áreas clicáveis. Já que o objetivo de um painel DX é ser mais bonito do que funcional. Se fosse pra ser mais funcional do que bonito, você deveria usar CEGUI em vez de DXGUI.

  1. Ao passar o mouse em cima de um botão, mude a cor dele para o jogador saber que é uma área clicável. Ou então mude a cor do texto do botão.

 

 

Edited by Lord Henry
Link to comment
Posted (edited)

então mn fiz o de cegui só que eu n sei como posso fazer para givar uma arma  e um carro tem 5 botão eu sei fazer sistema de 3 botão só que fazer o de spawnar um carr em um local e givar arm eu n sei, vc poderiar me mostrar como deve colocar no client e server 

 

 

oq eu fiz 

 

client:

janela = guiCreateWindow(794, 342, 292, 429, "Arsenal", false)
        guiWindowSetSizable(janela, false)
        guiSetVisible(janela, false)
       

button1 = guiCreateButton(0.04, 0.09, 0.38, 0.23, "M4", true, janela)
           guiSetVisible(button1, false)
button2 = guiCreateButton(0.55, 0.09, 0.38, 0.23, "Glock", true, janela)
           guiSetVisible(button2, false)
button3 = guiCreateButton(0.04, 0.39, 0.38, 0.23, "Veiculo", true, janela)
            guiSetVisible(button3, false)
button4 = guiCreateButton(0.55, 0.39, 0.38, 0.23, "Skin 1", true, janela)
            guiSetVisible(button4, false)
button5 = guiCreateButton(0.04, 0.67, 0.38, 0.23, "Skin 2", true, janela)
            guiSetVisible(button5, false)  




--Painel ^

local visible = false
addCommandHandler("painel", function()
    if visible == false then
   guiSetVisible(janela, true)
   guiSetVisible(button1, true)
   guiSetVisible(button2, true)
   guiSetVisible(button3, true)
   guiSetVisible(button4, true)
   guiSetVisible(button5, true)
   visible = true
   showCursor(true)
    else
        guiSetVisible(janela, false)
        guiSetVisible(button1, false)
        guiSetVisible(button2, false)
        guiSetVisible(button3, false)
        guiSetVisible(button4, false)
        guiSetVisible(button5, false)
        visible = false
        showCursor(false)

    end



end)

addEventHandler("onClientGUIClick", button1, function(tecla)
   if tecla == "left" then
      triggerServerEvent("Arma1", localplayer)
   end
end)

 

 
 

 

 

server:

addEvent("Arma1", true)
addEventHandler("Arma1", root, function()  
   giveWepon(source, 31, 200)

end)

 

 

 

 

 

 

Edited by JPzin
Link to comment
  • Other Languages Moderators
Posted (edited)

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)

 

Edited by Lord Henry
Adicionado condição de ACL no server-side.
  • Thanks 1
Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...