GetElementsWithinColShape: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 27: Line 27:


==Example==  
==Example==  
This example retrieves a table of the players in the server, and checks whether or not each one is in a vehicle:
This example retrieves a table of the players in the colshape and prints their name to the chat.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local colshape = createColSphere ( 1, 2, 3, 4 )
local colshape = createColSphere ( 1, 2, 3, 4 )

Revision as of 21:42, 8 October 2006

This function is used to retreive a list of all elements in a colshape, of the specified type.

Syntax

table getElementsWithinColShape ( colshape shape, [ string type ] ) 

Required Arguments

  • shape: The colshape you want to get the elements from.

Optional Arguments

  • type: The type of element you want a list of. This can be any one of the following ten things MTA is programmed to understand:
    • "player": A player connected to the server
    • "vehicle":: A vehicle
    • "object": An object
    • "pickup": A pickup
    • "blip": A blip
    • "marker": A marker
    • "spawnpoint": A spawnpoint
    • "remoteclient": A remote client connected to the server
    • "console": The server Console
    • "unknown": Unknown element type

Returns

Returns a table containing all the elements inside the colshape, of the specified type. Returns an empty table if there are no elements inside. Returns false if the colshape is invalid.

Example

This example retrieves a table of the players in the colshape and prints their name to the chat.

local colshape = createColSphere ( 1, 2, 3, 4 )
local players = getElementsWithinColShape ( colshape, "player" ) -- get all the players inside the sphere
for theKey,thePlayer in players do -- use a generic for loop to step through each player
   outputChatBox ( getClientName ( thePlayer ) .. " is in our new sphere" ) -- print their name to the chat
end

See Also