From ee3d1d024f64d54ee7a8500a97752fe12609b9dd Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Fri, 28 May 2021 10:29:02 +1000 Subject: [PATCH] improvement(server/main): Use the new xPlayer loop when restarting the resource --- server/main.lua | 54 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/server/main.lua b/server/main.lua index 85f15982..ceba0e04 100644 --- a/server/main.lua +++ b/server/main.lua @@ -7,23 +7,45 @@ AddEventHandler('onResourceStart', function(resourceName) return 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 - 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) + if ESX.GetExtendedPlayers then + for k,v in pairs(xPlayers) do + MySQL.Async.fetchAll('SELECT status FROM users WHERE identifier = @identifier', { + ['@identifier'] = v.identifier + }, function(result) + local data = {} + + if result[1].status then + data = json.decode(result[1].status) + end + + v.set('status', data) + TriggerClientEvent('esx_status:load', k, data) + 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)