ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Shared functions
  3. setElementPosition

Function

setElementPosition

Moves an element to the given place. On the server it works for any element. On the client it moves your own character (up to 50 m it is a plain move in the same frame and getElementPosition returns the new place right away, so it can be called every frame, e.g. for noclip; farther it is a teleport that loads the area), as well as client objects, sounds and collision shapes. An object moved every frame in onClientPreRender is drawn in its new place in the same frame.

Syntax

bool setElementPosition(element theElement, float x, float y, float z)

Arguments

theElementelement
The element.
xfloat
X position.
yfloat
Y position.
zfloat
Z position.

Differences from MTA:SA

  • These MTA:SA arguments are not here: bool warp = true

In MTA:SA

setElementPosition(element theElement, float x, float y, float z, bool warp = true)

Returns

true on success.

Example

A command teleporting to another player.

addCommandHandler("tp", function(player, cmd, name)
    local target = name and getPlayerFromName(name)
    if not target then
        outputChatBox("Nie ma takiego gracza.", player, 255, 0, 0)
        return
    end
    local x, y, z = getElementPosition(target)
    setElementInterior(player, getElementInterior(target))
    setElementDimension(player, getElementDimension(target))
    setElementPosition(player, x + 1, y, z)
end)

See also