Tokio

[HELP] Why not working onMarkerHit event?

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 

Share this post


Link to post

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. 

Share this post


Link to post
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 

Share this post


Link to post
1 minute ago, Randomly said:

Hm. Is it inside the setTimer with the creations? 

No, after the settimer

Share this post


Link to post
2 minutes ago, Randomly said:

Try it in the timer. 

does not working :/ 

Share this post


Link to post
6 minutes ago, Randomly said:

Do you use debugscript 3 in the console? Does it output sg? 

Bad argument @ addEventHandler [Expected element at argument 2, got nil]

Share this post


Link to post

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)

 

Share this post


Link to post
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.

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

  • Recently Browsing   0 members

    No registered users viewing this page.