diff --git a/[esx]/es_extended/server/functions.lua b/[esx]/es_extended/server/functions.lua index a1d3977c..3e61fee7 100644 --- a/[esx]/es_extended/server/functions.lua +++ b/[esx]/es_extended/server/functions.lua @@ -196,21 +196,50 @@ ESX.SavePlayer = function(xPlayer, cb) end ESX.SavePlayers = function(cb) - local xPlayers, asyncTasks = ESX.GetPlayers(), {} + local xPlayers = ESX.GetExtendedPlayers() + print("ESX.GetPlayers executed in es_extended saveplayers") + + local selectListWithNames = "SELECT '%s' AS identifier, '%s' AS new_accounts, '%s' AS new_job, %s AS new_job_grade, '%s' AS new_group, '%s' AS new_loadout, '%s' AS new_position, '%s' AS new_inventory " + local selectListNoNames = "SELECT '%s', '%s', '%s' , %s, '%s', '%s', '%s', '%s' " + + if #xPlayers > 0 then + local updateCommand = 'UPDATE users u JOIN (' + + local selectList = selectListNoNames + local first = true + for k, xPlayer in pairs(xPlayers) do + if first == false then + updateCommand = updateCommand .. ' UNION ' + else + selectList = selectListWithNames + end + + updateCommand = updateCommand .. string.format(selectList, + xPlayer.identifier, + json.encode(xPlayer.getAccounts(true)), + xPlayer.job.name, + xPlayer.job.grade, + xPlayer.getGroup(), + json.encode(xPlayer.getLoadout(true)), + json.encode(xPlayer.getCoords()), + json.encode(xPlayer.getInventory(true)) + ) + + first = false + end + + updateCommand = updateCommand .. ' ) vals ON u.identifier = vals.identifier SET accounts = new_accounts, job = new_job, job_grade = new_job_grade, `group` = new_group, loadout = new_loadout, `position` = new_position, inventory = new_inventory' + + MySQL.Async.execute(updateCommand) + + print(('[es_extended] [^2INFO^7] Saved %s player(s)'):format(#xPlayers)) - for i=1, #xPlayers, 1 do - table.insert(asyncTasks, function(cb2) - local xPlayer = ESX.GetPlayerFromId(xPlayers[i]) - ESX.SavePlayer(xPlayer, cb2) - end) end - Async.parallelLimit(asyncTasks, 8, function(results) - print(('[^2INFO^7] Saved ^5%s^0 player(s)'):format(#xPlayers)) - if cb then - cb() - end - end) + if cb then + cb() + end + end ESX.StartDBSync = function()