GetAttachedElements: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
Line 18: Line 18:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- Print a list of all the players attached to the specified element
-- Print a list of all the players attached to the specified element
   Inf = getElementByID ( "infernus1" )
   local Inf = getElementByID ( "infernus1" )
   attachedElements = getAttachedElements ( Inf )
   local attachedElements = getAttachedElements ( Inf )
   if ( attachedElements ) then -- if we got the table
   if ( attachedElements ) then -- if we got the table
     attachedElementsList = "none"
     local attachedElementsList = "none"
     -- Loop through the table
     -- Loop through the table
     for ElementKey, ElementValue in attachedElements do
     for ElementKey, ElementValue in ipairs ( attachedElements ) do
       -- add their name to the list
       -- add their name to the list
       if ( getElementType ( ElementValue ) == "player" ) then
       if ( getElementType ( ElementValue ) == "player" ) then

Revision as of 10:11, 15 December 2007

This function returns a table of all the elements attached to the specified element

Syntax

table getAttachedElements ( element theElement )

Required Arguments

  • theElement: The element which you require the information from.

Returns

Returns a table of all the elements attached to the specified element.

Example

Click to collapse [-]
Server
-- Print a list of all the players attached to the specified element
  local Inf = getElementByID ( "infernus1" )
  local attachedElements = getAttachedElements ( Inf )
  if ( attachedElements ) then -- if we got the table
    local attachedElementsList = "none"
    -- Loop through the table
    for ElementKey, ElementValue in ipairs ( attachedElements ) do
      -- add their name to the list
      if ( getElementType ( ElementValue ) == "player" ) then
        if ( attachedElementsList == "none" ) then
          attachedElementsList = getClientName ( ElementValue )
        else
          attachedElementsList = attachedElementsList .. ", " .. getClientName ( ElementValue )
        end
      end
    end
    outputConsole ( "Players attached to the infernus: " .. attachedElementsList )
  end

See Also