From Multi Theft Auto: Wiki
Jump to navigation Jump to search
[[{{{image}}}|link=|]] Important Note: If you wish to retrieve more than one element at a time, it is more efficient to use getElementsByType instead.

This function returns an element of the specified type with the specified index.


element getElementByIndex ( string theType, int index )  

OOP Syntax Help! I don't understand this!

Note: This function is a static function inside the Element class.
Method: Element.getByIndex(...)

Required Arguments

  • theType: the type of the element to be returned. Examples include "player", "vehicle", or a custom type.
  • index: the element's index (0 for the first element, 1 for the second, etc).


Returns the requested element, or false if it doesn't exist.


This example generates the name of the specified player that is on the server. For example: 'player 0' would return the name of the first player on the server.

function showPlayer(command, index)
	local thePlayer = getElementByIndex("player", tonumber(index))
	if thePlayer then
		outputChatBox("Player " .. index .. " is a: " .. getPlayerName(thePlayer))
		outputChatBox("Player not found.")
addCommandHandler("player", showPlayer)

See Also