setElementPosition
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
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!endaddCommandHandler("zero", teleportPlayerToMapCenter);
See Also
Element Functions
- attachElements
- createElement
- destroyElement
- detachElements
- getAllElementData
- getAttachedElements
- getElementAngularVelocity
- getElementAlpha
- getElementAttachedOffsets
- getElementAttachedTo
- getElementByID
- getElementByIndex
- getElementChild
- getElementChildren
- getElementChildrenCount
- getElementCollisionsEnabled
- getElementData
- getElementDimension
- getElementHealth
- getElementID
- getElementInterior
- getElementMatrix
- getElementModel
- getElementParent
- getElementPosition
- getElementRotation
- getElementType
- getElementVelocity
- getElementsByType
- getElementsWithinRange
- getLowLODElement
- getPedContactElement
- getResourceDynamicElementRoot
- getResourceRootElement
- getRootElement
- hasElementData
- isElement
- isElementAttached
- isElementCallPropagationEnabled
- isElementDoubleSided
- isElementFrozen
- isElementInWater
- isElementLowLOD
- isElementOnFire
- isElementWithinMarker
- setElementAlpha
- setElementAngularVelocity
- setElementAttachedOffsets
- setElementCallPropagationEnabled
- setElementData
- setElementCollisionsEnabled
- setElementDoubleSided
- setElementDimension
- setElementFrozen
- setElementHealth
- setElementID
- setElementInterior
- setElementModel
- setElementOnFire
- setElementParent
- setElementPosition
- setElementRotation
- setElementVelocity
- setLowLODElement
- getElementBoneMatrix
- getElementBonePosition
- getElementBoneQuaternion
- getElementBoneRotation
- getElementBoundingBox
- getElementDistanceFromCentreOfMassToBaseOfModel
- getElementLighting
- getElementRadius
- isElementCollidableWith
- isElementLocal
- isElementOnScreen
- isElementStreamable
- isElementStreamedIn
- isElementSyncer
- isElementWaitingForGroundToLoad
- setElementBoneMatrix
- setElementBonePosition
- setElementBoneRotation
- setElementBoneQuaternion
- setElementCollidableWith
- setElementLighting
- setElementStreamable
- updateElementRpHAnim
- addElementDataSubscriber
- cloneElement
- clearElementVisibleTo
- getElementSyncer
- getElementZoneName
- hasElementDataSubscriber
- isElementVisibleTo
- removeElementData
- removeElementDataSubscriber
- setElementSyncer
- setElementVisibleTo
Element Events
- onClientElementColShapeLeave
- onClientElementDestroy
- onClientElementColShapeHit
- onClientElementDataChange
- onClientElementDimensionChange
- onClientElementModelChange
- onClientElementInteriorChange
- onClientElementStreamOut
- onClientElementStreamIn
- onElementClicked
- onElementColShapeLeave
- onElementColShapeHit
- onElementDataChange
- onElementDestroy
- onElementDimensionChange
- onElementInteriorChange
- onElementModelChange
- onElementStartSync
- onElementStopSync