Jump to content

[Ajuda] Dificuldade do trigger


Recommended Posts

Tudo bem? Bom não sei se to fazendo algo de errado desse script e tbm não sei se isso funciona. Eu estou tentando pegar o marker de um script.lua e levar para outro .lua exemplo crio o Marker do exemplo.lua e queria leva ele para o exemplo2.lua so que nao sei . Aqui esta o meu script de como estou fazendo

 

Pegar o marker desse script.

addEvent("opengui",true)
    function opengui_func()
        AgenciaT = guiCreateWindow(412, 90, 546, 486, "Agencia de Empregos", false)

        Aceitar = guiCreateButton(78, 436, 130, 27, "Aceitar", false, AgenciaT)
        Cancelar = guiCreateButton(348, 436, 130, 27, "Cancelar", false, AgenciaT)
        Lista = guiCreateGridList(53, 170, 451, 253, false, AgenciaT)
        guiGridListAddColumn(Lista, "Empregos", 0.3)
        guiGridListAddColumn(Lista, "Salários", 0.3)
        guiGridListAddColumn(Lista, "Cidades", 0.3)
        for i = 1, 2 do
            guiGridListAddRow(Lista)
        end
        guiGridListSetItemText(Lista, 0, 1, "Piloto", false, false)
        guiGridListSetItemText(Lista, 0, 2, "1500", false, false)
        guiGridListSetItemText(Lista, 0, 3, "Los Santos", false, false)
        guiGridListSetItemText(Lista, 1, 1, "Fazendeiro", false, false)
        guiGridListSetItemText(Lista, 1, 2, "1000", false, false)
        guiGridListSetItemText(Lista, 1, 3, "Los Santos", false, false)
	    Messager = guiCreateMemo(48, 38, 451, 124, "Seja Bem Vindo a Prefeitura do Servidor, BRASIL TOP RPG para você começar a trabalhar precisa selecionar o emprego que você deseja trabalhar e apertar em Aceitar. Boa Sorte com seu novo emprego", false, AgenciaT)
		guiMemoSetReadOnly ( Messager, true)
		showCursor(true)
		addEventHandler("onClientGUIClick", Cancelar, function()
		destroyElement(AgenciaT)
		showCursor(false)
		end, false)
		
		function onGridListClick(source)
			local itemrow,itemcolumn = guiGridListGetSelectedItem(Lista)
			if itemrow ~= -1 then
			if guiGridListGetItemText( Lista, itemrow, 1 ) == "Piloto" then
			blip = createBlip ( 2003.5859375, -2401.1025390625, 13.546875, 42)
            outputDebugString("Blip visible distance: "..getBlipVisibleDistance(blip))
            setBlipVisibleDistance(blip, 10000) -- Distancia Aeroporto LS
			outputChatBox("Local marcador vá até o [T]", source) 
			destroyElement(AgenciaT)
			showCursor(false)
			else
			if itemrow ~= -1 then
			if guiGridListGetItemText( Lista, itemrow, 1 ) == "Fazendeiro" then
			Carro = createMarker (1482.3427734375, -1729.4150390625, 13.3828125 -1, "cylinder", 2, 255 ,0 ,0, 255) --Quero levar esse marker para outro .lua para pode spawna o veiculo
			triggerServerEvent(source, "trabalho", source, true) -- e aqui é quando leva para o script servidor bom nao se se é aqui o erro
			outputChatBox("Local marcador vá até o [T]", source) 
			destroyElement(AgenciaT)
			showCursor(false)
			       end
			    end
			  end
		   end
		end
		addEventHandler("onMarkerHit",Carro,onGridListClick) -- o evento
		addEventHandler("onClientGUIClick", Aceitar, onGridListClick)
				end
addEventHandler("opengui", root, opengui_func)

E levar para esse script. 

local marker = createMarker(362.8115234375, 173.8154296875, 1008.3828125 -1, "cylinder", 1.5, 255, 0, 0)
setElementInterior(marker, 3)
function guioeffnen(player)
	triggerClientEvent(player, "opengui", player, true)
end
addEventHandler("onMarkerHit",marker,guioeffnen)


function pegar (source) -- quero usar o marker de la para fazer essa função 
if isElementWithinMarker(source, Carro) then
if veh[source] and isElement( veh[source] ) then destroyElement ( veh[source] )
veh[source] = nil
end
x,y,z = getElementPosition(source)
Islamico = true
veh[source] = createVehicle(422,1481.083984375, -1730.6201171875, 13.3828125, 0, 0, 109.58242797852)
warpPedIntoVehicle( source, veh[source] )
end
addEvent("trabalho",true)
end
addEventHandler( "onMarkerHit",Carro, pegar )
 
