Jump to content

[HELP] Why not working onMarkerHit event?


Tokio

Recommended Posts

function ccv (thePlayer)
local accountname = getAccountName (getPlayerAccount(thePlayer))
	if isObjectInACLGroup ( "user." .. accountname, aclGetGroup ( "Admin" ) ) then
		setTimer(function()
		ve1 = createVehicle ( 535, -2220.98706, -129.69173, 35.32031 )
		ma1 = createMarker ( -2221.09668, -129.61031, 33.88103, "cylinder", 7.5, 255, 255, 0, 5 )
		end, 1000, 1)
	end
end
addCommandHandler("ccvp", ccv)

function marker1()
			destroyElement(ve1)
			destroyElement(ma1)
end
addEventHandler( "onMarkerHit", ma1, marker1)

when i walk into the marker, nothing happens :S 

Link to comment
5 minutes ago, Randomly said:

It may be because addEventHandler runs when the script starts but the marker is not existing at that time. I'd put the addEventHandler in the function after the creation of the vehicle and the marker and give it a try. 

does not working :S 

Link to comment
  • Moderators

You can't attach an addEventHandler to an element that doesn't exist yet.(it exist after the addCommandHandler has been executed.

Feel free to apply this tutorial: (because a parent element can be created and attached before the children are created)

 

Link to comment
On 11/11/2017 at 07:35, 50cent said:

function ccv (thePlayer)
local accountname = getAccountName (getPlayerAccount(thePlayer))
	if isObjectInACLGroup ( "user." .. accountname, aclGetGroup ( "Admin" ) ) then
		setTimer(function()
		ve1 = createVehicle ( 535, -2220.98706, -129.69173, 35.32031 )
		ma1 = createMarker ( -2221.09668, -129.61031, 33.88103, "cylinder", 7.5, 255, 255, 0, 5 )
		end, 1000, 1)
	end
end
addCommandHandler("ccvp", ccv)

function marker1()
			destroyElement(ve1)
			destroyElement(ma1)
end
addEventHandler( "onMarkerHit", ma1, marker1)

when i walk into the marker, nothing happens :S 

function ccv (thePlayer)
local accountname = getAccountName (getPlayerAccount(thePlayer))
	if isObjectInACLGroup ( "user." .. accountname, aclGetGroup ( "Admin" ) ) then
		setTimer(function()
		ve1 = createVehicle ( 535, -2220.98706, -129.69173, 35.32031 )
		ma1 = createMarker ( -2221.09668, -129.61031, 33.88103, "cylinder", 7.5, 255, 255, 0, 5 )
		addEventHandler( "onMarkerHit", ma1, marker1)
		end, 1000, 1)
	end
end
addCommandHandler("ccvp", ccv)

function marker1( hitElement )
	if(getElementType(hitElement) == "player") then
		if isElement(ve1) then
			destroyElement(ve1)
		end
		if isElement(ma1) then
			destroyElement(ma1)
		end	
	end	
end

try this.

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