GetElementsWithinRange: Difference between revisions
Jump to navigation
Jump to search
(Correct circle to sphere) |
Zangomangu (talk | contribs) (Added int/dim argument added in r20797) |
||
Line 3: | Line 3: | ||
{{New feature/item|3.0156|1.5.5|13823|This function is used to retrieve a list of all elements of specified type within a range of 3D coordinates.}} | {{New feature/item|3.0156|1.5.5|13823|This function is used to retrieve a list of all elements of specified type within a range of 3D coordinates.}} | ||
{{Note| | {{Note| | ||
* This function checks if elements are in a box, not in a sphere. | * This function checks if elements are in a box, not in a sphere. | ||
* Z argument isn't in use currently, but make your scripts like it is for future compatibility reasons. | * Z argument isn't in use currently, but make your scripts like it is for future compatibility reasons. | ||
Line 27: | Line 26: | ||
**'''"pickup":''' A pickup | **'''"pickup":''' A pickup | ||
**'''"marker":''' A marker | **'''"marker":''' A marker | ||
{{New feature/item|3.0160|1.5.8|20797| | |||
<syntaxhighlight lang="lua"> | |||
table getElementsWithinRange ( float x, float y, float z, float range [, string elemType = "", int interior = nil, int dimension = nil ] ) | |||
</syntaxhighlight> | |||
{{OOP| |[[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 | |||
===Optional Arguments=== | |||
*'''elemType:''' The type of element you want a list of. This can be any element type, such as: | |||
**'''"player":''' A player connected to the server | |||
**'''"ped":''' A ped | |||
**'''"vehicle":''' A vehicle | |||
**'''"object":''' An object | |||
**'''"pickup":''' A pickup | |||
**'''"marker":''' A marker | |||
*'''interior:''' The [[interior]] you want to limit the search to. If not specified, it can return elements in any interior. | |||
*'''dimension:''' The [[dimension]] you want to limit the search to. If not specified, it can return elements in any dimension. | |||
}} | |||
===Returns=== | ===Returns=== |
Revision as of 09:01, 26 January 2021
This function is used to retrieve a list of all elements of specified type within a range of 3D coordinates.
Syntax
table getElementsWithinRange ( float x, float y, float z, float range [, string elemType = "" ] )
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
Optional Arguments
- elemType: The type of element you want a list of. This can be any element type, such as:
- "player": A player connected to the server
- "ped": A ped
- "vehicle": A vehicle
- "object": An object
- "pickup": A pickup
- "marker": A marker
table getElementsWithinRange ( float x, float y, float z, float range [, string elemType = "", int interior = nil, int dimension = nil ] )
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
Optional Arguments
- elemType: The type of element you want a list of. This can be any element type, such as:
- "player": A player connected to the server
- "ped": A ped
- "vehicle": A vehicle
- "object": An object
- "pickup": A pickup
- "marker": A marker
- interior: The interior you want to limit the search to. If not specified, it can return elements in any interior.
- dimension: The dimension you want to limit the search to. If not specified, it can return elements in any dimension.
Returns
Returns a table containing all the elements of the specified type within range. Returns an empty table if there are no elements within range. Returns false if the arguments are invalid.
Example
This example allows admins to destroy all vehicles in close proximity.
function deleteNearbyVehicles(p) local acc = getPlayerAccount(p) if not isGuestAccount(acc) and isObjectInACLGroup("user."..getAccountName(acc), aclGetGroup("Admin")) then local x, y, z = getElementPosition(p) local nearbyVehicles = getElementsWithinRange(x, y, z, 300, "vehicle") for i,v in ipairs(nearbyVehicles) do if v and isElement(v) then destroyElement(v) end end end end addCommandHandler ("delnearvehs", deleteNearbyVehicles)
Example
This example retrieves a table of players within range of the 3D coordinates and prints their name to the chat.
local players = getElementsWithinRange( 0, 0, 3, 20, "player" ) -- get all player elements within 20 units of 0, 0, 3 for _, player in pairs( players ) do -- use a generic for loop to step through each player outputChatBox( getPlayerName( player ) .. " is within range" ) -- print their name to the chat 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