Implemented unregisterStatus and fixed restarting script midgame

This commit is contained in:
ElPumpo
2019-06-08 13:11:28 +02:00
parent 4b46663c96
commit 77a7080e38
3 changed files with 46 additions and 14 deletions
+27 -11
View File
@@ -2,28 +2,45 @@ ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
AddEventHandler('esx:playerLoaded', function(source)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
Citizen.CreateThread(function()
Citizen.Wait(1000)
local players = ESX.GetPlayers()
MySQL.Async.fetchAll('SELECT status FROM users WHERE identifier = @identifier', {
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)
end
end)
AddEventHandler('esx:playerLoaded', function(playerId, xPlayer)
MySQL.Async.fetchAll('SELECT status FROM users WHERE identifier = @identifier', {
['@identifier'] = xPlayer.identifier
}, function(result)
local data = {}
if result[1].status ~= nil then
if result[1].status then
data = json.decode(result[1].status)
end
xPlayer.set('status', data)
TriggerClientEvent('esx_status:load', _source, data)
TriggerClientEvent('esx_status:load', playerId, data)
end)
end)
AddEventHandler('esx:playerDropped', function(source)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local data = {}
AddEventHandler('esx:playerDropped', function(playerId, reason)
local xPlayer = ESX.GetPlayerFromId(playerId)
local status = xPlayer.get('status')
MySQL.Async.execute('UPDATE users SET status = @status WHERE identifier = @identifier', {
@@ -58,7 +75,6 @@ function SaveData()
for i=1, #xPlayers, 1 do
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
local data = {}
local status = xPlayer.get('status')
MySQL.Async.execute('UPDATE users SET status = @status WHERE identifier = @identifier', {