DetachElementFromElement: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
m (Changed "DeprecatedWithAlt" template to "Deprecated")
 
(9 intermediate revisions by 7 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__
{{Server client function}}
{{Deprecated|detachElements|}}
 
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
This fake function is for use with blah & blah and does blahblahblabhalbhl
This function detaches attached elements from one another.


==Syntax==  
==Syntax==  
Line 11: Line 14:
===Required Arguments===  
===Required Arguments===  
<!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type -->
<!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type -->
*'''argumentName:''' description
*'''theElement:''' The element to be detached (the "child")


<!-- Only include this section below if there are optional arguments -->
<!-- Only include this section below if there are optional arguments -->
===Optional Arguments===  
===Optional Arguments===  
{{OptionalArg}}  
{{OptionalArg}}  
*'''argumentName2:''' description
*'''theAttachToElement:''' The element you wish to detach from, will detach from the attached element if this isn't specified.
*'''argumentName3:''' description


===Returns===
===Returns===
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check -->
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check -->
Returns ''true'' if blah, ''false'' otherwise.
Returns ''true'' if the detaching was successful, ''false'' otherwise.


==Example==  
==Example==  
<!-- Explain what the example is in a single sentance -->
'''Example 1:''' This example attaches a marker to a vehicle, and detaches it when it blows up:
This example does...
<syntaxhighlight lang="lua">
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
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
    attachElementToElement ( 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
        detachElementFromElement ( v, source )
    end
    -- remove the event handler
    removeEventHandler ( "onVehicleExplode", source, "onMarkedCarExplode" )
end
</syntaxhighlight>
'''Example 2:''' This function will detach any elements that might have been attached to the passed element:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--This line does...
function freeElement( theElement )
blabhalbalhb --abababa
      if ( isElementAttached( theElement ) ) then --If the specified element is attached to something
--This line does this...
            detachElementFromElement( theElement ) --Detach it.
mooo
      else
            outputChatBox( "Element is not attached" ) --If not, say it wasn't attached in the first place.
      end
end
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
<!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc -->
<!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc -->
{{FunctionArea_functions}}
{{Element_functions}}
[[Category:Incomplete]] -- leave this unless you complete the function

Latest revision as of 16:27, 13 February 2015

Emblem-important.png This function is deprecated. This means that its use is discouraged and that it might not exist in future versions.

Please use detachElements instead.


This function detaches attached elements from one another.

Syntax

bool detachElementFromElement ( element theElement, [ element theAttachToElement ] )

Required Arguments

  • theElement: The element to be detached (the "child")

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.

  • theAttachToElement: The element you wish to detach from, will detach from the attached element if this isn't specified.

Returns

Returns true if the detaching was successful, false otherwise.

Example

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
    attachElementToElement ( 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
        detachElementFromElement ( v, source )
    end
    -- remove the event handler
    removeEventHandler ( "onVehicleExplode", source, "onMarkedCarExplode" )
end

Example 2: This function will detach any elements that might have been attached to the passed element:

function freeElement( theElement )
      if ( isElementAttached( theElement ) ) then --If the specified element is attached to something
            detachElementFromElement( theElement ) --Detach it.
      else
            outputChatBox( "Element is not attached" ) --If not, say it wasn't attached in the first place.
      end
end

See Also