Jump to content

tempo para entrar no carro


Recommended Posts

  • Other Languages Moderators
3 hours ago, kevincouto6 said:

Olá deixei apenas a parte de criar o veiculo agora 

esta é a parte server


function inicio6 ()
    if isElement (veh6[client]) then 
        destroyElement (veh6[client])
        veh6[client] = nil
    end
    local vx ,vy, vz, vrot = localitionveh6[ i ][ 2 ], localitionveh6[ i ][ 3 ], localitionveh6[ i ][ 4 ], localitionveh6[ i ][ 7 ]
    i = i + 1
    if i > #localitionveh6 then 
        i = 1
    end
    Trabalho = true
    veh6[client] = createVehicle ( 401, vx, vy, vz, 0, 0, vrot )
    setElementVisibleTo (Bfim6, client, true)
    outputChatBox ("#ffff00Drive the vehicle to the checkpoint. Note: You cannot leave the car during the mission.", client, 0, 0, 0, true)
    triggerClientEvent (client, "mission6", client,veh6)

end
addEvent ("iniciaJob6", true) 
addEventHandler ("iniciaJob6", getRootElement(), inicio6)

 

Cadê a tabela veh6? Eu não disse pra você deletar ela, falei pra passar ela ela pro server.

Link to comment

A tabela não foi removida apenas esqueci de copiar tudo copiei apenas do inicio para baixo 

Mfim6 = createMarker (-1828.72888, -1627.62219, 23.23001 -1, "cylinder", 2, 0 ,255 ,0, 255)

Bfim6 = createBlipAttachedTo ( Mfim6, 19 )
setElementVisibleTo ( Bfim6, root, false )

veh6 = {}

localitionveh6 = {
    [1] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
    [2] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
    [3] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
    [4] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
    [5] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
}

i = 1 

function inicio6 ()
    if isElement (veh6[client]) then 
        destroyElement (veh6[client])
        veh6[client] = nil
    end
    local vx ,vy, vz, vrot = localitionveh6[ i ][ 2 ], localitionveh6[ i ][ 3 ], localitionveh6[ i ][ 4 ], localitionveh6[ i ][ 7 ]
    i = i + 1
    if i > #localitionveh6 then 
        i = 1
    end
    Trabalho = true
    veh6[client] = createVehicle ( 401, vx, vy, vz, 0, 0, vrot )
    setElementVisibleTo (Bfim6, client, true)
    outputChatBox ("#ffff00Drive the vehicle to the checkpoint. Note: You cannot leave the car during the mission.", client, 0, 0, 0, true)
    triggerClientEvent (client, "mission6", client,veh6)

end
addEvent ("iniciaJob6", true) 
addEventHandler ("iniciaJob6", getRootElement(), inicio6)

lado client

function partClientSixMission (veh6)	
 
    local counter = 0
    setTimer(function(p)
        for seat, player in pairs??(getVehicleOccupants(veh6[p])) do
            counter = counter + 1
        end
   
        if counter > 0 then
            outputChatBox ( "Voçê esta no Vehicle", p, 255, 255, 255, true )
        else
            outputChatBox ( "Voçê Nao entrou no veiculo a tempo mission failed", p, 255, 255, 255, true )
            destroyElement (veh6[p])        
        end
            counter = 0
    end, 5000, 1)
		local player6 = client
	addEventHandler ( "onClientVehicleExplode", veh6[client], function ()
		if (veh6[player6]) and isElement(veh6[player6]) then
			destroyElement (source)
			takePlayerMoney ( player6, 5000 )
			setElementVisibleTo ( Bfim6, player6, false )
			outputChatBox("Mission failed, your veh6icle blew up.", player6 , 255, 0, 0)
		end
	end)	
	
end
addEvent ("mission6", true)
addEventHandler ("mission6", localPlayer, partClientSixMission)

o e rro que aparece no debbug é  "do" ( expected near ) line 5

Link to comment

Eu poderia add o script inteiro se nessesario porem e bastante coisa, eu tentei modificar o lado client, mas sempre aparecem esses erros @Lord Henry @DNL291

mission2/c.mission.lua252: Bad argument @'getVehicleOccupants'[Expecred vehicle at argument 1, got nill]

