SetElementPosition: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (make shared function)
No edit summary
Line 2: Line 2:
{{Shared function}}
{{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.}}
{{Warning|Do not use this function to spawn a [[player]]. It will cause problems with other functions like [[warpPedIntoVehicle]]. Use [[spawnPlayer]] instead. MTA freezes player by itself so it is not recommended to use [[setElementFrozen]] after changing element's position.}}
 
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">

Revision as of 18:00, 16 December 2017

This function sets the position of an element to the specified coordinates.

[[|link=|]] Warning: Do not use this function to spawn a player. It will cause problems with other functions like warpPedIntoVehicle. Use spawnPlayer instead. MTA freezes player by itself so it is not recommended to use setElementFrozen after changing element's position.

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 1

This 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 2
Click to expand [+]
Example 3

See Also