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