mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-30 07:01:33 +00:00
Performance, respect EnableHud from ESX
This commit is contained in:
+20
-40
@@ -1,5 +1,4 @@
|
||||
ESX = nil
|
||||
local RegisteredStatus = {}
|
||||
ESX = nil
|
||||
|
||||
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
||||
|
||||
@@ -7,43 +6,30 @@ AddEventHandler('esx:playerLoaded', function(source)
|
||||
local _source = source
|
||||
local xPlayer = ESX.GetPlayerFromId(_source)
|
||||
|
||||
MySQL.Async.fetchAll(
|
||||
'SELECT * FROM users WHERE identifier = @identifier',
|
||||
{
|
||||
MySQL.Async.fetchAll('SELECT status FROM users WHERE identifier = @identifier', {
|
||||
['@identifier'] = xPlayer.identifier
|
||||
},
|
||||
function(result)
|
||||
|
||||
local data = {}
|
||||
|
||||
if result[1].status ~= nil then
|
||||
data = json.decode(result[1].status)
|
||||
end
|
||||
|
||||
xPlayer.set('status', data)
|
||||
|
||||
TriggerClientEvent('esx_status:load', _source, data)
|
||||
}, function(result)
|
||||
local data = {}
|
||||
|
||||
if result[1].status ~= nil then
|
||||
data = json.decode(result[1].status)
|
||||
end
|
||||
)
|
||||
|
||||
xPlayer.set('status', data)
|
||||
TriggerClientEvent('esx_status:load', _source, data)
|
||||
end)
|
||||
end)
|
||||
|
||||
AddEventHandler('esx:playerDropped', function(source)
|
||||
local _source = source
|
||||
local xPlayer = ESX.GetPlayerFromId(_source)
|
||||
|
||||
local data = {}
|
||||
local status = xPlayer.get('status')
|
||||
|
||||
MySQL.Async.execute(
|
||||
'UPDATE users SET status = @status WHERE identifier = @identifier',
|
||||
{
|
||||
['@status'] = json.encode(status),
|
||||
['@identifier'] = xPlayer.identifier
|
||||
}
|
||||
)
|
||||
|
||||
MySQL.Async.execute('UPDATE users SET status = @status WHERE identifier = @identifier', {
|
||||
['@status'] = json.encode(status),
|
||||
['@identifier'] = xPlayer.identifier
|
||||
})
|
||||
end)
|
||||
|
||||
AddEventHandler('esx_status:getStatus', function(playerId, statusName, cb)
|
||||
@@ -56,14 +42,13 @@ AddEventHandler('esx_status:getStatus', function(playerId, statusName, cb)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx_status:update')
|
||||
AddEventHandler('esx_status:update', function(status)
|
||||
local _source = source
|
||||
local xPlayer = ESX.GetPlayerFromId(_source)
|
||||
|
||||
|
||||
if xPlayer ~= nil then
|
||||
xPlayer.set('status', status)
|
||||
end
|
||||
@@ -71,24 +56,19 @@ end)
|
||||
|
||||
function SaveData()
|
||||
local xPlayers = ESX.GetPlayers()
|
||||
|
||||
for i=1, #xPlayers, 1 do
|
||||
|
||||
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',
|
||||
{
|
||||
['@status'] = json.encode(status),
|
||||
['@identifier'] = xPlayer.identifier
|
||||
}
|
||||
)
|
||||
|
||||
MySQL.Async.execute('UPDATE users SET status = @status WHERE identifier = @identifier', {
|
||||
['@status'] = json.encode(status),
|
||||
['@identifier'] = xPlayer.identifier
|
||||
})
|
||||
end
|
||||
|
||||
SetTimeout(10 * 60 * 1000, SaveData)
|
||||
end
|
||||
|
||||
SaveData()
|
||||
SaveData()
|
||||
|
||||
Reference in New Issue
Block a user