mission2/c.mission.lua252: Bad argument #1 to 'pairs' (table expected, got boolean)

ou 

attempt to index a userdata value

Gui.Client.lua

addEventHandler ("onClientGUIClick", getRootElement(), 
	function (button, state, absoluteX, absoluteY)
   	 	outputDebugString("onClientGUIClick called.") 
          local me = not guiGetVisible (WinMission)
                  if (source == accepted) then
                      outputDebugString("guiGridListGetSelectedItem(ListMissions): "..guiGridListGetSelectedItem(ListMissions))
                          elseif (guiGridListGetSelectedItem(ListMissions) == 5) then
                              outputDebugString("6 was selected")
                              triggerServerEvent ("iniciaJob6", localPlayer)
                              guiSetVisible (WinMission, me)
                              showCursor (me)
                              for wnd, id in pairs(elementos.window) do
                              guiSetVisible (wnd, false)
                          end
                  end
     	end
end
)

Server.lua

veh6 = {}

localitionveh6 = {
	[1] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
	[2] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
	[3] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
	[4] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
	[5] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
}

i = 1 

function inicio6 ()

	if isElement (veh6[client]) then 
		destroyElement (veh6[client])
		veh6[client] = nil
	end
	local vx ,vy, vz, vrot = localitionveh6[ i ][ 2 ], localitionveh6[ i ][ 3 ], localitionveh6[ i ][ 4 ], localitionveh6[ i ][ 7 ]
	i = i + 1
	if i > #localitionveh6 then 
		i = 1
	end
	Trabalho = true
	veh6[client] = createVehicle ( 401, vx, vy, vz, 0, 0, vrot )
	setElementVisibleTo (Bfim6, client, true)
	outputChatBox ("#ffff00Drive the vehicle to the checkpoint. Note: You cannot leave the car during the mission.", client, 0, 0, 0, true)
	triggerClientEvent (client, "mission6", client, veh6[source])

end
addEvent ("iniciaJob6", true) 
addEventHandler ("iniciaJob6", getRootElement(), inicio6)

mission.client.lua

function timesveh ( veh6)	

outputDebugString("funcionando")   

   local counter = 0
    setTimer(function(p)
     
		for seat, player in pairs (getVehicleOccupants(veh6[p])) do
            counter = counter + 1
        end

        if counter > 0 then
            outputChatBox ( "Voçê esta no Vehicle", p, 255, 255, 255, true )
        else
            outputChatBox ( "Voçê Nao entrou no veiculo a tempo mission failed", p, 255, 255, 255, true )
            destroyElement (veh6[p])        
        end
            counter = 0
    end, 1000, 1, p)

end
addEvent ("mission6", true)
addEventHandler ("mission6", localPlayer, timesveh)

 

Edited by kevincouto6
Link to comment

Teste:

mission_client.lua

function timesveh (veh6)	
	outputDebugString("funcionando")   

	local counter = 0
	setTimer(function()
		for seat, player in pairs (getVehicleOccupants(veh6)) do
				counter = counter + 1
		end
		if counter > 0 then
			outputChatBox ( "Voçê esta no Vehicle", 255, 255, 255, true )
		else
			outputChatBox ( "Voçê Nao entrou no veiculo a tempo mission failed", 255, 255, 255, true )
			triggerServerEvent("delVeh",localPlayer)
		end
		counter = 0
	end,1000,1)

end
addEvent ("mission6", true)
addEventHandler ("mission6", localPlayer, timesveh)

Server.lua

veh6 = {}

localitionveh6 = {
	[1] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
	[2] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
	[3] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
	[4] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
	[5] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
}

i = 1 

function inicio6 ()

	if isElement (veh6[client]) then 
		destroyElement (veh6[client])
		veh6[client] = nil
	end
	local vx ,vy, vz, vrot = localitionveh6[ i ][ 2 ], localitionveh6[ i ][ 3 ], localitionveh6[ i ][ 4 ], localitionveh6[ i ][ 7 ]
	i = i + 1
	if i > #localitionveh6 then 
		i = 1
	end
	Trabalho = true
	veh6[client] = createVehicle ( 401, vx, vy, vz, 0, 0, vrot )
	setElementVisibleTo (Bfim6, client, true)
	outputChatBox ("#ffff00Drive the vehicle to the checkpoint. Note: You cannot leave the car during the mission.", client, 0, 0, 0, true)
	triggerClientEvent (client, "mission6", client, veh6[client])

