GetElementByIndex: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 6: Line 6:
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
element getElementByIndex ( string type, int index )   
element getElementByIndex ( string theType, int index )   
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''type:''' the type of the element to be returned. Examples include "player", "vehicle", or a custom type.
*'''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).
*'''index:''' the element's index (0 for the first element, 1 for the second, etc).



Revision as of 19:53, 4 October 2012

This template is no longer in use as it results in poor readability. This function returns an element of the specified type with the specified index.

Syntax

element getElementByIndex ( string theType, int index )  

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

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

Example

This example outputs the name of the specified vehicle currently existent in the XML tree. For example: 'vehicle 0' would return the first vehicle.

function showVehicle(thePlayer, command, index)
	local theVehicle = getElementByIndex("vehicle", tonumber(index))
	if theVehicle then
		outputChatBox("Vehicle " .. index .. " is a: " .. getVehicleName(theVehicle), thePlayer)
	else
		outputChatBox("Vehicle not found.", thePlayer)
	end
end
addCommandHandler("vehicle", showVehicle)

See Also