# CFX::GET_ENTITIES_IN_RADIUS

- **Hash:** `0xDFFBA12F`
- **Namespace:** CFX
- **Runtime name (Lua/JS):** `GetEntitiesInRadius`
- **Side:** shared (Cfx runtime native)
- **Name status:** official
- **Documentation:** described
- **URL:** https://natives.borderlinerp.com/natives/CFX/GET_ENTITIES_IN_RADIUS

## Signature

```c
object GET_ENTITIES_IN_RADIUS(float x, float y, float z, float radius, int entityType, BOOL sortByDistance, object models);
```

## Parameters

- `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

## Returns

`object` — An array containing entity handles for each entity.

## Description

*Source: Cfx.re native reference*

### Supported types

*   \[1] : Peds (including animals) and players.
*   \[2] : Vehicles.
*   \[3] : Objects (props), doors, and projectiles.

### Coordinates need to be send unpacked (x,y,z)

```lua

-- 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)
end

```

## Usage

### Lua

```lua
local retval = GetEntitiesInRadius(x, y, z, radius, entityType, sortByDistance, models)

-- always available, by hash
local retval = Citizen.InvokeNative(0xdffba12f, x, y, z, radius, entityType, sortByDistance, models, Citizen.ResultAsObject2(msgpack.unpack))
```

### JavaScript

```js
const retval = GetEntitiesInRadius(x, y, z, radius, entityType, sortByDistance, models);

// by hash
const retval = Citizen.invokeNative('0xdffba12f', x + 0.0000001, y + 0.0000001, z + 0.0000001, radius + 0.0000001, entityType, sortByDistance, models, Citizen.returnResultAnyway(), Citizen.resultAsObject2());
```

### C#

```csharp
Function.Call((Hash)0xdffba12f, x, y, z, radius, entityType, sortByDistance, models);
```

- Float parameters: Lua integers (`10`, or whole numbers decoded from NUI/JSON) are sent as ints and read as garbage. Write `10.0` or `value + 0.0`. The generated JS wrappers add `0.0000001` to non-zero floats for the same reason.

*Sources: Cfx.re native reference.*
