From 30ac1269497020baaf8246f001e3e1d6ce2c3034 Mon Sep 17 00:00:00 2001 From: Dark3581 <67527731+Dark3581@users.noreply.github.com> Date: Tue, 27 Dec 2022 12:33:36 -0800 Subject: [PATCH 1/3] GetPlayersFromCoords - Converted from qb/esx gets all players within an area --- client/functions.lua | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/client/functions.lua b/client/functions.lua index df20632..12fcc11 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -10,6 +10,28 @@ function NDCore.Functions.GetCharacters() return NDCore.Characters end + +function NDCore.Functions.GetPlayersFromCoords(coords, distance) + local players = GetActivePlayers() + local ped = PlayerPedId() + if coords then + coords = type(coords) == 'table' and vec3(coords.x, coords.y, coords.z) or coords + else + coords = GetEntityCoords(ped) + end + distance = distance or 5 + local closePlayers = {} + for _, player in pairs(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 +78,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 From 4551db736cae3b602f51b9d98b0969fa6f806104 Mon Sep 17 00:00:00 2001 From: Dark3581 <67527731+Dark3581@users.noreply.github.com> Date: Tue, 3 Jan 2023 18:18:54 -0800 Subject: [PATCH 2/3] requested changes --- client/functions.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/client/functions.lua b/client/functions.lua index 12fcc11..bf32766 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -11,16 +11,15 @@ function NDCore.Functions.GetCharacters() end -function NDCore.Functions.GetPlayersFromCoords(coords, distance) - local players = GetActivePlayers() - local ped = PlayerPedId() +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(ped) + coords = GetEntityCoords(PlayerPedId()) end distance = distance or 5 local closePlayers = {} + local players = GetActivePlayers() for _, player in pairs(players) do local target = GetPlayerPed(player) local targetCoords = GetEntityCoords(target) From a5b297e6f8f8e554827c6dae8eae59acc9c1fe88 Mon Sep 17 00:00:00 2001 From: Dark3581 <67527731+Dark3581@users.noreply.github.com> Date: Tue, 3 Jan 2023 18:24:38 -0800 Subject: [PATCH 3/3] ipair --- client/functions.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/functions.lua b/client/functions.lua index bf32766..6e2b4a4 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -20,7 +20,7 @@ function NDCore.Functions.GetPlayersFromCoords(distance, coords) distance = distance or 5 local closePlayers = {} local players = GetActivePlayers() - for _, player in pairs(players) do + for _, player in ipairs(players) do local target = GetPlayerPed(player) local targetCoords = GetEntityCoords(target) local targetdistance = #(targetCoords - coords)