Sign in to follow this  
kevincouto6

Help Ha

Recommended Posts

Hello, I've come to ask for help because I have a problem with
"addEventHandler (" onMarkerHit ")"

From what I can understand he is not detecting the Markers, but the makers are only created when the mission is started, as a way to solve this error ?

WARNING: GUImission/server.lua:113 Bad argument @ " addEventHandler { expected element at argument 2,got nill}

 

--mission five--

cardrivepoints = 0

createMarkerLocations1 = {
	{231.41704, 1877.68689, 17.64063 -1, "cylinder", 4, 0 ,255 ,0, 255},
	{231.41704, 1877.68689, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170 },
	{231.41704, 1877.68689, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170},
	{231.41704, 1877.68689, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170 },
	{231.41704, 1877.68689, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170},
}

createMarkerLocations2 = {
	{231.85756, 1892.57666, 17.64063 -1, "cylinder", 4, 0 ,255 ,0, 255},
	{231.85756, 1892.57666, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170 },
	{231.85756, 1892.57666, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170},
	{231.85756, 1892.57666, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170 },
	{231.85756, 1892.57666, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170},
}


createMarkerLocations3 = {
	{229.22476, 1906.36658, 17.64063 -1, "cylinder", 4, 0 ,255 ,0, 255},
	{229.22476, 1906.36658, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170 },
	{229.22476, 1906.36658, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170},
	{229.22476, 1906.36658, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170 },
	{229.22476, 1906.36658, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170},
}


createMarkerLocations4 = {
	{212.10025, 1908.91870, 17.64063 -1, "cylinder", 4, 0 ,255 ,0, 255},
	{212.10025, 1908.91870, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170 },
	{212.10025, 1908.91870, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170},
	{212.10025, 1908.91870, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170 },
	{212.10025, 1908.91870, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170},
}


createMarkerLocations5 = {
	{192.29828, 1911.02271, 17.64063 -1, "cylinder", 4, 0 ,255 ,0, 255},
	{192.29828, 1911.02271, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170 },
	{192.29828, 1911.02271, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170},
	{192.29828, 1911.02271, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170 },
	{192.29828, 1911.02271, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170},
}



veh5 = {}

 -- Recomendo que evite posições decimais muito grandes. Use só até 3 casas decimais.
localitionveh55 = {
	[1] = {493, 238.55833, 1925.76343, 17.6480, 0, 0, 270},
	[2] = {493, 238.55833, 1925.76343, 17.6480, 0, 0, 270},
	[3] = {493, 238.55833, 1925.76343, 17.6480, 0, 0, 270},
	[4] = {493, 238.55833, 1925.76343, 17.6480, 0, 0, 270},
	[5] = {493, 238.55833, 1925.76343, 17.6480, 0, 0, 270},
 -- O primeiro, quinto e sexto valor das posições não estão sendo usados. Recomendo que delete-os.
}

