improvement(server/main): Create a stored query for saving players

This commit is contained in:
Linden
2021-05-28 11:42:22 +10:00
committed by GitHub
parent 8669d816dd
commit b13e44939c
+15 -9
View File
@@ -163,19 +163,25 @@ ESX.TriggerServerCallback = function(name, requestId, source, cb, ...)
end
end
local savePlayers = -1
Citizen.CreateThread(function()
savePlayers = MySQL.Sync.store("UPDATE users SET ? WHERE ?")
end)
ESX.SavePlayer = function(xPlayer, cb)
local asyncTasks = {}
table.insert(asyncTasks, function(cb2)
MySQL.Async.execute('UPDATE users SET accounts = @accounts, job = @job, job_grade = @job_grade, `group` = @group, loadout = @loadout, position = @position, inventory = @inventory WHERE identifier = @identifier', {
['@accounts'] = json.encode(xPlayer.getAccounts(true)),
['@job'] = xPlayer.job.name,
['@job_grade'] = xPlayer.job.grade,
['@group'] = xPlayer.getGroup(),
['@loadout'] = json.encode(xPlayer.getLoadout(true)),
['@position'] = json.encode(xPlayer.getCoords()),
['@identifier'] = xPlayer.getIdentifier(),
['@inventory'] = json.encode(xPlayer.getInventory(true))
MySQL.Async.execute(savePlayers, {
{
['accounts'] = json.encode(xPlayer.getAccounts(true)),
['job'] = xPlayer.job.name,
['job_grade'] = xPlayer.job.grade,
['group'] = xPlayer.getGroup(),
['loadout'] = json.encode(xPlayer.getLoadout(true)),
['position'] = json.encode(xPlayer.getCoords()),
['inventory'] = json.encode(xPlayer.getInventory(true))
}, {['identifier'] = xPlayer.getIdentifier()}
}, function(rowsChanged)
cb2()
end)