getElementsWithinRange
Client-side
Server-side
Shared
Manual Review Required
Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.
This function is used to retrieve a list of all elements of specified type within a range of 3D coordinates.
Note
This function checks if elements are in a box, not in a sphere. This function doesn't work with elements which are created by createElement.
OOP Syntax Help! I don't understand this!
- Method:Element.)(...)
Syntax
table getElementsWithinRange ( float x, float y, float z, float range, [ string elemType = "" ], int interior, int dimension )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.
- interior: MISSING_PARAM_DESC
- dimension: MISSING_PARAM_DESC
Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.
- elemType (default: ""): 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.
Returns
- table: value
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.
Code Examples
shared
This example allows admins to destroy all vehicles in close proximity.
function deleteNearbyVehicles(playerElement) local playerAccount = getPlayerAccount(playerElement)
if (not playerAccount) then return false end
local guestAccount = isGuestAccount(playerAccount)
if (guestAccount) then return false end
local accountName = getAccountName(playerAccount) local aclObject = "user."..accountName local adminGroup = aclGetGroup("Admin") local playerAdmin = isObjectInACLGroup(aclObject, adminGroup)
if (not playerAdmin) then return false end
local playerX, playerY, playerZ = getElementPosition(playerElement) local playerInterior = getElementInterior(playerElement) local playerDimension = getElementDimension(playerElement) local searchRange = 300 local nearbyVehicles = getElementsWithinRange(playerX, playerY, playerZ, searchRange, "vehicle", playerInterior, playerDimension)
for vehicleID = 1, #nearbyVehicles do local vehicleElement = nearbyVehicles[vehicleID] local validElement = isElement(vehicleElement)
if (validElement) then destroyElement(vehicleElement) end endendaddCommandHandler("deletenearbyvehs", deleteNearbyVehicles)See Also
Element Functions
- addElementDataSubscriber
- attachElements
- clearElementVisibleTo
- cloneElement
- createElement
- destroyElement
- detachElements
- getAllElementData
- getAttachedElements
- getElementAlpha
- getElementAngularVelocity
- getElementAttachedOffsets
- getElementAttachedTo
- getElementBonePosition
- getElementBoneQuaternion
- getElementBoneRotation
- getElementBoundingBox
- getElementByID
- getElementByIndex
- getElementChild
- getElementChildren
- getElementChildrenCount
- getElementCollisionsEnabled
- getElementColShape
- getElementData
- getElementDimension
- getElementDistanceFromCentreOfMassToBaseOfModel
- getElementHealth
- getElementID
- getElementInterior
- getElementLighting
- getElementModel
- getElementParent
- getElementPosition
- getElementRadius
- getElementRotation
- getElementsByType
- getElementsWithinColShape
- getElementsWithinRange
- getElementSyncer
- getElementType
- getElementVelocity
- getElementZoneName
- getLowLODElement
- getRootElement
- hasElementData
- hasElementDataSubscriber
- isElement
- isElementAttached
- isElementCallPropagationEnabled
- isElementCollidableWith
- isElementDoubleSided
- isElementFrozen
- isElementInWater
- isElementLocal
- isElementLowLOD
- isElementOnFire
- isElementOnScreen
- isElementStreamable
- isElementStreamedIn
- isElementSyncer
- isElementVisibleTo
- isElementWaitingForGroundToLoad
- isElementWithinColShape
- isElementWithinMarker
- removeElementData
- removeElementDataSubscriber
- setElementAlpha
- setElementAngularVelocity
- setElementAttachedOffsets
- setElementBonePosition
- setElementBoneQuaternion
- setElementBoneRotation
- setElementCallPropagationEnabled
- setElementCollidableWith
- setElementCollisionsEnabled
- setElementData
- setElementDimension
- setElementDoubleSided
- setElementFrozen
- setElementHealth
- setElementID
- setElementInterior
- setElementLighting
- setElementModel
- setElementOnFire
- setElementParent
- setElementPosition
- setElementRotation
- setElementStreamable
- setElementSyncer
- setElementVelocity
- setElementVisibleTo
- setLowLODElement
- updateElementRpHAnim
Element Events
- onClientElementColShapeHit
- onClientElementColShapeLeave
- onClientElementDataChange
- onClientElementDestroy
- onClientElementDimensionChange
- onClientElementInteriorChange
- onClientElementModelChange
- onClientElementStreamIn
- onClientElementStreamOut
- onElementClicked
- onElementColShapeHit
- onElementColShapeLeave
- onElementDataChange
- onElementDestroy
- onElementDimensionChange
- onElementInteriorChange
- onElementModelChange
- onElementStartSync
- onElementStopSync