GetEntitiesInRadius
Docslocal retval = GetEntitiesInRadius(x, y, z, radius, entityType, sortByDistance, models)Description
### Supported types
\[1] : Peds (including animals) and players.
\[2] : Vehicles.
- \[3] : Objects (props), doors, and projectiles.
-- Define the allowed model hashes
local allowedModelHashes = { GetHashKey("p_crate03x"), GetHashKey("p_crate22x") }
-- Get the player's current coordinates
local playerCoords = GetEntityCoords(PlayerPedId())
-- Retrieve all entities of type Object (type 3) within a radius of 10.0 units
-- that match the allowed model hashes
-- and sort output entities by distance
local entities = GetEntitiesInRadius(playerCoords.x, playerCoords.y, playerCoords.z, 10.0, 3, true, allowedModelHashes)
-- Iterate through the list of entities and print their ids
for i = 1, #entities do
local entity = entities[i]
print(entity)
endParameters
| Name | Type | Description |
|---|---|---|
x | float | The X coordinate. |
y | float | The Y coordinate. |
z | float | The Z coordinate. |
radius | float | Max distance from coordinate to entity |
entityType | int | Entity types see list below |
sortByDistance | BOOL | Sort output entites by distance from nearest to farthest |
models | object | List of allowed models its also optional |
Quick Snippet: Get Coordinatesxyz
xyzAdd this command to your client script to retrieve precise locations in-game.
-- Add this to your client.lua. Type /pos in-game to copy coords.
RegisterCommand('pos', function()
local ped = PlayerPedId()
local coords = GetEntityCoords(ped)
local heading = GetEntityHeading(ped)
local output = string.format("vector4(%.2f, %.2f, %.2f, %.2f)", coords.x, coords.y, coords.z, heading)
print(output)
TriggerEvent('chat:addMessage', { args = { '^4[COORD]^0', output } })
end)Returns
object