improvement(server/main): Use the new xPlayer loop when restarting the resource

This commit is contained in:
Linden
2021-05-28 10:29:02 +10:00
committed by GitHub
parent d876399bab
commit ee3d1d024f
+38 -16
View File
@@ -7,23 +7,45 @@ AddEventHandler('onResourceStart', function(resourceName)
return return
end end
local players = ESX.GetPlayers() local xPlayers
if ESX.GetExtendedPlayers then
xPlayers = ESX.GetExtendedPlayers() -- Retrieve all xPlayer data directly (ESX Legacy)
else
xPlayers = ESX.GetPlayers() -- Retrieves player ids and gets xPlayer data one-by-one (ESX 1.2 support)
end
for _,playerId in ipairs(players) do if ESX.GetExtendedPlayers then
local xPlayer = ESX.GetPlayerFromId(playerId) for k,v in pairs(xPlayers) do
MySQL.Async.fetchAll('SELECT status FROM users WHERE identifier = @identifier', {
MySQL.Async.fetchAll('SELECT status FROM users WHERE identifier = @identifier', { ['@identifier'] = v.identifier
['@identifier'] = xPlayer.identifier }, function(result)
}, function(result) local data = {}
local data = {}
if result[1].status then
if result[1].status then data = json.decode(result[1].status)
data = json.decode(result[1].status) end
end
v.set('status', data)
xPlayer.set('status', data) TriggerClientEvent('esx_status:load', k, data)
TriggerClientEvent('esx_status:load', playerId, data) end)
end) end
else
for _,playerId in ipairs(xPlayers) do
local xPlayer = ESX.GetPlayerFromId(playerId)
MySQL.Async.fetchAll('SELECT status FROM users WHERE identifier = @identifier', {
['@identifier'] = xPlayer.identifier
}, function(result)
local data = {}
if result[1].status then
data = json.decode(result[1].status)
end
xPlayer.set('status', data)
TriggerClientEvent('esx_status:load', playerId, data)
end)
end
end end
end) end)