Bierbuikje Posted September 4, 2016 Posted September 4, 2016 (edited) Hello, recently I've picked up MTA map editing again with the lua scripting that comes with it. Right now I'm creating a race and in this race I want to teleport the player to a location as soon as it hits a previously created marker. For simplification and testing purposes I changed it so that the player will teleport when it hits any marker on the map. But when testing the map it doesn't work. When I enter a marker it doesn't teleport to the specified location. I tried various, for example changing the 'player' variable to other names, but I can't get it to work. I suppose I have missed something obvious. This is the code: function resourceStart() nep1 = createMarker(1450, 1250, 10, "checkpoint", 10, 0, 0, 255, 255) nep2 = createMarker(1450, 1450, 10, "checkpoint", 10, 0, 0, 255, 255) end function MarkerHit() setElementPosition(player, 1500, 1250, 10) end addEventHandler("onClientMarkerHit",getRootElement(),MarkerHit) addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),resourceStart) Does anyone know what I have missed? Thanks in advance! Bierbuikje Edited September 4, 2016 by Bierbuikje
Walid Posted September 4, 2016 Posted September 4, 2016 function MarkerHit(player) -- Added player here i think it's better if you put the whole code server side.
darkdreamingdan Posted September 5, 2016 Posted September 5, 2016 I wouldn't set it serverside, as the hit detection is slow. If it's for race, you probably need to set the player's vehicle position, and not the player himself. Use getPedOccupiedVehicle.
Bierbuikje Posted September 5, 2016 Author Posted September 5, 2016 Thanks to both of you! I needed both adjustments to make the script working.
aka Blue Posted September 5, 2016 Posted September 5, 2016 Optimized and i think should work local markers = { {1450, 1250, 10, "checkpoint", 10, 0, 0, 255, 255}, {1450, 1450, 10, "checkpoint", 10, 0, 0, 255, 255}, } local markers = { } addEventHandler( "onClientResourceStart", resourceRoot, function( ) for i=1, #markers do local v = markers[i] local marker = createMarker(v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9]) markers[marker] = marker addEventHandler( "onClientMarkerHit", getRootElement( ), markerHit ) end end ) function markerHit( player ) local vehicle = getPedOccupiedVehicle( player ) if vehicle then -- If is player in vehicle setElementPosition(player, 1500, 1250, 10) end end
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now