mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 18:01:25 +00:00
Implemented unregisterStatus and fixed restarting script midgame
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
function CreateStatus(name, default, color, visible, tickCallback)
|
||||
|
||||
|
||||
local self = {}
|
||||
|
||||
self.val = default
|
||||
|
||||
+18
-2
@@ -1,5 +1,12 @@
|
||||
local Status = {}
|
||||
local isPaused = false
|
||||
ESX = nil
|
||||
local Status, isPaused = {}, false
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
while ESX == nil do
|
||||
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
||||
Citizen.Wait(0)
|
||||
end
|
||||
end)
|
||||
|
||||
function GetStatusData(minimal)
|
||||
local status = {}
|
||||
@@ -31,6 +38,15 @@ AddEventHandler('esx_status:registerStatus', function(name, default, color, visi
|
||||
table.insert(Status, status)
|
||||
end)
|
||||
|
||||
AddEventHandler('esx_status:unregisterStatus', function(name)
|
||||
for k,v in ipairs(Status) do
|
||||
if v.name == name then
|
||||
table.remove(Status, k)
|
||||
break
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent('esx_status:load')
|
||||
AddEventHandler('esx_status:load', function(status)
|
||||
for i=1, #Status, 1 do
|
||||
|
||||
+27
-11
@@ -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', {
|
||||
|
||||
Reference in New Issue
Block a user