setElementPosition
Client-side
Server-side
Shared
Pair: getElementPosition
Manual Review Required
Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.
This function sets the position of an element to the specified coordinates.
Caution
Do not use this function to spawn a player . It will cause problems with other functions like warpPedIntoVehicle . Use spawnPlayer instead.
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 be moved.
- 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: value
Returns true if the function was successful, false otherwise.
Code Examples
shared
This example lets admins teleport 5 random players to themselves
function randomPlayersToLocation(p) if not isPlayerStaff(p) then return end
local playersOnline = getElementsByType("player") local amount = #playersOnline
if amount == 0 then return end
for index = 1,(amount > 5 and 5 or amount) do local player = playersOnline[index] setElementPosition(player, getElementPosition(p)) endendaddCommandHandler("randomtp", randomPlayersToLocation)addCommandHandler("playershere", randomPlayersToLocation)
-- Utility functionlocal staffACLs = { aclGetGroup("Admin"), aclGetGroup("Moderator")}
function isPlayerStaff(p) if isElement(p) and getElementType(p) == "player" and not isGuestAccount(getPlayerAccount(p)) then local object = getAccountName(getPlayerAccount(p))
for _, group in ipairs(staffACLs) do if isObjectInACLGroup("user." .. object, group) then return true end end end return falseendIssues
| ID | Description |
|---|---|
| 539 | Changing player position when he/she has a jetpack will remove the jetpack and bug when skin is changed |
| 529 | Player falls from his bike when its teleported by setElementPosition |
See Also
Element Functions
- addElementDataSubscriber
- attachElements
- clearElementVisibleTo
- cloneElement
- createElement
- destroyElement
- detachElements
- getAllElementData
- getAttachedElements
- getElementAlpha
- getElementAngularVelocity
- getElementAttachedOffsets
- getElementAttachedTo
- getElementBonePosition
- getElementBoneQuaternion
- getElementBoneRotation
- getElementBoundingBox
- getElementByID
- getElementByIndex
- getElementChild
- getElementChildren
- getElementChildrenCount
- getElementCollisionsEnabled
- getElementColShape
- getElementData
- getElementDimension
- getElementDistanceFromCentreOfMassToBaseOfModel
- getElementHealth
- getElementID
- getElementInterior
- getElementLighting
- getElementModel
- getElementParent
- getElementPosition
- getElementRadius
- getElementRotation
- getElementsByType
- getElementsWithinColShape
- getElementsWithinRange
- getElementSyncer
- getElementType
- getElementVelocity
- getElementZoneName
- getLowLODElement
- getRootElement
- hasElementData
- hasElementDataSubscriber
- isElement
- isElementAttached
- isElementCallPropagationEnabled
- isElementCollidableWith
- isElementDoubleSided
- isElementFrozen
- isElementInWater
- isElementLocal
- isElementLowLOD
- isElementOnFire
- isElementOnScreen
- isElementStreamable
- isElementStreamedIn
- isElementSyncer
- isElementVisibleTo
- isElementWaitingForGroundToLoad
- isElementWithinColShape
- isElementWithinMarker
- removeElementData
- removeElementDataSubscriber
- setElementAlpha
- setElementAngularVelocity
- setElementAttachedOffsets
- setElementBonePosition
- setElementBoneQuaternion
- setElementBoneRotation
- setElementCallPropagationEnabled
- setElementCollidableWith
- setElementCollisionsEnabled
- setElementData
- setElementDimension
- setElementDoubleSided
- setElementFrozen
- setElementHealth
- setElementID
- setElementInterior
- setElementLighting
- setElementModel
- setElementOnFire
- setElementParent
- setElementPosition
- setElementRotation
- setElementStreamable
- setElementSyncer
- setElementVelocity
- setElementVisibleTo
- setLowLODElement
- updateElementRpHAnim
Element Events
- onClientElementColShapeHit
- onClientElementColShapeLeave
- onClientElementDataChange
- onClientElementDestroy
- onClientElementDimensionChange
- onClientElementInteriorChange
- onClientElementModelChange
- onClientElementStreamIn
- onClientElementStreamOut
- onElementClicked
- onElementColShapeHit
- onElementColShapeLeave
- onElementDataChange
- onElementDestroy
- onElementDimensionChange
- onElementInteriorChange
- onElementModelChange
- onElementStartSync
- onElementStopSync