Jump to content

Ajuda aki


Recommended Posts

Olá pessoal, preciso de ajuda nesta função pois quando  o vehicle explode não consigo que de Mission failled, Alguem ai pode me ajudar 

--mission 4--

Mfim4 = createMarker ( -1875.0139160156, -1474.5141601563, 1 -1, "ring", 4, 0 ,255 ,0, 255)

Bfim4 = createBlipAttachedTo ( Mfim4, 20 )
setElementVisibleTo ( Bfim4, root, false )

veh4 = {}

function inicio4 ()
	if isElement (veh4[client]) then -- Client = localPlayer, somente neste caso.
		destroyElement (veh4[client])
		veh4[client] = nil
	end
	Trabalho = true
	veh4[client] = createVehicle (493, -615.03826904297, 1807.0825195313, 0.19021162390709, 0, 0, 76.391845703125)
	setElementVisibleTo ( Bfim4, client, true )
	warpPedIntoVehicle (client, veh4[client])
	outputChatBox ("#ffff00Take this Flag Card without leaving the vehicle!", client, 0, 0, 0, true)
end
addEvent ("iniciaJob4", true) -- Cria o evento "iniciaJob e permite que ele seja chamado pelo client.
addEventHandler ("iniciaJob4", getRootElement(), inicio4) -- Executa essa função quando o evento "iniciaJob" for chamado.

function fim4 (source)
	if veh4[source] and isElement(veh4[source]) then
		destroyElement (veh4[source])
		givePlayerMoney(source,200000)
		setElementVisibleTo ( Bfim4, source, false )
		outputChatBox("#00ff00Congratulations, you completed the mission, get your reward. $10.000!",source,0,0,0,true) 
	else
	end
end
addEventHandler("onMarkerHit",Mfim4 ,fim4)

function sair4 (source)
	if (veh4[source]) and isElement(veh4[source]) then
		destroyElement (veh4[source])
		setElementVisibleTo ( Bfim4, source, false )
		outputChatBox("#ff0000On leaving the vehicle, mission failed", source ,0,0,0,true)
	else
	end
end
addEventHandler ( "onVehicleExit", getRootElement(), sair4 )

function blowveh4 ()
	if (veh4[source]) and isElement(veh4[source]) then
		destroyElement (veh4[source])
		setElementVisibleTo ( Bfim4, source, false )
		outputChatBox("#ff0000Mission failled, your vehicle blow", root ,0,0,0,true)
	else
	end
end
addEventHandler ( "onVehicleExplode", getRootElement(), blowveh4 )

 

Link to comment
veh4[client] = createVehicle (493, -615.03826904297, 1807.0825195313, 0.19021162390709, 0, 0, 76.391845703125)
addEventHandler ( "onVehicleExplode", veh4[client],
function ()
		destroyElement (source)
		setElementVisibleTo ( Bfim4, source, false )
		outputChatBox("#ff0000Mission failled, your vehicle blow", root ,0,0,0,true)
end
)

 

Link to comment
  • Other Languages Moderators

Bom, o motivo do seu onVehicleExplode não funcionar é porque neste evento, source não é o jogador e sim o veículo.

Você criou o veículo como sendo veh4[client], ou seja, client = jogador. Mas client só é existe em funções que são chamadas por um script client-side usando triggerServerEvent.

Nas demais funções, você usou veh4[source] com o objetivo de source = jogador. Mas nas demais funções o source por padrão não é um jogador pois tudo depende do evento que está ativando a função.

No evento onMarkerHit, ele funcionou pois você declarou source no primeiro parâmetro da função. Se vc não tivesse declarado, source seria o marker que foi colidido.
No evento onVehicleExit, ele funcionou pois você declarou source no primeiro parâmetro da função. Se vc não tivesse declarado, source seria o veículo que o jogador saiu.
No evento onVehicleExplode, source = veículo que explodiu. Não adiantaria declarar source na função pois este evento não possui parâmetros.

A solução mais fácil, seria você colocar a função do onVehicleExplode dentro da função onde existe o client. No caso, dentro da função inicio4.

