FiveM Docs / Native Reference
API Set:
  • all
  • server
  • client
Language:
  • raw
  • lua
  • c#
  • js
Namespace: CFXAPI set: sharededitImprove

GET_ENTITIES_IN_RADIUS

0xDFFBA12F
// GetEntitiesInRadius
object GET_ENTITIES_IN_RADIUS(float x, float y, float z, float radius, int entityType, BOOL sortByDistance, object models);
Parameters:
  • x:

    The X coordinate.

  • y:

    The Y coordinate.

  • z:

    The Z coordinate.

  • radius:

    Max distance from coordinate to entity

  • entityType:

    Entity types see list below

  • sortByDistance:

    Sort output entites by distance from nearest to farthest

  • models:

    List of allowed models its also optional

Returns:

An array containing entity handles for each entity.

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)

-- 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
Privacy
•
Cookie Policy
•
Cookie Settings
GET_ALL_OBJECTS()
GET_ALL_PEDS()
GET_ALL_ROPES()
GET_ALL_TRACK_JUNCTIONS()
GET_ALL_VEHICLE_MODELS()
GET_ALL_VEHICLES()
GET_AMBIENT_PED_RANGE_MULTIPLIER()
GET_AMBIENT_VEHICLE_RANGE_MULTIPLIER()
GET_CALMING_QUAD_AT_COORDS(float x, float y)
GET_CALMING_QUAD_BOUNDS(int waterQuad, int* minX, int* minY, int* maxX, int* maxY)
GET_CALMING_QUAD_COUNT()
GET_CALMING_QUAD_DAMPENING(int waterQuad, float* calmingQuadDampening)
GET_CAM_MATRIX(Cam camera, Vector3* rightVector, Vector3* forwardVector, Vector3* upVector, Vector3* position)
GET_CLOSEST_TRACK_NODES(Vector3 position, float radius)
GET_CONSOLE_BUFFER()
GET_CONVAR(char* varName, char* default_)
GET_CONVAR_BOOL(char* varName, BOOL defaultValue)
GET_CONVAR_FLOAT(char* varName, float defaultValue)
GET_CONVAR_INT(char* varName, int default_)
GET_CURRENT_GAME_NAME()
GET_CURRENT_PED_WEAPON(Ped ped)
GET_CURRENT_RESOURCE_NAME()
GET_CURRENT_SERVER_ENDPOINT()
GET_DUI_HANDLE(long duiObject)
GET_ENTITIES_IN_RADIUS(float x, float y, float z, float radius, int entityType, BOOL sortByDistance, object models)
GET_ENTITY_ADDRESS(Entity entity)
GET_ENTITY_ARCHETYPE_NAME(Entity entity)
GET_ENTITY_ATTACHED_TO(Entity entity)
GET_ENTITY_COLLISION_DISABLED(Entity entity)
GET_ENTITY_COORDS(Entity entity)
GET_ENTITY_FROM_STATE_BAG_NAME(char* bagName)
GET_ENTITY_HEADING(Entity entity)
GET_ENTITY_HEALTH(Entity entity)
GET_ENTITY_INDEX_FROM_MAPDATA(int mapdata, int entity)
GET_ENTITY_MAPDATA_OWNER(Entity entity, int* mapdataHandle, int* entityHandle)