CloneElement: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
This function clones (creates an exact copy of) an already existing element. The root node, and player elements cannot be cloned.
This function clones (creates an exact copy of) an already existing element. The root node, and player elements cannot be cloned. If a player element is a child of an element that is cloned, it will be skipped, along with the elements that exist as a child to the player element.
 
The cloned element will be placed on the element tree as a child of the same parent as the cloned element.


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
element cloneElement ( element theElement, [ float xOffset, float yOffset, float zOffset, bool cloneChildren=false ] )   
element cloneElement ( element theElement, [ float xOffset = 0, float yOffset = 0, float zOffset = 0, bool cloneChildren = false ] )   
</syntaxhighlight>  
</syntaxhighlight>  


Line 11: Line 13:


===Optional Arguments===
===Optional Arguments===
* '''xPos''': A floating point number representing the offset from the cloned element's X coordinate on the map.
* '''xOffset''': A floating point number representing the offset from the cloned element's X coordinate on the map.
* '''yPos''': A floating point number representing the offset from the cloned element's Y coordinate on the map.
* '''yOffset''': A floating point number representing the offset from the cloned element's Y coordinate on the map.
* '''zPos''': A floating point number representing the offset from the cloned element's Z coordinate on the map.
* '''zOffset''': A floating point number representing the offset from the cloned element's Z coordinate on the map.
* '''cloneChildren''': A boolean value representing whether or not the element's children will be cloned.
* '''cloneChildren''': A boolean value representing whether or not the element's children will be cloned.



Revision as of 15:11, 16 August 2006

This function clones (creates an exact copy of) an already existing element. The root node, and player elements cannot be cloned. If a player element is a child of an element that is cloned, it will be skipped, along with the elements that exist as a child to the player element.

The cloned element will be placed on the element tree as a child of the same parent as the cloned element.

Syntax

element cloneElement ( element theElement, [ float xOffset = 0, float yOffset = 0, float zOffset = 0, bool cloneChildren = false ] )  

Required Arguments

  • theElement: The element that you wish to clone.

Optional Arguments

  • xOffset: A floating point number representing the offset from the cloned element's X coordinate on the map.
  • yOffset: A floating point number representing the offset from the cloned element's Y coordinate on the map.
  • zOffset: A floating point number representing the offset from the cloned element's Z coordinate on the map.
  • cloneChildren: A boolean value representing whether or not the element's children will be cloned.

Returns

Returns the handle of the new cloned element of the parent.

Example

This example clones the vehicle a player is in.

if ( command == "clone" ) then
  x, y, z = getElementPosition ( source ) -- get the position of the player
  clone = cloneElement ( getPlayerOccupiedVehicle ( source ), 5, 0, 0 ) -- create a clone of the player's vehicle
end

See Also