cloneElement | Multi Theft Auto: Wiki Skip to content

cloneElement

Client-side
Server-side
Shared

This page is incomplete! Help wanted!

Please finish this page using the corresponding Old Wiki article.
Go to Contribution guidelines for more information.


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.

Syntax

cloneElement ( )

Code Examples

server

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

function cloneVehicle ( thePlayer, commandName )
local occupiedVehicle = getPedOccupiedVehicle ( thePlayer ) -- get the player's vehicle
if occupiedVehicle then -- If the player is actually in a vehicle
local x, y, z = getElementPosition ( occupiedVehicle ) -- get the vehicle's position
local clone = cloneElement ( occupiedVehicle, x+5, y, z ) -- create a clone of the vehicle near it
else
outputChatBox ( "You can't clone a vehicle if you're not in a vehicle", thePlayer, 255, 0, 0 )
end
end
addCommandHandler ( "clone", cloneVehicle )

See Also

Element Functions