Entities

CLIENT SIDE ONLY

A small selection of usefull functions relevant to entities within FiveM.

Functions

get_nearby_objects

Retrieves list of nearby objects.

--- Define coords
local coords = vector3(100.0, 100.0, 20.0)
--- Define radius
local radius = 10.0

--- Utils object
local objects = utils.entities.get_nearby_objects(coords, radius)

for _, obj in ipairs(objects) do
    print("Object ID:", obj.entity)
    print("Object Coordinates:", obj.coords)
end

--- Direct export
local objects = exports.boii_utils:get_nearby_objects(...)

get_nearby_peds

Retrieves list of nearby peds.

--- Define coords
local coords = vector3(100.0, 100.0, 20.0)
--- Define radius
local radius = 10.0

--- Utils object
local nearby_peds = utils.entities.get_nearby_peds(coords, radius)

for _, ped in ipairs(nearby_peds) do
    print("Ped ID:", ped.entity)
    print("Ped Coordinates:", ped.coords)
end

--- Direct export
exports.boii_utils:get_nearby_peds(...)

get_nearby_players

Retrieves a list of nearby players.

--- Define coords
local coords = vector3(100.0, 100.0, 20.0)
--- Define radius
local radius = 10.0
--- Specify if the player should be included
local include_player = true

--- Utils object
local nearby_players = utils.entities.get_nearby_players(coords, radius, include_player)

for _, player in ipairs(nearby_players) do
    print("Pplayer ID:", player.entity)
    print("Ped Coordinates:", player.coords)
end

--- Direct export
exports.boii_utils:get_nearby_players(...)

get_nearby_vehicles

Retrieve list of nearby vehicles optionally include players vehicle.

--- Define coords
local coords = vector3(100.0, 100.0, 20.0)
--- Define radius
local radius = 10.0
--- Specify if the player should be included
local include_player_vehicle = true

--- Utils object
local vehicles = utils.entities.get_nearby_vehicles(coords, radius, include_player_vehicle)

for _, vehicle in ipairs(vehicles) do
    print("Vehicle ID:", vehicle.entity)
    print("Vehicle Coordinates:", vehicle.coords)
end

--- Direct export
exports.boii_utils:get_nearby_vehicles(...)

get_closest_object

Retrieves the closest object.

--- Define coords
local coords = vector3(100.0, 100.0, 20.0)
--- Define radius
local radius = 10.0

--- Utils object
local closest_object, object_coords = utils.entities.get_closest_object(coords, radius)
if closest_object then
    print("Closest Object ID:", closest_object)
    print("Closest Object Coordinates:", object_coords)
else
    print("No objects found within the specified distance.")
end

--- Direct export
exports.boii_utils:get_closest_object(...)

get_closest_ped

Retrieves the closest ped excluding players.

--- Define coords
local coords = vector3(100.0, 100.0, 20.0)
--- Define radius
local radius = 10.0

--- Utils object
local closest_ped, ped_coords = utils.entities.get_closest_ped(coords, radius)
if closest_ped then
    print("Closest Ped ID:", closest_ped)
    print("Closest Ped Coordinates:", ped_coords)
else
    print("No peds found within the specified distance.")
end

--- Direct export
exports.boii_utils:get_closest_ped(...)

get_closest_player

Retrieves the closest player.

--- Define coords
local coords = vector3(100.0, 100.0, 20.0)
--- Define radius
local radius = 10.0
--- Specify if the player should be included
local include_player = true


--- Utils object
local closest_player, player_ped, player_coords = utils.entities.get_closest_player(coords, radius, include_player)
if closest_player then
    print("Closest Player ID:", closest_player)
    print("Closest Player Ped:", player_ped)
    print("Closest Player Coordinates:", player_coords)
else
    print("No players found within the specified distance.")
end

--- Direct export
exports.boii_utils:get_closest_player(...)

get_closest_vehicle

Retrieve the closest vehicle.

--- Define coords
local coords = vector3(100.0, 100.0, 20.0)
--- Define radius
local radius = 10.0
--- Specify if players vehicle should be included
local include_player_vehicle = true

--- Utils object
local closest_vehicle, vehicle_coords = utils.entities.get_closest_vehicle(coords, radius, include_player_vehicle)
if closest_vehicle then
    print("Closest Vehicle ID:", closest_vehicle)
    print("Closest Vehicle Coordinates:", vehicle_coords)
else
    print("No vehicles found within the specified distance.")
end

--- Direct export
exports.boii_utils:get_closest_vehicle(...)

get_entities_infront_of_player

Gets entities in front of player within a specified FOV and distance.

--- Define FOV
local FOV = 45.0
--- Define distance
local distance = 10.0

--- Utils object
local entity_in_front = utils.entities.get_entities_in_front_of_player(FOV, distance)
if entity_in_front then
    print("Entity in front of player:", entity_in_front)
else
    print("No entity found in front of the player within the specified FOV and distance.")
end

--- Direct export
exports.boii_utils:get_entities_infront_of_player(...)

get_target_ped

Gets the target ped or nearest ped.

--- Define FOV
local FOV = 45.0
--- Define distance
local distance = 10.0

--- Utils object
local target_ped, target_coords = utils.entities.get_target_ped(PlayerPedId(), FOV, distance)
if target_ped then
    print("Target Ped ID:", target_ped)
    print("Target Ped Coordinates:", target_coords)
else
    print("No target ped found within the specified FOV or distance.")
end

--- Direct export
exports.boii_utils:get_target_ped(...)

Last updated