refactor(es_extended/server/functions): refactor ESX.GetExtendedPlayers

This commit is contained in:
Ilias Rbayti
2024-11-23 01:00:47 +01:00
parent 4feda3ba08
commit 3a61ae5310
+16 -14
View File
@@ -276,15 +276,15 @@ end
ESX.GetPlayers = GetPlayers
local function checkTable(key, val, player, xPlayers)
local function checkTable(key, val, xPlayer, xPlayers)
for valIndex = 1, #val do
local value = val[valIndex]
if not xPlayers[value] then
xPlayers[value] = {}
end
if (key == "job" and player.job.name == value) or player[key] == value then
xPlayers[value][#xPlayers[value] + 1] = player
if (key == "job" and xPlayer.job.name == value) or xPlayer[key] == value then
xPlayers[value][#xPlayers[value] + 1] = xPlayer
end
end
end
@@ -293,20 +293,22 @@ end
---@param val? string|table
---@return table
function ESX.GetExtendedPlayers(key, val)
if not key then
return ESX.Table.ToArray(ESX.Players)
end
local xPlayers = {}
if type(val) == "table" then
for _, v in pairs(ESX.Players) do
checkTable(key, val, v, xPlayers)
for i, xPlayer in pairs(ESX.Players) do
checkTable(key, val, xPlayer, xPlayers)
end
else
for _, v in pairs(ESX.Players) do
if key then
if (key == "job" and v.job.name == val) or v[key] == val then
xPlayers[#xPlayers + 1] = v
end
else
xPlayers[#xPlayers + 1] = v
end
return xPlayers
end
for i, xPlayer in pairs(ESX.Players) do
if (key == "job" and xPlayer.job.name == val) or xPlayer[key] == val then
xPlayers[#xPlayers + 1] = xPlayer
end
end