--mission 4--

Mfim4 = createMarker ( -1875.0139160156, -1474.5141601563, 1 -1, "ring", 4, 0 ,255 ,0, 255)

Bfim4 = createBlipAttachedTo ( Mfim4, 20 )
setElementVisibleTo ( Bfim4, root, false )

veh4 = {}

function inicio4 ()
	if isElement (veh4[client]) then -- Client = localPlayer, somente neste caso.
		destroyElement (veh4[client])
		veh4[client] = nil
	end
	Trabalho = true
	veh4[client] = createVehicle (493, -615.03826904297, 1807.0825195313, 0.19021162390709, 0, 0, 76.391845703125)
	setElementVisibleTo ( Bfim4, client, true )
	warpPedIntoVehicle (client, veh4[client])
	outputChatBox ("Take this Flag Card without leaving the vehicle!", client, 255, 255, 0)
	
	addEventHandler ( "onVehicleExplode", veh4[client], function ()
		if (veh4[client]) and isElement(veh4[client]) then
			destroyElement (veh4[client])
			setElementVisibleTo ( Bfim4, client, false )
			outputChatBox("Mission failled, your vehicle blow.", client , 255, 0, 0)
		end
	end)
end
addEvent ("iniciaJob4", true)
addEventHandler ("iniciaJob4", getRootElement(), inicio4)

 

Edited by Lord Henry
Link to comment
1 hour ago, Lord Henry said:

 

Olá, eu peguei os 2 e fiz assim funcionou porem aconteceu um erro apenas no Bip4 tentei trocar, porem n funciona, sabe me dizer oque esta acontecendo

WARNING: Mission/server.lua:118:Bad argument @ 'setElementVisibleTo' [Expected element at argument 2]

function inicio4 ()
	if isElement (veh4[client]) then -- Client = localPlayer, somente neste caso.
		destroyElement (veh4[client])
		veh4[client] = nil
	end
	Trabalho = true
	veh4[client] = createVehicle (493, -615.03826904297, 1807.0825195313, 0.19021162390709, 0, 0, 76.391845703125)
	setElementVisibleTo ( Bfim4, client, true )
	warpPedIntoVehicle (client, veh4[client])
	outputChatBox ("Take this Flag Card without leaving the vehicle!", client, 255, 255, 0)
	
	addEventHandler ( "onVehicleExplode", veh4[client], function ()
			destroyElement (source)
			setElementVisibleTo ( Bfim4, source, false )
			outputChatBox("Mission failled, your vehicle blow.", client , 255, 0, 0)
	end)
end
addEvent ("iniciaJob4", true)
addEventHandler ("iniciaJob4", getRootElement(), inicio4)

 

Link to comment
  • Other Languages Moderators
35 minutes ago, kevincouto6 said:

Olá, eu peguei os 2 e fiz assim funcionou porem aconteceu um erro apenas no Bip4 tentei trocar, porem n funciona, sabe me dizer oque esta acontecendo

WARNING: Mission/server.lua:118:Bad argument @ 'setElementVisibleTo' [Expected element at argument 2]

Essa sua função não foi a que eu mandei. Use essa:

function inicio4 ()
	if isElement (veh4[client]) then -- Client = localPlayer, somente neste caso.
		destroyElement (veh4[client])
		veh4[client] = nil
	end
	Trabalho = true
	veh4[client] = createVehicle (493, -615.03826904297, 1807.0825195313, 0.19021162390709, 0, 0, 76.391845703125)
	setElementVisibleTo ( Bfim4, client, true )
	warpPedIntoVehicle (client, veh4[client])
	outputChatBox ("Take this Flag Card without leaving the vehicle!", client, 255, 255, 0)
	
	addEventHandler ( "onVehicleExplode", veh4[client], function ()
		if (veh4[client]) and isElement(veh4[client]) then
			destroyElement (veh4[client])
			setElementVisibleTo ( Bfim4, client, false )
			outputChatBox("Mission failled, your vehicle blow.", client , 255, 0, 0)
		end
	end)
