GetElementAttachedTo: 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__  
{{Server client function}}
This function returns an element from the specified ID.
__NOTOC__
This function determines the element that the specified element is attached to.


==Syntax==  
==Syntax==  
Line 14: Line 15:


==Example==  
==Example==  
This example assigns the element that the specified element is attached to into attached.
<section name="Server" class="server" show="true">
This example defines a console command that outputs the type of the element that the player is attached to.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler ( "onConsole", root, "onConsole" )
function getAttached ( thePlayer )
function onConsole ( text )
     local attached = getElementAttachedTo ( thePlayer )
  if ( getElementType ( source ) == "player" ) then
    if ( attached ) then
    command = gettok ( text, 1, 32 )
         outputConsole ( getClientName(thePlayer) .. " is attached to a " .. getElementType(attached) )
     if ( command == "getattached" ) then
    else
      attached = getElementAttachedTo ( source )
         outputConsole ( getClientName(thePlayer) .. " is not attached to an element" )
      if ( attached ) then
         outputConsole ( "element type: " .. getElementType ( attached ) ) -- possible output
      else
         outputConsole ( "not attached to an element" ) -- display error
      end
     end
     end
  end
end
end
addCommandHandler ( "getattached", getAttached )
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Element_functions}}
{{Element_functions}}

Revision as of 15:50, 20 August 2007

This function determines the element that the specified element is attached to.

Syntax

element getElementAttachedTo ( element theElement )  

Required Arguments

  • theElement: The element you require the information for.

Returns

Returns the element that the chosen element is attached to, or false if the element isn't attached to another element.

Example

Click to collapse [-]
Server

This example defines a console command that outputs the type of the element that the player is attached to.

function getAttached ( thePlayer )
    local attached = getElementAttachedTo ( thePlayer )
    if ( attached ) then
        outputConsole ( getClientName(thePlayer) .. " is attached to a " .. getElementType(attached) )
    else
        outputConsole ( getClientName(thePlayer) .. " is not attached to an element" )
    end
end
addCommandHandler ( "getattached", getAttached )

See Also