Jump to content

Recommended Posts

ola estou criando um painel mas estou tendo problema q quando o player clica no botão a açao desejada n executa

client

local dp = createMarker ( 1579.9151611328,-1635.1785888672,13.561134338379, "cylinder", 1.5, 0, 85, 0, 255 )
Painel_DP = false


function DXPM()
    dxDrawRectangle(83, 136, 814, 449, tocolor(0, 0, 0, 184), false)
    dxDrawRectangle(83, 136, 814, 28, tocolor(10, 72, 175, 254), false)
    dxDrawText("PMESP", 468, 138, 509, 164, tocolor(255, 255, 255, 255), 1.00, "bankgothic", "center", "center", false, false, false, false, false)
    dxDrawRectangle(115, 197, 195, 343, tocolor(0, 0, 0, 176), false)
    dxDrawText("Fardas", 130, 174, 300, 197, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false)
-------------------------------------------------------------------------------------
    dxDrawRectangle(115, 217, 195, 18, tocolor(129, 129, 129, 162), false)
    dxDrawText("Farda 1", 130, 212, 300, 235, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "bottom", false, false, false, false, false)
    --------------------------------------------------------------------------------
    dxDrawRectangle(115, 245, 195, 18, tocolor(129, 129, 129, 162), false)
    dxDrawText("Farda 2", 130, 240, 300, 263, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "bottom", false, false, false, false, false)
    ------------------------------------------------------
    dxDrawRectangle(115, 273, 195, 18, tocolor(129, 129, 129, 162), false)
    dxDrawText("Farda 3", 130, 268, 300, 291, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "bottom", false, false, false, false, false)
    -----------------------------------------------------------------------------
    dxDrawRectangle(115, 301, 195, 18, tocolor(129, 129, 129, 162), false)
    dxDrawText("Farda 4", 130, 296, 300, 319, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "bottom", false, false, false, false, false)
    ----------------------------------------------------------------------------
    dxDrawRectangle(335, 197, 195, 343, tocolor(0, 0, 0, 176), false)
    dxDrawText("Viaturas", 345, 174, 515, 197, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false)
    ------------------------------------------------------------------------------
    dxDrawRectangle(335, 217, 195, 18, tocolor(129, 129, 129, 162), false)
    dxDrawText("VTR 1", 345, 212, 515, 235, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "bottom", false, false, false, false, false)
    ------------------------------------------------------------------------------------
    dxDrawRectangle(335, 245, 195, 18, tocolor(129, 129, 129, 162), false)
    dxDrawText("VTR 2", 345, 240, 515, 263, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "bottom", false, false, false, false, false)
    -----------------------------------------------------------------------------------
    dxDrawRectangle(335, 273, 195, 18, tocolor(129, 129, 129, 162), false)
    dxDrawText("VTR 3", 345, 268, 515, 291, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "bottom", false, false, false, false, false)
    ---------------------------------------------------------------------------------
    dxDrawRectangle(335, 301, 195, 18, tocolor(129, 129, 129, 162), false)
    dxDrawImage(571, 181, 280, 36, ":PMESP/botao.png", 0, 0, 0, tocolor(10, 72, 175, 254), false)
    dxDrawText("Pegar Armamento", 636, 192, 782, 213, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "top", false, false, false, false, false)
    dxDrawImage(571, 504, 280, 36, ":PMESP/botao.png", 0, 0, 0, tocolor(10, 72, 175, 254), false)
    dxDrawText("Concluido", 640, 514, 786, 535, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "top", false, false, false, false, false)
    dxDrawImage(574, 239, 277, 249, ":[SAMU]Departamento/Img/Logo.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
    dxDrawImage(650, 309, 113, 106, ":[SAMU]Departamento/Img/dp.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
end

function render()
    if Painel_DP == false then
        Painel_DP = true
        addEventHandler("onClientRender", root, DXPM)
        showCursor(true)
    end
end
addEventHandler ( "onClientMarkerHit", dp, render )

function botoes()
if Painel_DP == true then 
    f1 = guiCreateButton( 115, 217, 195, 18, "", true )
    setElementAlpha (f1, 0)
    f2 = guiCreateButton( 115, 245, 195, 18, "", true )
    setElementAlpha (f2, 0)
    f3 = guiCreateButton( 115, 273, 195, 18, "", true )
    setElementAlpha (f3, 0)
    f4 = guiCreateButton( 115, 301, 195, 18, "", true )
    setElementAlpha (f4, 0)
    v1 = guiCreateButton( 115, 301, 195, 18, "", true )
    setElementAlpha (v1, 0)
    v2 = guiCreateButton( 115, 301, 195, 18, "", true )
    setElementAlpha (v2, 0)
    v3 = guiCreateButton( 115, 301, 195, 18, "", true )
    setElementAlpha (v3, 0)
    addEventHandler ( "onClientGUIClick", f1, skin1, true )
    addEventHandler ( "onClientGUIClick", f2, skin2, true )
    addEventHandler ( "onClientGUIClick", f3, skin3, true )
    addEventHandler ( "onClientGUIClick", f4, skin4, true )
    addEventHandler ( "onClientGUIClick", v1, vtr1, true )
    addEventHandler ( "onClientGUIClick", v2, vtr2, true )
    addEventHandler ( "onClientGUIClick", v3, vtr3, true )
end
end

function skin1()
    triggerServerEvent("Farda1PM",getLocalPlayer())
end

function skin2()
    triggerServerEvent("Farda2PM",getLocalPlayer())
end

function skin3()
    triggerServerEvent("Farda3PM",getLocalPlayer())
end

function skin4()
    triggerServerEvent("Farda4PM",getLocalPlayer())
end
--------------------VTR--------------------

function vtr1()
    createVehicle ( 432, 1603.0577392578,-1684.6134033203,5.890625 )
end

function vtr2()
    createVehicle ( 432, 1601.2092285156,-1692.5222167969,5.890625 )
end

function vtr3()
    createVehicle ( 432, 1601.6129150391,-1699.3563232422,5.890625 )
end

server

function Farda1 ()
	setElementModel ( source, 272 )
end
addEvent("Farda1PM", true)
addEventHandler("Farda1PM",root, Farda1)

function Farda2 ()
	setElementModel ( source, 273 )
end
addEvent("Farda2PM", true)
addEventHandler("Farda2PM",root, Farda2)

function Farda3 ()
	setElementModel ( source, 0 )
end
addEvent("Farda3PM", true)
addEventHandler("Farda3PM",root, Farda3)

function Farda4 ()
	setElementModel ( source, 0 )
end
addEvent("Farda4PM", true)
addEventHandler("Farda4PM",root, Farda4)

function Farda5 ()
	setElementModel ( source, 0 )
end
addEvent("Farda5PM", true)
addEventHandler("Farda5PM",root, Farda5)

function Farda6 ()
	setElementModel ( source, 23 )
end
addEvent("Farda6PM", true)
addEventHandler("Farda6PM",root, Farda6)

----------------------------------------------------------------------------------------------------------

 

Link to comment
  • Other Languages Moderators

Vc criou um painel em DX, depois tentou criar botões em CEGUI e tentou deixá-los invisíveis com setElementAlpha quando na verdade deveria ter usado guiSetAlpha para isso.

Faça o painel inteiro em CEGUI se vc não tem conhecimento suficiente pra fazer em DX.

A função que cria os botões não foi chamada em nenhum momento.

Edited by Lord Henry
  • Thanks 1
Link to comment

''O bonito as vezes sai caro'', faça em GUI, se tiver dificuldades poste o código que te ajudo.

1. Faça o ambiente de trabalho. (Janelas, botões, labels, editboxs se tiver, enfim) e poste aqui se não souber continuar...

Edited by Jonas^
Link to comment
addEventHandler ("onClientGUIClick", root, function (btn)
	if btn ~= "left" then return end -- Se o botão clicado do mouse não for o esquerdo, cancela a função e nada acontece.
	if source == buttonSkin then -- Se o botão clicado for o botão buttonSkin, então:
		setElementModel (localPlayer, id)
	end
end) 

 

Link to comment
dp = createMarker ( 1579.9151611328,-1635.1785888672,13.561134338379, "cylinder", 1.5, 0, 85, 0, 255 )

GUIEditor = {
    button = {},
    window = {}
}

    function PM()
        GUIEditor.window[1] = guiCreateWindow(79, 76, 398, 380, "Equipamentos", false)
        guiWindowSetSizable(GUIEditor.window[1], false)

        f1 = guiCreateButton(36, 54, 145, 29, "Farda 1", false, GUIEditor.window[1])
        f2 = guiCreateButton(36, 93, 145, 29, "Farda 2", false, GUIEditor.window[1])
        f3 = guiCreateButton(36, 132, 145, 29, "Farda 3", false, GUIEditor.window[1])
        f4 = guiCreateButton(36, 171, 145, 29, "Farda 4", false, GUIEditor.window[1])
        vtr1 = guiCreateButton(230, 54, 145, 29, "viatura 1", false, GUIEditor.window[1])
        vtr2 = guiCreateButton(230, 93, 145, 29, "viatura 2", false, GUIEditor.window[1])
        vtr3 = guiCreateButton(230, 132, 145, 29, "viatura 3", false, GUIEditor.window[1])
        aguia = guiCreateButton(230, 171, 145, 29, "Aguia", false, GUIEditor.window[1])
        Equipamento = guiCreateButton(130, 307, 284, 49, "Pegar Equipamento", false, GUIEditor.window[1])
        colete = guiCreateButton(131, 375, 283, 46, "Pegar colete", false, GUIEditor.window[1])
    end

function render()
    addEventHandler("onClientRender", root, PM)
    showCursor(true)
end
addEventHandler ( "onClientMarkerHit", dp, render )

addEventHandler ("onClientGUIClick", root, function (btn)
    if btn ~= "left" then return end -- Se o botão clicado do mouse não for o esquerdo, cancela a função e nada acontece.
    if source == f1 then -- Se o botão clicado for o botão buttonSkin, então:
        setElementModel (localPlayer, 2)
    end
end)

addEventHandler ("onClientGUIClick", root, function (btn)
    if btn ~= "left" then return end -- Se o botão clicado do mouse não for o esquerdo, cancela a função e nada acontece.
    if source == f2 then -- Se o botão clicado for o botão buttonSkin, então:
        setElementModel (localPlayer, 4)
    end
end)

addEventHandler ("onClientGUIClick", root, function (btn)
    if btn ~= "left" then return end -- Se o botão clicado do mouse não for o esquerdo, cancela a função e nada acontece.
    if source == f3 then -- Se o botão clicado for o botão buttonSkin, então:
        setElementModel (localPlayer, 1)
    end
end)

addEventHandler ("onClientGUIClick", root, function (btn)
    if btn ~= "left" then return end -- Se o botão clicado do mouse não for o esquerdo, cancela a função e nada acontece.
    if source == f4 then -- Se o botão clicado for o botão buttonSkin, então:
        setElementModel (localPlayer, 4)
    end
end)

addEventHandler ("onClientGUIClick", root, function (btn)
    if btn ~= "left" then return end -- Se o botão clicado do mouse não for o esquerdo, cancela a função e nada acontece.
    if source == vtr1 then -- Se o botão clicado for o botão buttonSkin, então:
        createVehicle ( 432, 1603.0577392578,-1684.6134033203,5.890625 )
    end
end)

addEventHandler ("onClientGUIClick", root, function (btn)
    if btn ~= "left" then return end -- Se o botão clicado do mouse não for o esquerdo, cancela a função e nada acontece.
    if source == vtr2 then -- Se o botão clicado for o botão buttonSkin, então:
        createVehicle ( 432, 1601.2092285156,-1692.5222167969,5.890625 )
    end
end)

addEventHandler ("onClientGUIClick", root, function (btn)
    if btn ~= "left" then return end -- Se o botão clicado do mouse não for o esquerdo, cancela a função e nada acontece.
    if source == vtr3 then -- Se o botão clicado for o botão buttonSkin, então:
        createVehicle ( 432, 1601.6129150391,-1699.3563232422,5.890625 )
    end
end)

addEventHandler ("onClientGUIClick", root, function (btn)
    if btn ~= "left" then return end -- Se o botão clicado do mouse não for o esquerdo, cancela a função e nada acontece.
    if source == aguia then -- Se o botão clicado for o botão buttonSkin, então:
        createVehicle ( 432, 1601.6129150391,-1699.3563232422,5.890625 )
    end
end)

 

Link to comment

Adicione um botão para fechar o painel, ou use o evento onClientMarkerLeave.

local dp = createMarker (1579.9151611328, -1635.1785888672, 13.561134338379, "cylinder", 1.5, 0, 85, 0, 255)

addEventHandler ("onClientResourceStart", resourceRoot, function ()
	windowPolice = guiCreateWindow (79, 76, 398, 380, "Equipamentos", false)
	guiWindowSetSizable (windowPolice, false)
	f1 = guiCreateButton (36, 54, 145, 29, "Farda 1", false, windowPolice)
	f2 = guiCreateButton (36, 93, 145, 29, "Farda 2", false, windowPolice)
	f3 = guiCreateButton (36, 132, 145, 29, "Farda 3", false, windowPolice)
	f4 = guiCreateButton (36, 171, 145, 29, "Farda 4", false, windowPolice)
	vtr1 = guiCreateButton (230, 54, 145, 29, "viatura 1", false, windowPolice)
	vtr2 = guiCreateButton (230, 93, 145, 29, "viatura 2", false, windowPolice)
	vtr3 = guiCreateButton (230, 132, 145, 29, "viatura 3", false, windowPolice)
	aguia = guiCreateButton (230, 171, 145, 29, "Aguia", false, windowPolice)
	Equipamento = guiCreateButton (130, 307, 284, 49, "Pegar Equipamento", false, windowPolice)
	colete = guiCreateButton (131, 375, 283, 46, "Pegar colete", false, windowPolice)
end)

addEventHandler ("onClientMarkerHit", dp, function (hitPlayer, matchingDimension)
	if hitPlayer and getElementType (hitPlayer) == "player" and matchingDimension then
		render ()
	end	
end)

addEventHandler ( "onClientMarkerLeave", getRootElement(), markerLeave )

function render ()
	if not guiGetVisible (windowPolice) then -- Seta a janela principal não estiver ativa, então:
		guiSetVisible (windowPolice, true) -- Seta a janela principal como true (ativada).
		showCursor (true) -- Seta o cursor como true (ativado).
	else -- Senão:
		guiSetVisible (windowPolice, false) -- Seta a janela principal como false (desativada).
		showCursor (false) -- Seta o cursor como false (desativado).
	end
end

addEventHandler ("onClientGUIClick", root, function (btn)
    if btn ~= "left" then return end -- Se o botão clicado do mouse não for o esquerdo, cancela a função e nada acontece.
	if source == aguia then -- Se o botão clicado for o botão aguia, então:
		--createVehicle (432, 1601.6129150391,-1699.3563232422,5.890625)
	elseif source == vtr1 then -- Se o botão clicado for o botão vtr1, então:
		-- createVehicle (432, 1603.0577392578, -1684.6134033203, 5.890625)
	elseif source == vtr2 then -- Se o botão clicado for o botão vtr2, então:
		-- createVehicle (432, 1601.2092285156, -1692.5222167969, 5.890625)
	elseif source == vtr3 then -- Se o botão clicado for o botão vtr3, então:
		-- createVehicle (432, 1601.6129150391, -1699.3563232422, 5.890625)
		-- OBS: Veículos tem que ser criados server-side pois client-side são apenas enfeites. (não funcionam)
		-- Mande um trigger para o server pra criar os veículos.
	elseif source == f1 then -- Se o botão clicado for o botão f1, então:
		setElementModel (localPlayer, 2)
	elseif source == f2 then -- Se o botão clicado for o botão f2, então:
		setElementModel (localPlayer, 4)
	elseif source == f3 then -- Se o botão clicado for o botão f3, então:
		setElementModel (localPlayer, 1)
	elseif source == f4 then -- Se o botão clicado for o botão f4, então:
		setElementModel (localPlayer, 4)
	end
end)

 

Edited by Jonas^
Link to comment
  • Other Languages Moderators
8 hours ago, Eficiencia said:

no exemplo da wiki tem false no final. coloco ou nao?

O false é usado em funções onde você especifica o botão no eventHandler em vez de usar o source para verificar qual o guiElement que foi clicado. O false indica que a função não deve pegar os elementos parentes ao clicar nos elementos filhos. Por exemplo, se vc clica em um botão, na verdade está clicando na janela também. Se não tiver o false, ele vai ativar a função 2x (uma por clicar na janela e outra por clicar no botão). O false evita que ele considere a janela ao clicar no botão. Se vc não declarar o botão direto no addEventHandler e usar o source em vez disso, então não precisa do false, pois ele só vai passar caso a condição do source for verdadeira.

Note: If the GUI Element attached to this event has a parent element, this event will be triggered once the parent element of the attached element is clicked too. You can set the parameter getPropagated to false in the call to addEventHandler to prevent this.

Edited by Lord Henry
Errei 1 vírgula.
Link to comment
  • Other Languages Moderators

Quando usar o source, quando declarar o botão no evento e quando usar o parâmetro getPropagated (o false):

addEventHandler ("onClientGUIClick", button01, functionQualquer) -- Sem o false e declarando o botão que deve chamar essa função.

Esse caso acima é recomendado para botões únicos e que não tenham parentes. Quando vc só tem um único botão, é mais fácil declará-lo direto no evento ativador. Por não existir um parente desse botão, não precisa do false. Se existisse um parente (como uma janela) dai precisaria do false, caso contrário a função seria ativada novamente para esse parente.

addEventHandler ("onClientGUIClick", button01, functionQualquer, false) -- Com o false e declarando o botão.

Esse caso com o false é recomendado para casos de um botão único e que possui algum parente, como uma guiWindow. O false evita que a janela seja considerada ao clicar no botão. Ativando a função somente 1 vez por clique.

addEventHandler ("onClientGUIClick", root, functionQualquer) -- Sem declarar o botão e sem o false.

Nesse último caso é o mais comum e recomendado para a maioria dos casos onde uma janela possui vários botões. Você não declara um botão específico no evento, usa-se root para que a função ative em qualquer guiElement clicável. Dentro da função, vc usa source para saber qual elemento foi clicado e se ele é igual a tal botão, por exemplo:

if (source == button01) then
	-- Faz algo.
elseif (source == button02) then
	-- Faz outra coisa.
end

Em vez de usar vários addEventHandlers para cada botão, e uma função diferente para cada botão, usa-se a mesma função e o mesmo addEventHandler para todos, diferenciando o que cada um dos botões faz através das condições. Isso é questão de otimização. Vários eventos pequenos são mais pesados do que um único evento grande.

  • Like 1
  • Thanks 1
Link to comment
  • Moderators
13 hours ago, MaligNos said:

Uma boa também é usar resourceRoot no lugar de root, assim aciona a função apenas para elementos pertencentes ao mesmo resource, evitando com isso chamadas desnecessárias por elementos de outros resources.

Uma maneira ainda mais efetiva é utilizar getResourceGUIElement - cuja variável predefinida é guiRoot.

Ex:

addEventHandler ("onClientGUIClick", guiRoot, functionQualquer) -- Sem declarar o botão e sem o false.

É um hábito que todos que buscam otimizar seus scripts devem ter. root (getRootElement()) sempre deve ser evitado quando possível.

Edited by DNL291
  • Like 2
Link to comment
16 hours ago, Lord Henry said:

Quando usar o source, quando declarar o botão no evento e quando usar o parâmetro getPropagated (o false):


addEventHandler ("onClientGUIClick", button01, functionQualquer) -- Sem o false e declarando o botão que deve chamar essa função.

Esse caso acima é recomendado para botões únicos e que não tenham parentes. Quando vc só tem um único botão, é mais fácil declará-lo direto no evento ativador. Por não existir um parente desse botão, não precisa do false. Se existisse um parente (como uma janela) dai precisaria do false, caso contrário a função seria ativada novamente para esse parente.


addEventHandler ("onClientGUIClick", button01, functionQualquer, false) -- Com o false e declarando o botão.

Esse caso com o false é recomendado para casos de um botão único e que possui algum parente, como uma guiWindow. O false evita que a janela seja considerada ao clicar no botão. Ativando a função somente 1 vez por clique.


addEventHandler ("onClientGUIClick", root, functionQualquer) -- Sem declarar o botão e sem o false.

Nesse último caso é o mais comum e recomendado para a maioria dos casos onde uma janela possui vários botões. Você não declara um botão específico no evento, usa-se root para que a função ative em qualquer guiElement clicável. Dentro da função, vc usa source para saber qual elemento foi clicado e se ele é igual a tal botão, por exemplo:


if (source == button01) then	-- Faz algo.elseif (source == button02) then	-- Faz outra coisa.end

Em vez de usar vários addEventHandlers para cada botão, e uma função diferente para cada botão, usa-se a mesma função e o mesmo addEventHandler para todos, diferenciando o que cada um dos botões faz através das condições. Isso é questão de otimização. Vários eventos pequenos são mais pesados do que um único evento grande.

entendi no caso false serve pra evitar que quando o player clicar no botao não selecione a janela junto

Edited by Eficiencia
Link to comment
  • Other Languages Moderators
22 hours ago, Eficiencia said:

entendi no caso false serve pra evitar que quando o player clicar no botao não selecione a janela junto

Não. Serve pra evitar de ativar a função novamente por clicar no parente junto.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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