detachElements | Multi Theft Auto: Wiki Skip to content

detachElements

Client-side
Server-side
Shared

Pair: attachElements

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 detaches attached elements from one another.

Syntax

detachElements ( )

Code Examples

server

Example 1:This example attaches a marker to a vehicle, and detaches it when it blows up:

function attachMarkerToVehicle ( theVehicle )
-- create the marker to attach
local arrowMarker = createMarker ( 0, 0, 0, "arrow", 1.5, 0, 0, 255, 255 )
-- attach the marker above the vehicle
attachElements ( arrowMarker, theVehicle, 0, 0, 2 )
-- add an event handler for when the vehicle blows up
addEventHandler ( "onVehicleExplode", theVehicle, onMarkedCarExplode )
end
function onMarkedCarExplode ()
-- get the elements attached to the vehicle
local attachedElements = getAttachedElements ( source )
-- loop through the table of elements
for i,v in ipairs ( attachedElements ) do
-- detach the element from the vehicle
detachElements ( v, source )
end
-- remove the event handler
removeEventHandler ( "onVehicleExplode", source, onMarkedCarExplode )
end

See Also

Element Functions