Jump to content

Teleport player function


Bierbuikje

Recommended Posts

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 by Bierbuikje
Link to comment

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

 

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