- Documentation
- Shared functions
- getElementPosition
Function
getElementPosition
Returns an element's position in the world: a player, vehicle, object or marker.
Syntax
float, float, float getElementPosition(element el)Arguments
elelement- The element whose position you want.
Returns
Three numbers x, y, z, or false if the element does not exist.
Example
Distance between two players in metres.
function distance(a, b)
local x1, y1, z1 = getElementPosition(a)
local x2, y2, z2 = getElementPosition(b)
return getDistanceBetweenPoints3D(x1, y1, z1, x2, y2, z2)
end
addCommandHandler("distance", function(player, _, nick)
local other = getPlayerFromName(nick or "")
if not other then return outputChatBox("No such player.", player) end
outputChatBox(("%s is %.0f m away."):format(nick, distance(player, other)), player)
end)
Notes
Good to know. You set the position with setElementPosition(el, x, y, z). Coordinates are described in Conventions.
See also
createVehicleCreates a vehicle in the world: model, position, rotation and number plate text.spawnPlayerSpawns a player at the given place: position, rotation, skin, interior and dimension.setTimerCalls a function after a given time, once, several times or forever.setElementPositionMoves 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 andgetElementPositionreturns 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 inonClientPreRenderis drawn in its new place in the same frame.