end
addEvent ("iniciaJob6", true) 
addEventHandler ("iniciaJob6", getRootElement(), inicio6)

addEvent( "delVeh", true )
addEventHandler( "delVeh", getRootElement(),
	function()
		if isElement (veh6[client]) then 
			destroyElement (veh6[client])
			veh6[client] = nil
		end
	end
)

 

Edited by MaligNos
Link to comment
  • Moderators

As localizações junto com a variável devem ser no lado client; assim como o blip e as markers. No lado server é só o veículo como já foi dito (give/takePlayerMoney também caso você use).

Edit: esse seu código aqui tem um 'end' a mais:

2 hours ago, kevincouto6 said:

 


addEventHandler ("onClientGUIClick", getRootElement(), 
	function (button, state, absoluteX, absoluteY)
   	 	outputDebugString("onClientGUIClick called.") 
          local me = not guiGetVisible (WinMission)
                  if (source == accepted) then
                      outputDebugString("guiGridListGetSelectedItem(ListMissions): "..guiGridListGetSelectedItem(ListMissions))
                          elseif (guiGridListGetSelectedItem(ListMissions) == 5) then
                              outputDebugString("6 was selected")
                              triggerServerEvent ("iniciaJob6", localPlayer)
                              guiSetVisible (WinMission, me)
                              showCursor (me)
                              for wnd, id in pairs(elementos.window) do
                              guiSetVisible (wnd, false)
                          end
                  end
     	end
end
)

 

Fora isso também tem a variável "Trabalho", você pode trocar por um setElementData e setar no jogador; e remove ou seta nil quando ele não tiver mais no trabalho.

Eu editei aqui como seria o código, só não testei. Aqui está (Leia comentário na parte do setTimer ?) :

Client


local localitionveh6 = {
	[1] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
	[2] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
	[3] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
	[4] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
	[5] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
}

local i = 1 

function createPlayerLocation()
	local vx ,vy, vz, vrot = localitionveh6[ i ][ 2 ], localitionveh6[ i ][ 3 ], localitionveh6[ i ][ 4 ], localitionveh6[ i ][ 7 ]
	i = i + 1
	if i > #localitionveh6 then 
		i = 1
	end
	triggerServerEvent( "iniciaJob6", localPlayer, vx, vy, vz, vrot )
end

Server


local veh6 = {}

function inicio6 ( vx, vy, vz, vrot )
	if client ~= source then return end -- cheater detected!

	if isElement (veh6[client]) then 
		destroyElement (veh6[client])
	end
	
	setElementData( client, "Trabalho", true, false ) -- seta o jogador no element-data "Trabalho"; sinc com o client desativada
	
	veh6[client] = createVehicle ( 401, vx, vy, vz, 0, 0, vrot )
	outputChatBox ("#ffff00Drive the vehicle to the checkpoint. Note: You cannot leave the car during the mission.", client, 0, 0, 0, true)
	
	local counter = 0
	setTimer( function(p)
		if not ( isElement( veh6[p] ) ) then return end
		
		--[[ Acho que aqui o correto é verificar se quem está no veículo 
			é o jogador que tá no trabalho;
			Então seria assim:
			if getVehicleController(veh6[p]) == p then
				outputChatBox ( "Voçê esta no Vehicle", p, 255, 255, 255, true )
			else
				[....]
		]]
		
		for seat, player in pairs (getVehicleOccupants(veh6[p])) do
			counter = counter + 1
		end

		if counter > 0 then
			outputChatBox ( "Voçê esta no Vehicle", p, 255, 255, 255, true )
		else
			outputChatBox ( "Voçê Nao entrou no veiculo a tempo mission failed", p, 255, 255, 255, true )
			destroyElement (veh6[p])
			veh6[p] = nil
		end
		counter = 0
	end, 1000, 1, client )
	
	local player = client
	addEventHandler ( "onClientVehicleExplode", veh6[player], function ()
		destroyElement (source)
		veh6[player] = nil
		takePlayerMoney ( player, 5000 )
		outputChatBox("Mission failed, your veh6icle blew up.", player , 255, 0, 0)
	end)
	
