Skip to content
This repository was archived by the owner on Apr 28, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions imports/getClosestPlayer/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
---@return vector3? playerCoords
function lib.getClosestPlayer(coords, maxDistance, includePlayer)
local players = GetActivePlayers()
local closestId, closestPed, closestCoords
local closestId, closestPed, closestCoords, closestVehicle
maxDistance = maxDistance or 2.0

for i = 1, #players do
Expand All @@ -23,18 +23,23 @@ function lib.getClosestPlayer(coords, maxDistance, includePlayer)
if playerId ~= cache.playerId or includePlayer then
local playerPed = GetPlayerPed(playerId)
local playerCoords = GetEntityCoords(playerPed)

local vehicle = GetVehiclePedIsIn(playerPed, false)
local playerCoords = vehicle == 0 and GetEntityCoords(playerPed) or GetWorldPositionOfEntityBone(playerPed, 0)

local distance = #(coords - playerCoords)

if distance < maxDistance then
maxDistance = distance
closestId = playerId
closestPed = playerPed
closestCoords = playerCoords
closestVehicle = vehicle
end
end
end

return closestId, closestPed, closestCoords
return closestId, closestPed, closestCoords, closestVehicle
end

return lib.getClosestPlayer
6 changes: 5 additions & 1 deletion imports/getNearbyPlayers/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ function lib.getNearbyPlayers(coords, maxDistance, includePlayer)

if playerId ~= cache.playerId or includePlayer then
local playerPed = GetPlayerPed(playerId)
local playerCoords = GetEntityCoords(playerPed)

local vehicle = GetVehiclePedIsIn(playerPed, false)
local playerCoords = vehicle == 0 and GetEntityCoords(playerPed) or GetWorldPositionOfEntityBone(playerPed, 0)

local distance = #(coords - playerCoords)

if distance < maxDistance then
Expand All @@ -30,6 +33,7 @@ function lib.getNearbyPlayers(coords, maxDistance, includePlayer)
id = playerId,
ped = playerPed,
coords = playerCoords,
vehicle = vehicle
}
end
end
Expand Down