Edited by NewGamer
Link to comment
  • Other Languages Moderators

Fica meio difícil entender seu código server-side sem indentação. Mas pelo que percebi, você adicionou o event "trabalho", mas em momento algum você ativou ele.

Veja como é feito no triggerServerEvent. Perceba que após ele adicionar o evento, ele já chama o evento usando addEventHandler.

Além disso você precisa passar o marker pelos parâmetros do evento "trabalho" caso você queira usá-lo no outro script, mas você só passou um argumento true.

triggerServerEvent(source, "trabalho", source, true) -- Pra que serve o argumento true? E cadê o marker nos argumentos? Você criou o marker mas não passou ele pro outro script pelo trigger.

 

Link to comment

Erro: WARNING: Agencia\Agencia.s.lua:19: Bad argument @ 'addEventHandler' [Expected element at argument 2, got nil] do lado Servidor

function pegar (source)
if isElementWithinMarker(source, Carro) then
if veh[source] and isElement( veh[source] ) then destroyElement ( veh[source] )
veh[source] = nil
end
x,y,z = getElementPosition(source)
Islamico = true
veh[source] = createVehicle(422,1481.083984375, -1730.6201171875, 13.3828125, 0, 0, 109.58242797852)
warpPedIntoVehicle( source, veh[source] )
end
end
addEventHandler("onMarkerHit", source, pegar)
addEvent("trabalho",true)

 

Link to comment
  • Moderators

Client:

function opengui_func()
	AgenciaT = guiCreateWindow(412, 90, 546, 486, "Agencia de Empregos", false)

	Aceitar = guiCreateButton(78, 436, 130, 27, "Aceitar", false, AgenciaT)
	Cancelar = guiCreateButton(348, 436, 130, 27, "Cancelar", false, AgenciaT)
	Lista = guiCreateGridList(53, 170, 451, 253, false, AgenciaT)
	guiGridListAddColumn(Lista, "Empregos", 0.3)
	guiGridListAddColumn(Lista, "Salários", 0.3)
	guiGridListAddColumn(Lista, "Cidades", 0.3)
	for i = 1, 2 do
		guiGridListAddRow(Lista)
	end
	guiGridListSetItemText(Lista, 0, 1, "Piloto", false, false)
	guiGridListSetItemText(Lista, 0, 2, "1500", false, false)
	guiGridListSetItemText(Lista, 0, 3, "Los Santos", false, false)
	guiGridListSetItemText(Lista, 1, 1, "Fazendeiro", false, false)
	guiGridListSetItemText(Lista, 1, 2, "1000", false, false)
	guiGridListSetItemText(Lista, 1, 3, "Los Santos", false, false)
	Messager = guiCreateMemo(48, 38, 451, 124, "Seja Bem Vindo a Prefeitura do Servidor, BRASIL TOP RPG para você começar a trabalhar precisa selecionar o emprego que você deseja trabalhar e apertar em Aceitar. Boa Sorte com seu novo emprego", false, AgenciaT)
	guiMemoSetReadOnly ( Messager, true)
		
	addEventHandler("onClientGUIClick", Cancelar, function()
		guiSetVisible(AgenciaT, false)
		showCursor(false)
	end, false)
		
	addEventHandler("onClientGUIClick", Aceitar, onGridListClick)
end
addEventHandler( "onClientResourceStart", resourceRoot, opengui_func )

function guioeffnen(player, d)
	if player == localPlayer and d then
		guiSetVisible(AgenciaT, true)
		showCursor(true)
	end
end
addEventHandler("onClientMarkerHit",marker,guioeffnen)

function onGridListClick()
	local itemrow,itemcolumn = guiGridListGetSelectedItem(Lista)
	if itemrow ~= -1 and guiGridListGetItemText( Lista, itemrow, 1 ) == "Piloto" then
		piloto_marker = createMarker( )
		piloto_blip = createBlipAttachedTo(piloto_marker)
		addEventHandler( "onClientMarkerHit", piloto_marker, onJobMarkerHit )
		
		triggerServerEvent( "server:takeJob", localPlayer, coloca_o_id_do_carro )
		outputChatBox("Local marcador vá até o [T]")
			
		guiSetVisible(AgenciaT, false)
		showCursor(false)
	elseif itemrow ~= -1 and guiGridListGetItemText( Lista, itemrow, 1 ) == "Fazendeiro" then
		fazendeiro_marker = createMarker( )
		fazendeiro_blip = createBlipAttachedTo(fazendeiro_marker)
		addEventHandler( "onClientMarkerHit", fazendeiro_marker, onJobMarkerHit )
				
		triggerServerEvent( "server:takeJob", localPlayer, coloca_o_id_do_carro )
		outputChatBox("Local marcador vá até o [T]")
				
		guiSetVisible(AgenciaT, false)
		showCursor(false)
	end