end
addEvent ("iniciaJob6", true) 
addEventHandler ("iniciaJob6", getRootElement(), inicio6)

Não fiz muita coisa no client porque você não mostrou todo o código.

 

Edited by DNL291
Link to comment

Me baseando no que voçê me enviou fiz isso 

gui.client.lua 

Neste aqui eu troquei tringgerEvent por  "createPlayerLocalition" assim ativa a localisão e depois ativa a criação do veiculo,

elseif (guiGridListGetSelectedItem(ListMissions) == 5) then
    outputDebugString("6 was selected")
	createPlayerLocation ()
	guiSetVisible (WinMission, me)
	showCursor (me)
	for wnd, id in pairs(elementos.window) do
	guiSetVisible (wnd, false)
	end
end

mission.client.lua

Como voçês tinham falado anteriormente para passar tudo para o lado CLIENT então passei, bom o timer esta funcionando, porem a função que foi me recomendado usar  "getVehicleController" para detectar se quem entrou no veh é o player da mission, não funcionou pois como esta no lado server não estou conseguindo detectar o jogador,  e outra coisa que tenho que resolver e o destroyElement ( veh6 ) ele não esta funcionando,

local localitionveh6 = {
	[1] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
	[2] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
	[3] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
	[4] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
	[5] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
}
local i = 1 

function createPlayerLocation()
	local vx ,vy, vz, vrot = localitionveh6[ i ][ 2 ], localitionveh6[ i ][ 3 ], localitionveh6[ i ][ 4 ], localitionveh6[ i ][ 7 ]
	i = i + 1
	if i > #localitionveh6 then 
		i = 1
	end
	triggerServerEvent( "iniciaJob6", localPlayer, vx, vy, vz, vrot )
end

function vehiclePartsMission6 ( veh6 )

	outputDebugString("funcionando")   

local counter = 0

		setTimer( function()
	
			if not ( isElement( veh6 ) ) then return end
		
			for seat, player in pairs (getVehicleOccupants(veh6)) do
				counter = counter + 1
			end
			
			if counter > 0 then
        		if getVehicleController(veh6) == p then
					outputChatBox ( "Voçê esta no Vehicle", 255, 255, 255, true )
					Mfim6 = createMarker (-1828.72888, -1627.62219, 23.23001 -1, "cylinder", 2, 0 ,255 ,0, 255)
					Bfim6 = createBlipAttachedTo ( Mfim6, 19 
            		else
            			outputChatBox ( "Voçê não é o player da mission, Por favor saia do veiculo !" )
            		end   	
			else
				outputChatBox ( "Voçê Nao entrou no veiculo a tempo mission failed", 255, 255, 255, true )
				destroyElement ( veh6[localPlayer] )
				veh6 = nil
			end
			counter = 0
		
		end, 5000, 1, client )
	
		function blowvehicle6 ()
			if veh6 and isElement(veh6) then
				outputChatBox("Mission failed, your veh6icle blew up.")
				destroyElement (veh6)
			else
			end
		end
		addEventHandler ( "onClientVehicleExplode", veh6, blowvehicle6)
		
		function sair6 (thePlayer) 
			if source == veh6[thePlayer] then 
				if isTimer (timerVeh[source]) then 
					resetTimer (timerVeh[source]) 
				else 
					timerVeh[source] = setTimer (function () 
						destroyElement(veh6[thePlayer])
						veh6[thePlayer] = nil
						triggerClientEvent (thePlayer, "failPlayerLeave5", thePlayer) 
					end, 60000, 1)
				end
			end
		end
		addEventHandler ("onClientVehicleExit", getRootElement(), sair6)
		
		function entrar6 (thePlayer)
			if isTimer (timerVeh[source]) then 
				killTimer (timerVeh[source]) 
			end
		end
		addEventHandler ("onClientVehicleEnter", getRootElement(), entrar6)
		
		function playerDead5() 
			if veh6 and isElement(veh6) then
				outputChatBox("Mission failed, your veh6icle blew up.")
			else
			end
		end
		addEventHandler("onClientPlayerWasted", root, playerDead5)
		
		function finalmission6 ()
			if veh6 and isElement(veh6) then
				outputChatBox("Mission failed, your veh6icle blew up.")
			else
			end
		end
		addEventHandler("onClientMarkerHit",Mfim6 ,finalmission6)
		
		
end
addEvent ("partesMissionSix", true) 
addEventHandler ("partesMissionSix", getRootElement(), vehiclePartsMission6)

server.lua

aqui foi como ficou o lado server

local veh6 = {}
function inicio6 ( vx, vy, vz, vrot )

	if client ~= source then return end -- cheater detected!
	if isElement (veh6[client]) then 
		destroyElement (veh6[client])
	end
	
	setElementData( client, "Trabalho", true, false ) -- seta o jogador no element-data "Trabalho"; sinc com o client desativada
	
	veh6[client] = createVehicle ( 401, vx, vy, vz, 0, 0, vrot )
	outputChatBox ("#ffff00Drive the vehicle to the checkpoint. Note: You cannot leave the car during the mission.", client, 0, 0, 0, true)
	
	triggerClientEvent (client, "partesMissionSix", client, veh6[client]) 
end
addEvent ("iniciaJob6", true) 
addEventHandler ("iniciaJob6", getRootElement(), inicio6)

Então o que tenho que resolver

1) add a verificação se o jogador da missião que esta entrando no veiculo  