i = 1 -- contador global

	
function inicio5 ()
	if isElement (veh5[client]) then -- Client = localPlayer, somente neste caso.
		destroyElement (veh5[client])
		veh5[client] = nil
	end
	local vx ,vy, vz, vrot = localitionveh55[ i ][ 2 ], localitionveh55[ i ][ 3 ], localitionveh55[ i ][ 4 ], localitionveh55[ i ][ 7 ]
	i = i + 1
	if i > #localitionveh55 then -- se i > 5, então:
		i = 1
	end
	Trabalho = true
	veh5[client] = createVehicle ( 433, vx, vy, vz, 0, 0, vrot )
	warpPedIntoVehicle (client, veh5[client])
	outputChatBox ("#ffff00Drive the veh5icle to the checkpoint. Note: You cannot leave the car during the mission.", client, 0, 0, 0, true)

	function createRandomMarker(table)
		local randomRow = math.random(1,#table)
		return createMarker(table[randomRow][1], table[randomRow][2], table[randomRow][3], table[randomRow][4], table[randomRow][5], table[randomRow][6], table[randomRow][7], table[randomRow][8], table[randomRow][9])
	end

	local markerElement1 = createRandomMarker(createMarkerLocations1) 
	local markerElement2 = createRandomMarker(createMarkerLocations2) 
	local markerElement3 = createRandomMarker(createMarkerLocations3) 
	local markerElement4 = createRandomMarker(createMarkerLocations4) 
	local markerElement5 = createRandomMarker(createMarkerLocations5)
	
		
	local player2 = client
	addEventHandler ( "onVehicleExplode", veh5[client], function ()
		if (veh5[player2]) and isElement(veh5[player2]) then
			destroyElement (source)
			takePlayerMoney ( player2, 5000 )
			outputChatBox("Mission failed, your veh5icle blew up.", player2 , 255, 0, 0)
		end
	end)
end
addEvent ("iniciaJob5", true) -- Cria o evento "iniciaJob e permite que ele seja chamado pelo client.
addEventHandler ("iniciaJob5", getRootElement(), inicio5) -- Executa essa função quando o evento "iniciaJob" for chamado.


function partfim2 (source)
	if veh5[source] and isElement(veh5[source]) then
		cardrivepoints = cardrivepoints+1
		outputChatBox("Funcionando!",source,0,0,0,true)
	else
	end
end
addEventHandler("onMarkerHit",markerElement2 ,partfim2)

function partfim3 (source)
	if veh5[source] and isElement(veh5[source]) then
		cardrivepoints = cardrivepoints+1
		outputChatBox("Funcionando!",source,0,0,0,true)
	else
	end
end
addEventHandler("onMarkerHit",markerElement3 ,partfim3)

function partfim4 (source)
	if veh5[source] and isElement(veh5[source]) then
		cardrivepoints = cardrivepoints+1
		outputChatBox("Funcionando!",source,0,0,0,true)
	else
	end
end
addEventHandler("onMarkerHit",markerElement4 ,partfim4)

function partfim5 (source)
	if veh5[source] and isElement(veh5[source]) then
		cardrivepoints = cardrivepoints+1
		outputChatBox("Funcionando!",source,0,0,0,true)
	else
	end
end
addEventHandler("onMarkerHit",markerElement5 ,partfim5)


function completed(source)
		if cardrivepoints >= 5 then 
				outputChatBox("#00ff00Mission passed. You successfully completed this task. You've received $10.000!",source,0,0,0,true)
		end
end

 

Share this post


Link to post

I simplified that. I dont know if it works but you can try it!

--mission five--

cardrivepoints = 0

markersTable = {
	{
		{231.41704, 1877.68689, 17.64063 -1, "cylinder", 4, 0 ,255 ,0, 255},
		{231.41704, 1877.68689, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170 },
		{231.41704, 1877.68689, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170},
		{231.41704, 1877.68689, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170 },
		{231.41704, 1877.68689, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170},
	},

	{
		{231.85756, 1892.57666, 17.64063 -1, "cylinder", 4, 0 ,255 ,0, 255},
		{231.85756, 1892.57666, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170 },
		{231.85756, 1892.57666, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170},
		{231.85756, 1892.57666, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170 },
		{231.85756, 1892.57666, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170},
	},


	{
		{229.22476, 1906.36658, 17.64063 -1, "cylinder", 4, 0 ,255 ,0, 255},
		{229.22476, 1906.36658, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170 },
		{229.22476, 1906.36658, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170},
		{229.22476, 1906.36658, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170 },
		{229.22476, 1906.36658, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170},
	},


	{
		{212.10025, 1908.91870, 17.64063 -1, "cylinder", 4, 0 ,255 ,0, 255},
		{212.10025, 1908.91870, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170 },
		{212.10025, 1908.91870, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170},
		{212.10025, 1908.91870, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170 },
		{212.10025, 1908.91870, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170},
	},


	{
		{192.29828, 1911.02271, 17.64063 -1, "cylinder", 4, 0 ,255 ,0, 255},
		{192.29828, 1911.02271, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170 },
		{192.29828, 1911.02271, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170},
		{192.29828, 1911.02271, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170 },
		{192.29828, 1911.02271, 17.64063 -1, "cylinder", 4, 255, 255, 0, 170},
	},
}

veh5 = {}
markers_obj = {}

 -- Recomendo que evite posições decimais muito grandes. Use só até 3 casas decimais.
localitionveh55 = {
	[1] = {493, 238.55833, 1925.76343, 17.6480, 0, 0, 270},
	[2] = {493, 238.55833, 1925.76343, 17.6480, 0, 0, 270},
	[3] = {493, 238.55833, 1925.76343, 17.6480, 0, 0, 270},
	[4] = {493, 238.55833, 1925.76343, 17.6480, 0, 0, 270},
	[5] = {493, 238.55833, 1925.76343, 17.6480, 0, 0, 270},
 -- O primeiro, quinto e sexto valor das posições não estão sendo usados. Recomendo que delete-os.
}

i = 1 -- contador global

function inicio5 ()
	if isElement (veh5[client]) then -- Client = localPlayer, somente neste caso.
		destroyElement (veh5[client])
		veh5[client] = nil
	end
	local vx ,vy, vz, vrot = localitionveh55[ i ][ 2 ], localitionveh55[ i ][ 3 ], localitionveh55[ i ][ 4 ], localitionveh55[ i ][ 7 ]
	i = i + 1
	if i > #localitionveh55 then -- se i > 5, então:
		i = 1
	end
	Trabalho = true
	veh5[client] = createVehicle ( 433, vx, vy, vz, 0, 0, vrot )
	warpPedIntoVehicle (client, veh5[client])
	outputChatBox ("#ffff00Drive the veh5icle to the checkpoint. Note: You cannot leave the car during the mission.", client, 0, 0, 0, true)

	function createAllMarkers()
		for i=1, #markersTable do 
			local v = markersTable[i]
			markers_obj[i] = createMarker( unpack(v) )
			addEventHandler( "onMarkerHit", markers_obj[i],
				function()
					if veh5[source] and isElement(veh5[source]) then
						cardrivepoints = cardrivepoints+1
						outputChatBox("Funcionando!",source,0,0,0,true)
					else
					end				
				end
			)
		end
	end
	
		
	local player2 = client
	addEventHandler ( "onVehicleExplode", veh5[client], function ()
		if (veh5[player2]) and isElement(veh5[player2]) then
			destroyElement (source)
			takePlayerMoney ( player2, 5000 )
			outputChatBox("Mission failed, your veh5icle blew up.", player2 , 255, 0, 0)
		end
	end)
end
addEvent ("iniciaJob5", true) -- Cria o evento "iniciaJob e permite que ele seja chamado pelo client.
addEventHandler ("iniciaJob5", getRootElement(), inicio5) -- Executa essa função quando o evento "iniciaJob" for chamado.


function completed(source)
		if cardrivepoints >= 5 then 
				outputChatBox("#00ff00Mission passed. You successfully completed this task. You've received $10.000!",source,0,0,0,true)
		end
end

 

Share this post


Link to post

Delete 'local' before elements. (Because is it local, you can only use in 'inicio5' function)

 

local markerElement1 = createRandomMarker(createMarkerLocations1) 
local markerElement2 = createRandomMarker(createMarkerLocations2) 
local markerElement3 = createRandomMarker(createMarkerLocations3) 
local markerElement4 = createRandomMarker(createMarkerLocations4) 
local markerElement5 = createRandomMarker(createMarkerLocations5)
  
-- TO
  
markerElement1 = createRandomMarker(createMarkerLocations1) 
markerElement2 = createRandomMarker(createMarkerLocations2) 
markerElement3 = createRandomMarker(createMarkerLocations3) 
markerElement4 = createRandomMarker(createMarkerLocations4) 
markerElement5 = createRandomMarker(createMarkerLocations5)

Share this post


Link to post

I think making a table of the markers, looping it and adding the event inside the loop is faster and a better solution because all 'onMarkerHit' do the same function. Making tons of variables makes things more difficult ;) 
 

Edited by aka Blue

Share this post


Link to post
5 hours ago, Patrick2562 said:

Delete 'local' before elements. (Because is it local, you can only use in 'inicio5' function)

 


local markerElement1 = createRandomMarker(createMarkerLocations1) local markerElement2 = createRandomMarker(createMarkerLocations2) local markerElement3 = createRandomMarker(createMarkerLocations3) local markerElement4 = createRandomMarker(createMarkerLocations4) local markerElement5 = createRandomMarker(createMarkerLocations5)  -- TO  markerElement1 = createRandomMarker(createMarkerLocations1) markerElement2 = createRandomMarker(createMarkerLocations2) markerElement3 = createRandomMarker(createMarkerLocations3) markerElement4 = createRandomMarker(createMarkerLocations4) markerElement5 = createRandomMarker(createMarkerLocations5)

I have one more question, and is it possible to create the marker just for who is doing the mission? Examples create individually marker for each player

@aka Blue @Patrick2562

Edited by kevincouto6

Share this post


Link to post
1 hour ago, kevincouto6 said:

I have one more question, and is it possible to create the marker just for who is doing the mission? Examples create individually marker for each player

@aka Blue @Patrick2562

 

setElementVisibleTo()

or createMarker 10th argument.

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.