setElementPosition | Multi Theft Auto: Wiki Skip to content

setElementPosition

Client-side
Server-side
Shared

Pair: getElementPosition

This function sets the position of an element to the specified coordinates.

Do not use this function to spawn a player. It will cause problems with other functions like warpPedIntoVehicle. Use spawnPlayer instead.

If you want to put a vehicle or player out of the water or simulate the position-resetting behaviour if CJ goes below the ground too far, then you need to retrieve a recommended coordinate on ground to place the element at. Take a look at this MTA forums post for steps in the right direction.

OOP Syntax Help! I don't understand this!

  • Method: element:setPosition(...)
  • Variable: .position

Syntax

bool setElementPosition ( element theElement, float x, float y, float z, [ bool warp = true ] )
Required Arguments
  • theElement: A valid element to set the position.
  • x: The x coordinate of the destination.
  • y: The y coordinate of the destination.
  • z: The z coordinate of the destination.
Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.

  • warp (default: true): teleports players, resetting any animations they were doing. Setting this to false preserves the current animation.

Returns

  • bool: result

Returns true if the function was successful, false otherwise.

Code Examples

client

This example teleports the player to map center using /zero command. (aka. origin point)

function teleportPlayerToMapCenter()
-- teleport player to 0,0,0 coordinates (map origin/center)
setElementPosition(localPlayer, 0, 0, 0 + 3); -- add +3 to z coordinate to not fall below map!
end
addCommandHandler("zero", teleportPlayerToMapCenter);

See Also

Element Functions