2)destruir o veiculo no lado Client, se não for possível, vou tentar com tringgerEvents 

poderiam me ajudar com isso, e se tiver mais alguma coisa a ser mudado pf avise-me, obrigado desde já

Edited by kevincouto6
Link to comment
  • Other Languages Moderators
1 hour ago, kevincouto6 said:

Então o que tenho que resolver

1) add a verificação se o jogador da missião que esta entrando no veiculo  

2)destruir o veiculo no lado Client, se não for possível, vou tentar com tringgerEvents 

poderiam me ajudar com isso, e se tiver mais alguma coisa a ser mudado pf avise-me, obrigado desde já

2) Terá que ser com triggerServerEvent. Pois se você tentar usar o destroyElement no client, ele vai dizer que o veículo não existe, pois ele foi criado no server. Basta você usar o triggerServerEvent que executa uma função de destruição no server, que irá verificar se o veh6[client] existe e depois destruir ele. Não se esqueça de anular a variável do veículo depois disso com veh6[client] = nil.

Link to comment

Tudo que voçê falou foi feito, porem quando eu estava testando percebi algo, tipo ele so vai detectar  se voçê esta no veiculo depois que der o tempo maximo tipo 1 min, se o player entrar no veiculo com 12 sec ele tera que esperar mais 48 sec para receber a messagem de que esta no veiculo. exite alguma forma de eu fazer que assim que ele entre no veiculo inicie 

?
local counter = 0

		setTimer( function()
	
			if not ( isElement( veh6 ) ) then return end
		
			for seat, player in pairs (getVehicleOccupants(veh6)) do
				counter = counter + 1
			end
			
			if counter > 0 then
					outputChatBox ( "Voçê esta no Vehicle", 255, 255, 255, true )
			else
				outputChatBox ( "Voçê Nao entrou no veiculo a tempo mission failed", 255, 255, 255, true )
				triggerServerEvent("delVeh6",localPlayer)
			end
			counter = 0
		
		end, 15000, 1, client )

 

Esta é a parte no lado client que eu uso pra, dar 2 min fora do veiculo se não mission failed, eu poderia usar a função entrar6 para ativar a função de cima.

Eu tentei de uma fora tipo usar counter = counter +1 a cada vez que ele entrar no veiculo, mas não funcionou deve ser devido estar dentro de um timer, alguem poderia me dizer como fazer ? OBG !

		function sair6 () 
			if source == veh6 then 
				if isTimer (timerVeh[source]) then 
					resetTimer (timerVeh[source]) 
				else 
					timerVeh[source] = setTimer (function () 
						outputChatBox("Voçê ficou mais de 2 min fora do Veiculo, missão failed")
						triggerServerEvent("timerDestroyVeh6",localPlayer)
					end, 60000, 1)
				end
			end
		end
		addEventHandler ("onClientVehicleExit", getRootElement(), sair6)
		
		function entrar6 ()
			if isTimer (timerVeh[source]) then
				killTimer (timerVeh[source]) 
			end
		end
		addEventHandler ("onClientVehicleEnter", getRootElement(), entrar6)

 