end
addEvent ("iniciaJob4", true)
addEventHandler ("iniciaJob4", getRootElement(), inicio4)

Na sua função, setElementVisibleTo vai falhar se o veículo (source) estiver vazio.

Edited by Lord Henry
Link to comment
21 minutes ago, Lord Henry said:

 

Porem deste formato não funciona eu testei e a função  "onVehicleExplode" ela não funciona, porem no debug nao aparece nenhum erro.

quendo removo " if (veh4[client]) and isElement(veh4[client]) then" ela funciona, esta havendo algum bug nesta parte 
 

Link to comment

Provavelmente por causa do 'client' que só está disponível no escopo da função inicio4.

Algumas formas de obter o dono do veículo:

usar getElementSyncer(source) dentro do "onVehicleExplode", criar uma variável "local player = client" e usar a variável player no evento ou chamar uma função passando o jogador e adicionar o evento fora (o que daria mais trabalho).

Link to comment
9 hours ago, DNL291 said:

Provavelmente por causa do 'client' que só está disponível no escopo da função inicio4.

Algumas formas de obter o dono do veículo:

usar getElementSyncer(source) dentro do "onVehicleExplode", criar uma variável "local player = client" e usar a variável player no evento ou chamar uma função passando o jogador e adicionar o evento fora (o que daria mais trabalho).

Eu tentei porem continua não funcionando 

--mission 4--
Mfim4 = createMarker ( -1875.0139160156, -1474.5141601563, 1 -1, "ring", 4, 0 ,255 ,0, 255)

Bfim4 = createBlipAttachedTo ( Mfim4, 20 )
setElementVisibleTo ( Bfim4, root, false )

veh4 = {}

local player = client

function inicio4 ()
	if isElement (veh4[client]) then -- Client = localPlayer, somente neste caso.
		destroyElement (veh4[client])
		veh4[client] = nil
	end
	Trabalho = true
	veh4[client] = createVehicle (493, -615.03826904297, 1807.0825195313, 0.19021162390709, 0, 0, 76.391845703125)
	setElementVisibleTo ( Bfim4, client, true )
	warpPedIntoVehicle (client, veh4[client])
	outputChatBox ("Take this Flag Card without leaving the vehicle!", client, 255, 255, 0)
	
	addEventHandler ( "onVehicleExplode", veh4[client], function ()
		if (veh4[client]) and isElement(veh4[client]) then
			getElementSyncer(source) 
			destroyElement (source)
			setElementVisibleTo ( Bfim4, player, false )
			outputChatBox("Mission failled, your vehicle blow.", player , 255, 0, 0)
		end
	end)
end
addEvent ("iniciaJob4", true)
addEventHandler ("iniciaJob4", getRootElement(), inicio4)

 

Link to comment
--mission 4--
local Mfim4 = createMarker ( -1875.0139160156, -1474.5141601563, 1 -1, "ring", 4, 0 ,255 ,0, 255)

local Bfim4 = createBlipAttachedTo ( Mfim4, 20 )
setElementVisibleTo ( Bfim4, root, false )

local veh4 = {}

function inicio4 ()
	if isElement (veh4[client]) then -- Client = localPlayer, somente neste caso.
		destroyElement (veh4[client])
		veh4[client] = nil
	end
	Trabalho = true
	veh4[client] = createVehicle (493, -615.03826904297, 1807.0825195313, 0.19021162390709, 0, 0, 76.391845703125)
	setElementVisibleTo ( Bfim4, client, true )
	warpPedIntoVehicle (client, veh4[client])
	outputChatBox ("Take this Flag Card without leaving the vehicle!", client, 255, 255, 0)
	
	local player = client
	addEventHandler ( "onVehicleExplode", veh4[client], function ()
		if (veh4[player]) and isElement(veh4[player]) then
			destroyElement (source)
			setElementVisibleTo ( Bfim4, player, false )
			outputChatBox("Mission failled, your vehicle blow.", player , 255, 0, 0)
		end
	end)
end
addEvent ("iniciaJob4", true)
addEventHandler ("iniciaJob4", getRootElement(), inicio4)

 

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...