GetElementByIndex: Difference between revisions
Jump to navigation
Jump to search
m (Removed a line of example code that just said "if (". Removed tostring() around getVehicleName()) |
No edit summary |
||
Line 17: | Line 17: | ||
==Example== | ==Example== | ||
This example outputs the name of the specified vehicle currently | This example outputs the name of the specified vehicle currently existent in the XML tree. For example: 'vehicle 0' would return the first vehicle. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function showVehicle( | function showVehicle(thePlayer, command, index) | ||
local | local theVehicle = getElementByIndex("vehicle", tonumber(index)) | ||
if | if theVehicle then | ||
outputChatBox("Vehicle " .. index .. " is a: " .. getVehicleName( | outputChatBox("Vehicle " .. index .. " is a: " .. getVehicleName(theVehicle), thePlayer) | ||
else | else | ||
outputChatBox("Vehicle not found.", | outputChatBox("Vehicle not found.", thePlayer) | ||
end | end | ||
end | end | ||
addCommandHandler("vehicle",showVehicle) | addCommandHandler("vehicle", showVehicle) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{Element_functions}} | {{Element_functions}} |
Revision as of 19:36, 19 August 2007
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 type, int index )
Required Arguments
- type: 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
- attachElements
- createElement
- destroyElement
- detachElements
- getAttachedElements
- getElementAlpha
- getElementAttachedOffsets
- getElementAttachedTo
- getElementByIndex
- getElementByID
- getElementChild
- getElementChildren
- getElementChildrenCount
- getElementCollisionsEnabled
- getElementColShape
- getElementData
- getAllElementData
- hasElementData
- getElementDimension
- getElementHealth
- getElementID
- getElementInterior
- getElementMatrix
- getElementModel
- getElementParent
- getElementPosition
- getElementRotation
- getElementsByType
- getElementsWithinColShape
- getElementsWithinRange
- getElementType
- getElementVelocity
- getLowLODElement
- getRootElement
- isElement
- isElementAttached
- isElementCallPropagationEnabled
- isElementDoubleSided
- isElementFrozen
- isElementInWater
- isElementLowLOD
- isElementWithinColShape
- isElementWithinMarker
- setElementAlpha
- setElementAngularVelocity
- getElementAngularVelocity
- setElementAttachedOffsets
- setElementCallPropagationEnabled
- setElementCollisionsEnabled
- setElementData
- setElementDimension
- setElementDoubleSided
- setElementFrozen
- setElementHealth
- setElementID
- setElementInterior
- setElementModel
- setElementParent
- setElementPosition
- setElementRotation
- setElementVelocity
- setLowLODElement
- getPedContactElement
- getResourceDynamicElementRoot
- getResourceRootElement