GetElementsByType: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(removed cols -> colshape)
No edit summary
Line 1: Line 1:
{{Needs_Checking|I don't think any of the "colcube", "colsphere", "coltube", "colcircle" or "colsquare work at all.  I've only been able to use "colshape" which isnt even listed here.}}
{{Server_client_function}}
 
__NOTOC__  
__NOTOC__  
This function is used to retreive a list of all elemets of the specified type. This can be useful, as it disregards ''where'' in the element table it is in the element heirarchy. It can be used with either the built in types (listed below) or with any type used in the .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.
This function is used to retreive a list of all elemets of the specified type. This can be useful, as it disregards ''where'' in the element table it is in the element heirarchy. It can be used with either the built in types (listed below) or with any type used in the .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.

Revision as of 20:14, 3 April 2008

This function is used to retreive a list of all elemets of the specified type. This can be useful, as it disregards where in the element table it is in the element heirarchy. It can be used with either the built in types (listed below) or with any type used in the .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.

Syntax

table getElementsByType ( string type, [ element startat=getRootElement() ] ) 

Required Arguments

  • type: The type of element you want a list of. This is the same as the tag name in the .map file, so this can be used with a custom element type if desired. Built in types are:
    • "player": A player connected to the server
    • "vehicle":: A vehicle
    • "object": An object
    • "pickup": A pickup
    • "marker": A marker
    • "colshape": A collision shape
    • "blip": A blip
    • "radararea": A radar area
    • "team": A team
    • "spawnpoint": A spawnpoint
    • "remoteclient": A remote client connected to the server
    • "console": The server Console

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • startat: The element the search should start at. Children of this element are searched, siblings or parents will not be found. By default, this is the root element which should suit most uses.

Returns

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).

Example

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 ( getClientName ( thePlayer ) .. " is in a vehicle" )
   else -- if the player isn't in a vehicle, announce that he/she is on foot
      outputChatBox ( getClientName ( thePlayer ) .. " is on foot" )
   end
end

See Also