GetElementsWithinRange: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
m (→Example) |
||
Line 21: | Line 21: | ||
This example retrieves a table of players within range of the 3D coordinates and prints their name to the chat. | This example retrieves a table of players within range of the 3D coordinates and prints their name to the chat. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
local elements = getElementsWithinRange( 0, 0, 3, 20 ) | local elements = getElementsWithinRange( 0, 0, 3, 20 ) -- get all elements within 20 units of 0, 0, 3 | ||
for _, element in ipairs( elements ) do | for _, element in ipairs( elements ) do -- use a generic for loop to step through each player | ||
if ( getElementType( element ) == "player" ) then | if ( getElementType( element ) == "player" ) then -- if the element is a player | ||
outputChatBox( getPlayerName( element ) .. " is within range" ) -- print their name to the chat | outputChatBox( getPlayerName( element ) .. " is within range" ) -- print their name to the chat | ||
end | end |
Revision as of 05:45, 29 July 2018
This function is used to retrieve a list of all elements within a range of 3D coordinates.
Syntax
table getElementsWithinRange ( float x, float y, float z, float range )
OOP Syntax Help! I don't understand this!
- Method: Element.getWithinRange(...)
Required Arguments
- x: the x coordinate at which to retrieve elements
- y: the y coordinate at which to retrieve elements
- z: the z coordinate at which to retrieve elements
- range: the range at the coordinates in which to retrieve elements
Returns
Returns a table containing all the elements within range. Returns an empty table if there are no elements within range. Returns false if the arguments are invalid.
Example
This example retrieves a table of players within range of the 3D coordinates and prints their name to the chat.
local elements = getElementsWithinRange( 0, 0, 3, 20 ) -- get all elements within 20 units of 0, 0, 3 for _, element in ipairs( elements ) do -- use a generic for loop to step through each player if ( getElementType( element ) == "player" ) then -- if the element is a player outputChatBox( getPlayerName( element ) .. " is within range" ) -- print their name to the chat end end
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