mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-04 16:23:21 +00:00
Merge pull request #1119 from CanysLypys/main
Fixing getNearbyPlayers function source definition
This commit is contained in:
@@ -7,15 +7,23 @@ ESX.OneSync = {}
|
|||||||
local function getNearbyPlayers(source, closest, distance, ignore)
|
local function getNearbyPlayers(source, closest, distance, ignore)
|
||||||
local result = {}
|
local result = {}
|
||||||
local count = 0
|
local count = 0
|
||||||
|
local playerPed
|
||||||
|
local playerCoords
|
||||||
if not distance then distance = 100 end
|
if not distance then distance = 100 end
|
||||||
if type(source) == 'number' then
|
if type(source) == 'number' then
|
||||||
source = GetPlayerPed(source)
|
playerPed = GetPlayerPed(source)
|
||||||
|
|
||||||
if not source then
|
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")
|
||||||
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
source = GetEntityCoords(GetPlayerPed(source))
|
playerCoords = GetEntityCoords(playerPed)
|
||||||
|
|
||||||
|
if not playerCoords then
|
||||||
|
error("Received nil value (playerCoords); perhaps source is nil at first place?")
|
||||||
|
return result
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, xPlayer in pairs(ESX.Players) do
|
for _, xPlayer in pairs(ESX.Players) do
|
||||||
@@ -24,16 +32,18 @@ local function getNearbyPlayers(source, closest, distance, ignore)
|
|||||||
local coords = GetEntityCoords(entity)
|
local coords = GetEntityCoords(entity)
|
||||||
|
|
||||||
if not closest then
|
if not closest then
|
||||||
local dist = #(source - coords)
|
local dist = #(playerCoords - coords)
|
||||||
if dist <= distance then
|
if dist <= distance then
|
||||||
count = count + 1
|
count = count + 1
|
||||||
result[count] = { id = xPlayer.source, ped = NetworkGetNetworkIdFromEntity(entity), coords = coords, dist = dist }
|
result[count] = { id = xPlayer.source, ped = NetworkGetNetworkIdFromEntity(entity), coords = coords, dist = dist }
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local dist = #(source - coords)
|
if xPlayer.source ~= source then
|
||||||
if dist <= (result.dist or distance) then
|
local dist = #(playerCoords - coords)
|
||||||
result = { id = xPlayer.source, ped = NetworkGetNetworkIdFromEntity(entity), coords = coords, dist = dist }
|
if dist <= (result.dist or distance) then
|
||||||
end
|
result = { id = xPlayer.source, ped = NetworkGetNetworkIdFromEntity(entity), coords = coords, dist = dist }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user