Edited by kevincouto6
Link to comment
  • Other Languages Moderators
1 hour ago, kevincouto6 said:

exite alguma forma de eu fazer que assim que ele entre no veiculo inicie

Adicione uma função com o evento onVehicleEnter, e nessa função você verifica o veículo. Se for o veículo certo, então cancela o timer da verificação e inicia.

E pare de usar Ç na palavra você.

Edited by Lord Henry
Erro ortográfico
  • Haha 1
Link to comment
  • Moderators

Um erro no lado server do meu último código foi o uso do evento "onClientVehicleExplode".

Agora sobre o seu código:

10 hours ago, kevincouto6 said:

Me baseando no que voçê me enviou fiz isso 

Só faltou entender o porque eu usei o timer e o evento do veículo no lado server. Parece que você só olhou meu código mas fez tudo do seu jeito talvez pra evitar de reescrever parte do seu código. Passe isso pro lado server.

4 hours ago, kevincouto6 said:

tentei fazer dentro da função mais não esta funcionando, poderia me mostrar como ?

Mostre seu código, vai ser bem mais fácil. Ele te "mostrar" e você copiar e testar não vai resolver nada e você também não vai aprender nada.

Link to comment
  • Moderators

Sim, o timer é no lado server e esses eventos também:

"onVehicleExplode"
"onVehicleExit"
"onVehicleEnter"
"onPlayerWasted"

Faça dentro desse código que eu postei:

On 17/12/2018 at 23:41, DNL291 said:

 


local veh6 = {}

function inicio6 ( vx, vy, vz, vrot )
	if client ~= source then return end -- cheater detected!

	if isElement (veh6[client]) then 
		destroyElement (veh6[client])
	end
	
	setElementData( client, "Trabalho", true, false ) -- seta o jogador no element-data "Trabalho"; sinc com o client desativada
	
	veh6[client] = createVehicle ( 401, vx, vy, vz, 0, 0, vrot )
	outputChatBox ("#ffff00Drive the vehicle to the checkpoint. Note: You cannot leave the car during the mission.", client, 0, 0, 0, true)
	
	local counter = 0
	setTimer( function(p)
		if not ( isElement( veh6[p] ) ) then return end
		
		--[[ Acho que aqui o correto é verificar se quem está no veículo 
			é o jogador que tá no trabalho;
			Então seria assim:
			if getVehicleController(veh6[p]) == p then
				outputChatBox ( "Voçê esta no Vehicle", p, 255, 255, 255, true )
			else
				[....]
		]]
		
		for seat, player in pairs (getVehicleOccupants(veh6[p])) do
			counter = counter + 1
		end

		if counter > 0 then
			outputChatBox ( "Voçê esta no Vehicle", p, 255, 255, 255, true )
		else
			outputChatBox ( "Voçê Nao entrou no veiculo a tempo mission failed", p, 255, 255, 255, true )
			destroyElement (veh6[p])
			veh6[p] = nil
		end
		counter = 0
	end, 1000, 1, client )
	
	local player = client
	addEventHandler ( "onVehicleExplode", veh6[player], function ()
		destroyElement (source)
		veh6[player] = nil
		takePlayerMoney ( player, 5000 )
		outputChatBox("Mission failed, your veh6icle blew up.", player , 255, 0, 0)
	end)
	
end
addEvent ("iniciaJob6", true) 
addEventHandler ("iniciaJob6", getRootElement(), inicio6)

 

Tente fazer e mostre aqui o código. No setTimer, use este no lugar:

		setTimer( function(p)
	
			if not ( isElement( veh6[p] ) ) then return end
		
        		if getVehicleController( veh6[p] ) ~= p then
				outputChatBox ( "Voçê Nao entrou no veiculo a tempo mission failed", p, 255, 255, 255, true )
				destroyElement ( veh6[p] )
				veh6[p] = nil
			end
		
		end, 5000, 1, client )

Te recomendo também adicionar ele numa tabela do jogador já que o evento onVehicleExit terá um resetTimer.

