CloneElement: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(updated)
(Fixed example)
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. 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.
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.


Players are not the only elements that cannot be cloned. This list also includes remoteclients, and console elements.
Players are not the only elements that cannot be cloned. This list also includes remoteclients, and console elements.
Line 23: Line 23:


===Returns===
===Returns===
Returns the handle of the new cloned element of the parent.
Returns the handle of the new cloned element of the parent, ''false'' if invalid arguments were passed.


==Example==  
==Example==  
Line 29: Line 29:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function cloneVehicle ( source, commandName )
function cloneVehicle ( source, commandName )
  x, y, z = getElementPosition ( source ) -- get the position of the player
local occupiedVehicle = getPlayerOccupiedVehicle ( source ) -- get the player's vehicle
  clone = cloneElement ( getPlayerOccupiedVehicle ( source ), 5, 0, 0 ) -- create a clone of the player's vehicle
local clone = cloneElement ( occupiedVehicle, 5, 0, 0 ) -- create a clone of the player's vehicle
addCommandHandler ( "clone", "cloneVehicle" )
end
addCommandHandler ( "clone", cloneVehicle )
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Element functions}}
{{Element functions}}

Revision as of 11:29, 16 July 2007

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.

Players are not the only elements that cannot be cloned. This list also includes remoteclients, and console elements.

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 xPos = 0, float yPos = 0, float zPos = 0, bool cloneChildren = false ] )  

Required Arguments

  • theElement: The element that you wish to clone.

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • xPos: A floating point number representing the X coordinate on the map.
  • yPos: A floating point number representing the Y coordinate on the map.
  • zPos: A floating point number representing the Z coordinate on the map.
  • cloneChildren: A boolean value representing whether or not the element's children will be cloned.

Note: if 'cloneChildren' is true, the position floats will be offsets from the cloned element's position.

Returns

Returns the handle of the new cloned element of the parent, false if invalid arguments were passed.

Example

This example clones the vehicle a player is in. This allows carrying over of the current state of the vehicle, including mods, for exmple.

function cloneVehicle ( source, commandName )
	local occupiedVehicle = getPlayerOccupiedVehicle ( source ) -- get the player's vehicle
	local clone = cloneElement ( occupiedVehicle, 5, 0, 0 ) -- create a clone of the player's vehicle
end
addCommandHandler ( "clone", cloneVehicle )

See Also

Shared