From 30d497500d0ac64e5cdb67c77517a9ae4f09683b Mon Sep 17 00:00:00 2001 From: Canis_Lupus <56067968+CanysLypys@users.noreply.github.com> Date: Fri, 21 Jul 2023 00:50:16 +0200 Subject: [PATCH] Fixing getNearbyPlayers source definition (updated) The requested features are now included. playerPed and playerCoords do have now two different locals for better orientation and included nil checking for the function. --- [core]/es_extended/server/onesync.lua | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/[core]/es_extended/server/onesync.lua b/[core]/es_extended/server/onesync.lua index fcb249a2..19fb2eab 100644 --- a/[core]/es_extended/server/onesync.lua +++ b/[core]/es_extended/server/onesync.lua @@ -7,15 +7,21 @@ ESX.OneSync = {} local function getNearbyPlayers(source, closest, distance, ignore) local result = {} local count = 0 + local playerPed + local playerCoords if not distance then distance = 100 end if type(source) == 'number' then - source = GetPlayerPed(source) - + playerPed = GetPlayerPed(source) + if not source then - error("Received invalid first argument (source); should be playerId or vector3 coordinates") + error("Received invalid first argument (source); should be playerId") end - source = GetEntityCoords(source) + playerCoords = GetEntityCoords(playerPed) + + if not playerCoords then + error("Received nil value (playerCoords); perhaps source is nil at first place?") + end end for _, xPlayer in pairs(ESX.Players) do @@ -24,13 +30,13 @@ local function getNearbyPlayers(source, closest, distance, ignore) local coords = GetEntityCoords(entity) if not closest then - local dist = #(source - coords) + local dist = #(playerCoords - coords) if dist <= distance then count = count + 1 result[count] = { id = xPlayer.source, ped = NetworkGetNetworkIdFromEntity(entity), coords = coords, dist = dist } end else - local dist = #(source - coords) + local dist = #(playerCoords - coords) if dist <= (result.dist or distance) then result = { id = xPlayer.source, ped = NetworkGetNetworkIdFromEntity(entity), coords = coords, dist = dist } end