Save accounts as encoded json text, migrate script found in development discord

This commit is contained in:
ElPumpo
2020-03-06 20:41:37 +01:00
parent e31077efbb
commit 3ba2ed150f
5 changed files with 68 additions and 139 deletions
+7 -25
View File
@@ -150,7 +150,7 @@ ESX.RegisterServerCallback = function(name, cb)
end
ESX.TriggerServerCallback = function(name, requestId, source, cb, ...)
if ESX.ServerCallbacks[name] ~= nil then
if ESX.ServerCallbacks[name] then
ESX.ServerCallbacks[name](source, cb, ...)
else
print(('[es_extended] [^3WARNING^7] Server callback "%s" does not exist. Make sure that the server sided file really is loading, an error in that file might cause it to not load.'):format(name))
@@ -160,26 +160,9 @@ end
ESX.SavePlayer = function(xPlayer, cb)
local asyncTasks = {}
-- User accounts
for k,v in ipairs(xPlayer.accounts) do
if ESX.LastPlayerData[xPlayer.source].accounts[v.name] ~= v.money then
table.insert(asyncTasks, function(cb)
MySQL.Async.execute('UPDATE user_accounts SET money = @money WHERE identifier = @identifier AND name = @name', {
['@money'] = v.money,
['@identifier'] = xPlayer.identifier,
['@name'] = v.name
}, function(rowsChanged)
cb()
end)
end)
ESX.LastPlayerData[xPlayer.source].accounts[v.name] = v.money
end
end
-- Job, loadout, inventory and position
table.insert(asyncTasks, function(cb)
MySQL.Async.execute('UPDATE users SET job = @job, job_grade = @job_grade, loadout = @loadout, position = @position, inventory = @inventory WHERE identifier = @identifier', {
MySQL.Async.execute('UPDATE users SET accounts = @accounts, job = @job, job_grade = @job_grade, loadout = @loadout, position = @position, inventory = @inventory WHERE identifier = @identifier', {
['@accounts'] = json.encode(xPlayer.getAccounts(true)),
['@job'] = xPlayer.job.name,
['@job_grade'] = xPlayer.job.grade,
['@loadout'] = json.encode(xPlayer.getLoadout(true)),
@@ -194,15 +177,14 @@ ESX.SavePlayer = function(xPlayer, cb)
Async.parallel(asyncTasks, function(results)
print(('[es_extended] [^2INFO^7] Saved player "%s^7"'):format(xPlayer.getName()))
if cb ~= nil then
if cb then
cb()
end
end)
end
ESX.SavePlayers = function(cb)
local asyncTasks = {}
local xPlayers = ESX.GetPlayers()
local xPlayers, asyncTasks = ESX.GetPlayers(), {}
for i=1, #xPlayers, 1 do
table.insert(asyncTasks, function(cb)
@@ -213,7 +195,7 @@ ESX.SavePlayers = function(cb)
Async.parallelLimit(asyncTasks, 8, function(results)
print(('[es_extended] [^2INFO^7] Saved %s player(s)'):format(#xPlayers))
if cb ~= nil then
if cb then
cb()
end
end)
@@ -259,7 +241,7 @@ ESX.UseItem = function(source, item)
end
ESX.GetItemLabel = function(item)
if ESX.Items[item] ~= nil then
if ESX.Items[item] then
return ESX.Items[item].label
end
end