SetElementPosition: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(18 intermediate revisions by 12 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{ | {{Shared function}} | ||
This function sets the position of an element to the specified coordinates. | This function sets the position of an element to the specified coordinates. | ||
{{Warning|Do not use this function to spawn a [[player]]. It will cause problems with other functions like [[warpPedIntoVehicle]]. Use [[spawnPlayer]] instead.}} | |||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool setElementPosition ( element theElement, float x, float y, float z ) | bool setElementPosition ( element theElement, float x, float y, float z [, bool warp = true ] ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP||[[element]]:setPosition|position|getElementPosition}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
Line 13: | Line 15: | ||
*'''y:''' The y coordinate of the destination. | *'''y:''' The y coordinate of the destination. | ||
*'''z:''' The z coordinate of the destination. | *'''z:''' The z coordinate of the destination. | ||
===Optional Arguments=== | |||
*'''warp:''' teleports players, resetting any animations they were doing. Setting this to ''false'' preserves the current animation. | |||
===Returns=== | ===Returns=== | ||
Line 26: | Line 31: | ||
addCommandHandler ( "setpos", consoleSetPlayerPosition ) | addCommandHandler ( "setpos", consoleSetPlayerPosition ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | |||
<section name="Example 2" class="client" show="false"> | <section name="Example 2" class="client" show="false"> | ||
This example adds a "setpos" command to console, which allows setting of the local player's position. | This example adds a "setpos" command to console, which allows setting of the local player's position. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function consoleSetPlayerPosition ( commandName, posX, posY, posZ ) | function consoleSetPlayerPosition ( commandName, posX, posY, posZ ) | ||
setElementPosition ( | setElementPosition ( localPlayer, posX, posY, posZ ) | ||
end | end | ||
addCommandHandler ( "setpos", consoleSetPlayerPosition ) | addCommandHandler ( "setpos", consoleSetPlayerPosition ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | |||
<section name="Example 3" class="server" show="false"> | <section name="Example 3" class="server" show="false"> | ||
This example enables a player to type /warpto <playername> to warp to them. If the player being warped to is in a vehicle with a free passenger seat, it will warp into the vehicle. | This example enables a player to type /warpto <playername> to warp to them. If the player being warped to is in a vehicle with a free passenger seat, it will warp into the vehicle. | ||
Line 98: | Line 105: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> | ||
==Issues== | |||
{{Issues| | |||
{{Issue|9522|Setting a [[ped|ped's]] or [[player|player's]] position whilst occupying a [[givePedJetPack|jetpack]] will remove their jetpack, but not the jetpack sound}} | |||
}} | |||
==See Also== | ==See Also== | ||
{{Element functions}} | {{Element functions}} | ||
[[ | |||
[[hu:setElementPosition]] | |||
[[ru:setElementPosition]] |
Revision as of 21:23, 8 December 2018
This function sets the position of an element to the specified coordinates.
Warning: Do not use this function to spawn a player. It will cause problems with other functions like warpPedIntoVehicle. Use spawnPlayer instead. |
Syntax
bool setElementPosition ( element theElement, float x, float y, float z [, bool warp = true ] )
OOP Syntax Help! I don't understand this!
- Method: element:setPosition(...)
- Variable: .position
- Counterpart: getElementPosition
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
- warp: teleports players, resetting any animations they were doing. Setting this to false preserves the current animation.
Returns
Returns true if the function was successful, false otherwise.
Example
Click to collapse [-]
Example 1This example adds a "setpos" command to console, which allows setting of a player's position.
function consoleSetPlayerPosition ( source, commandName, posX, posY, posZ ) setElementPosition ( source, posX, posY, posZ ) end addCommandHandler ( "setpos", consoleSetPlayerPosition )
Click to expand [+]
Example 2Click to expand [+]
Example 3Issues
Issue ID | Description |
---|---|
#9522 | Setting a ped's or player's position whilst occupying a jetpack will remove their jetpack, but not the jetpack sound |
See Also
- addElementDataSubscriber
- clearElementVisibleTo
- cloneElement
- getAllElementData
- getElementSyncer
- getElementZoneName
- hasElementDataSubscriber
- isElementVisibleTo
- removeElementData
- removeElementDataSubscriber
- setElementSyncer
- setElementVisibleTo
Shared
- attachElements
- createElement
- destroyElement
- detachElements
- getAttachedElements
- getElementAlpha
- getElementAttachedOffsets
- getElementAttachedTo
- getElementByIndex
- getElementByID
- getElementChild
- getElementChildren
- getElementChildrenCount
- getElementCollisionsEnabled
- getElementColShape
- getElementData
- getAllElementData
- hasElementData
- getElementDimension
- getElementHealth
- getElementID
- getElementInterior
- getElementMatrix
- getElementModel
- getElementParent
- getElementPosition
- getElementRotation
- getElementsByType
- getElementsWithinColShape
- getElementsWithinRange
- getElementType
- getElementVelocity
- getLowLODElement
- getRootElement
- isElement
- isElementAttached
- isElementCallPropagationEnabled
- isElementDoubleSided
- isElementFrozen
- isElementInWater
- isElementLowLOD
- isElementWithinColShape
- isElementWithinMarker
- setElementAlpha
- setElementAngularVelocity
- getElementAngularVelocity
- setElementAttachedOffsets
- setElementCallPropagationEnabled
- setElementCollisionsEnabled
- setElementData
- setElementDimension
- setElementDoubleSided
- setElementFrozen
- setElementHealth
- setElementID
- setElementInterior
- setElementModel
- setElementParent
- setElementPosition
- setElementRotation
- setElementVelocity
- setLowLODElement
- getPedContactElement
- getResourceDynamicElementRoot
- getResourceRootElement