Merge pull request #1078 from MoskalykA/simplify-GetExtendedPlayers

refactor: simplify the `GetExtendedPlayers` function
This commit is contained in:
Gellipapa
2023-06-27 22:18:23 +02:00
committed by GitHub
+29 -11
View File
@@ -221,18 +221,36 @@ end
ESX.GetPlayers = GetPlayers
local function checkTable(key, val, player, 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
end
end
end
function ESX.GetExtendedPlayers(key, val)
local xPlayers = {}
for k, 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
end
return xPlayers
if not key then return ESX.Players end
local xPlayers = {}
if type(val) == "table" then
for _, v in pairs(ESX.Players) do
checkTable(key, val, v, xPlayers)
end
else
for _, v in pairs(ESX.Players) do
if (key == 'job' and v.job.name == val) or v[key] == val then
xPlayers[#xPlayers + 1] = v
end
end
end
return xPlayers
end
function ESX.GetPlayerFromId(source)