mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-04 16:23:21 +00:00
improvement(server/main): Use the new xPlayer loop when restarting the resource
This commit is contained in:
+38
-16
@@ -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)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user