diff --git a/client/functions.lua b/client/functions.lua index df20632..6e2b4a4 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -10,6 +10,27 @@ function NDCore.Functions.GetCharacters() return NDCore.Characters end + +function NDCore.Functions.GetPlayersFromCoords(distance, coords) + if coords then + coords = type(coords) == 'table' and vec3(coords.x, coords.y, coords.z) or coords + else + coords = GetEntityCoords(PlayerPedId()) + end + distance = distance or 5 + local closePlayers = {} + local players = GetActivePlayers() + for _, player in ipairs(players) do + local target = GetPlayerPed(player) + local targetCoords = GetEntityCoords(target) + local targetdistance = #(targetCoords - coords) + if targetdistance <= distance then + closePlayers[#closePlayers + 1] = player + end + end + return closePlayers +end + -- Callbacks are licensed under LGPL v3.0 -- NDCore.callback = {} @@ -56,4 +77,4 @@ function NDCore.callback.register(name, callback) RegisterNetEvent(("ND:%s_cb"):format(name), function(key, ...) TriggerServerEvent("ND:callbacks", key, callback(...)) end) -end \ No newline at end of file +end