getElementsByType | Multi Theft Auto: Wiki Skip to content

getElementsByType

Client-side
Server-side
Shared

Manual Review Required

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


This function is used to retrieve a list of all elements of the specified type. This can be useful, as it disregards where in the element tree it is. It can be used with either the built in types (listed below) or with any custom type used in a .map file. For example, if there is an element of type "flag" (e.g. <flag />) in the .map file, the using "flag" as the type argument would find it.

OOP Syntax Help! I don't understand this!

  • Note: This function is a static function underneath the Element class.

  • Method:Element.)(...)

Syntax

table getElementsByType ( string theType, [ [ element startat = getRootElement( ] )
Required Arguments
  • theType: MISSING_PARAM_DESC
Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.

  • element startat (default: getRootElement(): MISSING_PARAM_DESC

Returns

  • table: value

Returns a table containing all the elements of the specified type. Returns an empty table if there are no elements of the specified type. Returns false if the string specified is invalid (or not a string).

Code Examples

server

Example 1:This example retrieves a table of the players in the server, and checks whether or not each one is in a vehicle:

local players = getElementsByType ( "player" ) -- get a table of all the players in the server
for theKey,thePlayer in ipairs(players) do -- use a generic for loop to step through each player
if ( isPlayerInVehicle ( thePlayer ) ) then -- if the player is in a vehicle, announce it
outputChatBox ( getPlayerName ( thePlayer ) .. " is in a vehicle" )
else -- if the player isn't in a vehicle, announce that he/she is on foot
outputChatBox ( getPlayerName ( thePlayer ) .. " is on foot" )
end
end

See Also

Element Functions