Link to comment

Olá, no começo o script esta, no lado server, então voçê pediu para min pasar pra client para evitar bugs, ou talvez eu tenha entendido errado então pesso desculpa, okay eu vou passa-lo pro lado server e quando pronto eu add aqui para ver se esta tudo correto.

 

Edited by kevincouto6
Link to comment

@DNL291  Aqui esta 

server-side

local veh6 = {}
function inicio6 ( vx, vy, vz, vrot )
	if client ~= source then return end -- cheater detected!
	if isElement (veh6[client]) then 
		destroyElement (veh6[client])
	end
	
	setElementData( client, "Trabalho", true, false ) -- seta o jogador no element-data "Trabalho"; sinc com o client desativada
	
	veh6[client] = createVehicle ( 401, vx, vy, vz, 0, 0, vrot )
	outputChatBox ("#ffff00Drive the vehicle to the checkpoint. Note: You cannot leave the car during the mission.", client, 0, 0, 0, true)
	
		setTimer( function(p)
		
		if not ( isElement( veh6[p] ) ) then return end
		
    	if getVehicleController( veh6[p] ) ~= p then
			outputChatBox ( "Voçê Nao entrou no veiculo a tempo mission failed", p, 255, 255, 255, true )
			destroyElement ( veh6[p] )
			veh6[p] = nil
		end

		end, 5000, 1, client )
	
		local player = client
		addEventHandler ( "onVehicleExplode", veh6[player], function ()
			destroyElement (source)
			veh6[player] = nil
			takePlayerMoney ( player, 5000 )
			outputChatBox("Mission failed, your veh6icle blew up.", player , 255, 0, 0)
		end)
	

		function playerDead6()
			if veh6[client] and isElement(veh6[client]) then
				outputChatBox ( "Voçê Nao entrou no veiculo a tempo mission failed", client, 255, 255, 255, true )
				destroyElement (veh6[client])
			else
			end
		end
		addEventHandler ( "onPlayerWasted", getRootElement(), playerDead6) 
		
		timerVeh6 = {}

		function sair6 (thePlayer) --If you leave the vehicle for more than 1 min and do not return then the vehicle will disappear and the mission will failled--
			if source == veh6[thePlayer] then 
				if isTimer (timerVeh6[source]) then 
					resetTimer (timerVeh6[source]) 
				else 
					timerVeh6[source] = setTimer (function () 
						destroyElement(veh6[thePlayer])
						veh6[thePlayer] = nil
						triggerClientEvent (thePlayer, "failPlayerLeave5", thePlayer) 
					end, 5000, 1)
				end
			end
		end
		addEventHandler ("onVehicleExit", getRootElement(), sair6)

		function entrar6 (thePlayer)
			if isTimer (timerVeh6[source]) then 
				killTimer (timerVeh6[source]) 
			end
		end
		addEventHandler ("onVehicleEnter", getRootElement(), entrar6)
		
	addEvent( "completedMisionVeh6", true )
	addEventHandler( "completedMisionVeh6", getRootElement(),
	function()
		if source and isElement(veh6[client]) then
			destroyElement (veh6[client])
			veh6[client] = nil
		end
	end
	)
end
addEvent ("iniciaJob6", true) 
addEventHandler ("iniciaJob6", getRootElement(), inicio6)

mission.client.lua

local localitionveh6 = {
	[1] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
	[2] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
	[3] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
	[4] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
	[5] = {401, 213.33366, 1871.35400, 13.14063, 0, 0, 270},
}
local i = 1 

function createPlayerLocation6()
	local vx ,vy, vz, vrot = localitionveh6[ i ][ 2 ], localitionveh6[ i ][ 3 ], localitionveh6[ i ][ 4 ], localitionveh6[ i ][ 7 ]
	i = i + 1
	if i > #localitionveh6 then 
		i = 1
	end
	triggerServerEvent( "iniciaJob6", localPlayer, vx, vy, vz, vrot )
	
	Mfim6 = createMarker (213.00009, 1914.55029, 17.64063 -1, "cylinder", 2, 0 ,255 ,0, 255)
	Bfim6 = createBlipAttachedTo ( Mfim6, 19 )
end