end

function onJobMarkerHit( thePlayer )
	--
end

Server:

local veh = {}
function takeJob( vehID ) -- quero usar o marker de la para fazer essa função 
	if veh[source] and isElement( veh[source] ) then destroyElement ( veh[source] )
		veh[source] = nil
	end
	veh[source] = createVehicle( tonumber(vehID), getElementPosition(source) )
	warpPedIntoVehicle( source, veh[source] )
end
addEvent("server:takeJob",true)
addEventHandler("server:takeJob", root, takeJob)

Coloquei as marcas no lado client porque é o lado mais apropriado, apenas o veículo deve ficar no lado server.

O código tava muito confuso, então refiz quase tudo. E a função onJobMarkerHit vai ser chamada quando uma das marcas ou do piloto ou fazendeiro for atingida.

Link to comment
  • Moderators

Ok. Sobre a marca no lado server, a questão é que você não vai querer mostrar elas a outros jogadores e vai ter que ficar usando setElementVisibleTo pra deixar visível só pro jogador que está trabalhando, já criando no lado client, vai ser sempre criado pro jogador local e dispensa esse trabalho extra de ter que ocultar dos outros jogadores.

  • Thanks 1
Link to comment
4 minutes ago, DNL291 said:

Ok. Sobre a marca no lado server, a questão é que você não vai querer mostrar elas a outros jogadores e vai ter que ficar usando setElementVisibleTo pra deixar visível só pro jogador que está trabalhando, já criando no lado client, vai ser sempre criado pro jogador local e dispensa esse trabalho extra de ter que ocultar dos outros jogadores.

Grande professor!!!

Link to comment

Bom nao sei se fiz algo de errado ou o codigo ta meio errado num sei. Mas quando eu inicio o script a GUI ja aparece e nao era para aparecer .

Edit: O erro da GUI abrir quando iniciar o script arrumei e a setar tbm so que quando eu aperto do Piloto eu vou direto para o veiculo mas eu quero passa pelo marker primeiro ai sim eu vou por veiculo.

local veh = {}
function takeJob( vehID ) -- quero usar o marker de la para fazer essa função 
	if veh[source] and isElement( veh[source] ) then destroyElement ( veh[source] )
		veh[source] = nil
	end
	veh[source] = createVehicle(422,-282.26953125, 1529.451171875, 75.359375, 0, 0, 109.58242797852)
	warpPedIntoVehicle( source, veh[source] )
end
addEvent("server:takeJob",true)
addEventHandler("server:takeJob", root, takeJob)

 

Edited by NewGamer
Link to comment
  • Moderators

Tente:


addEventHandler( "onClientResourceStart", resourceRoot,
	function()
		addEventHandler( "onClientMarkerHit", resourceRoot, onJobMarkerHit )
	end
)

function onGridListClick()
	local itemrow,itemcolumn = guiGridListGetSelectedItem(Lista)
	if itemrow ~= -1 and guiGridListGetItemText( Lista, itemrow, 1 ) == "Piloto" then
		piloto_marker = createMarker( )
		piloto_blip = createBlipAttachedTo(piloto_marker)
		
		outputChatBox("Local marcador vá até o [T]")
			
		guiSetVisible(AgenciaT, false)
		showCursor(false)
	elseif itemrow ~= -1 and guiGridListGetItemText( Lista, itemrow, 1 ) == "Fazendeiro" then
		fazendeiro_marker = createMarker( )
		fazendeiro_blip = createBlipAttachedTo(fazendeiro_marker)
				
		outputChatBox("Local marcador vá até o [T]")
				
		guiSetVisible(AgenciaT, false)
		showCursor(false)
	end
end

function onJobMarkerHit( theElement, d )
	if theElement == localPlayer and d then
		if source == piloto_marker then
			triggerServerEvent( "server:takeJob", theElement, coloca_o_id_do_carro )
		elseif source == fazendeiro_marker  then
			triggerServerEvent( "server:takeJob", theElement, coloca_o_id_do_carro )
		end
	end
end

 

Edited by DNL291
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...