getElementsWithinRange | Multi Theft Auto: Wiki Skip to content

getElementsWithinRange

Client-side
Server-side
Shared

This page is incomplete! Help wanted!

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.

Syntax

getElementsWithinRange ( )

Code Examples

server

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
end
end
addCommandHandler("deletenearbyvehs", deleteNearbyVehicles)

See Also

Element Functions