function vehiclePartsMission6 ( veh6 )
		
		function finalmission6 ()
			if veh6 and isElement(veh6) then
				outputChatBox("Mission Completed")
				destroyElement( Mfim6 )
				destroyElement( Bfim6 )
				triggerServerEvent("completedMisionVeh6",localPlayer)
			else
			end
		end
		addEventHandler("onClientMarkerHit",Mfim6 ,finalmission6)
end
addEvent ("partesMissionSix", true) 
addEventHandler ("partesMissionSix", getRootElement(), vehiclePartsMission

GuiMission.lua

  

    elseif (guiGridListGetSelectedItem(ListMissions) == 5) then
        outputDebugString("6 was selected")
        createPlayerLocation6 ()
        guiSetVisible (WinMission, me)
        showCursor (me)
            for wnd, id in pairs(elementos.window) do
                guiSetVisible (wnd, false)
            end
      end

 

Link to comment
  • Moderators

Esqueceu de adicionar o timer do começo dentro da tabela timerVeh6. De qualquer forma eu editei o código server-side aqui que tinha alguns erros, tente:


local veh6 = {}
local timerVeh6 = {}

function inicio6 ( vx, vy, vz, vrot )
	if client ~= source or not (vrot) then return end -- cheater detected!
	if isElement (veh6[client]) then 
		destroyElement (veh6[client])
	end
	
	setElementData( client, "Trabalho", true, false ) -- seta o jogador no element-data "Trabalho"; sinc com o client desativada
	
	veh6[client] = createVehicle ( 401, vx, vy, vz, 0, 0, vrot )
	outputChatBox ("#ffff00Drive the vehicle to the checkpoint. Note: You cannot leave the car during the mission.", client, 0, 0, 0, true)
	
	timerVeh6[client] = setTimer( addEndMissionTimer, 5000, 1,  client )
	
	local player = client
	addEventHandler ( "onVehicleExplode", veh6[player], function ()
		destroyElement (source)
		veh6[player] = nil
		takePlayerMoney ( player, 5000 )
		setElementData( player, "Trabalho", nil, false )
		outputChatBox("Mission failed, your veh6icle blew up.", player , 255, 0, 0)
	end)
	
	function entrar6 (thePlayer)
		if isTimer (timerVeh6[thePlayer]) then 
			killTimer (timerVeh6[thePlayer]) 
		end
	end
	addEventHandler ("onVehicleEnter", veh6[client], entrar6)
end
addEvent ("iniciaJob6", true) 
addEventHandler ("iniciaJob6", getRootElement(), inicio6)

addEvent( "completedMisionVeh6", true )
addEventHandler( "completedMisionVeh6", getRootElement(),
	function()
		if client and isElement(veh6[client]) then
			destroyElement (veh6[client])
			veh6[client] = nil
			setElementData( client, "Trabalho", nil, false )
		end
	end
)

function playerDead6()
	if veh6[source] then
		outputChatBox ( "Missão falhou: Você morreu!", source, 255, 255, 255, true )
		destroyElement (veh6[source])
		veh6[source] = nil
		setElementData( source, "Trabalho", nil, false )
	end
end
addEventHandler ( "onPlayerWasted", getRootElement(), playerDead6)

function sair6 (thePlayer) --If you leave the vehicle for more than 1 min and do not return then the vehicle will disappear and the mission will failled--
	if source == veh6[thePlayer] then 
		if isTimer (timerVeh6[thePlayer]) then 
			resetTimer (timerVeh6[thePlayer]) 
		else 
			timerVeh6[thePlayer] = setTimer( addEndMissionTimer, 5000, 1,  thePlayer )
		end
	end
end
addEventHandler ("onVehicleExit", getRootElement(), sair6)

function addEndMissionTimer( player )
	if player then
		if not ( isElement( veh6[player] ) ) then return end
		
		if getVehicleController( veh6[player] ) ~= player then
			outputChatBox ( "Voçê Nao entrou no veiculo a tempo mission failed", player, 255, 255, 255, true )
			destroyElement ( veh6[player] )
			veh6[player] = nil
			setElementData( player, "Trabalho", nil, false )
			triggerClientEvent (player, "failPlayerLeave5", player) 
		end
	end
end

 

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