mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 09:18:53 +00:00
Tab indent update
This commit is contained in:
+122
-182
@@ -1,226 +1,171 @@
|
||||
local Charset = {}
|
||||
|
||||
for i = 48, 57 do table.insert(Charset, string.char(i)) end
|
||||
for i = 65, 90 do table.insert(Charset, string.char(i)) end
|
||||
for i = 97, 122 do table.insert(Charset, string.char(i)) end
|
||||
|
||||
ESX.Trace = function(str)
|
||||
if Config.EnableDebug then
|
||||
print('ESX> ' .. str)
|
||||
end
|
||||
end
|
||||
|
||||
ESX.GetConfig = function()
|
||||
return Config
|
||||
end
|
||||
|
||||
ESX.GetRandomString = function(length)
|
||||
|
||||
math.randomseed(os.time())
|
||||
|
||||
if length > 0 then
|
||||
return ESX.GetRandomString(length - 1) .. Charset[math.random(1, #Charset)]
|
||||
else
|
||||
return ''
|
||||
end
|
||||
|
||||
if Config.EnableDebug then
|
||||
print('ESX> ' .. str)
|
||||
end
|
||||
end
|
||||
|
||||
ESX.SetTimeout = function(msec, cb)
|
||||
local id = ESX.TimeoutCount + 1
|
||||
|
||||
local id = ESX.TimeoutCount + 1
|
||||
SetTimeout(msec, function()
|
||||
if ESX.CancelledTimeouts[id] then
|
||||
ESX.CancelledTimeouts[id] = nil
|
||||
else
|
||||
cb()
|
||||
end
|
||||
end)
|
||||
|
||||
SetTimeout(msec, function()
|
||||
|
||||
if ESX.CancelledTimeouts[id] then
|
||||
ESX.CancelledTimeouts[id] = nil
|
||||
else
|
||||
cb()
|
||||
end
|
||||
|
||||
end)
|
||||
|
||||
ESX.TimeoutCount = id
|
||||
|
||||
return id
|
||||
ESX.TimeoutCount = id
|
||||
|
||||
return id
|
||||
end
|
||||
|
||||
ESX.ClearTimeout = function(id)
|
||||
ESX.CancelledTimeouts[id] = true
|
||||
ESX.CancelledTimeouts[id] = true
|
||||
end
|
||||
|
||||
ESX.RegisterServerCallback = function(name, cb)
|
||||
ESX.ServerCallbacks[name] = cb
|
||||
ESX.ServerCallbacks[name] = cb
|
||||
end
|
||||
|
||||
ESX.TriggerServerCallback = function(name, requestId, source, cb, ...)
|
||||
|
||||
if ESX.ServerCallbacks[name] ~= nil then
|
||||
ESX.ServerCallbacks[name](source, cb, ...)
|
||||
else
|
||||
print('TriggerServerCallback => [' .. name .. '] does not exist')
|
||||
end
|
||||
|
||||
if ESX.ServerCallbacks[name] ~= nil then
|
||||
ESX.ServerCallbacks[name](source, cb, ...)
|
||||
else
|
||||
print('es_extended: TriggerServerCallback => [' .. name .. '] does not exist')
|
||||
end
|
||||
end
|
||||
|
||||
ESX.SavePlayer = function(xPlayer, cb)
|
||||
local asyncTasks = {}
|
||||
xPlayer.lastPosition = xPlayer.get('coords')
|
||||
|
||||
local asyncTasks = {}
|
||||
xPlayer.lastPosition = xPlayer.get('coords')
|
||||
-- User accounts
|
||||
for i=1, #xPlayer.accounts, 1 do
|
||||
|
||||
-- User accounts
|
||||
for i=1, #xPlayer.accounts, 1 do
|
||||
if ESX.LastPlayerData[xPlayer.source].accounts[xPlayer.accounts[i].name] ~= xPlayer.accounts[i].money then
|
||||
|
||||
if ESX.LastPlayerData[xPlayer.source].accounts[xPlayer.accounts[i].name] ~= xPlayer.accounts[i].money then
|
||||
table.insert(asyncTasks, function(cb)
|
||||
MySQL.Async.execute('UPDATE user_accounts SET `money` = @money WHERE identifier = @identifier AND name = @name',
|
||||
{
|
||||
['@money'] = xPlayer.accounts[i].money,
|
||||
['@identifier'] = xPlayer.identifier,
|
||||
['@name'] = xPlayer.accounts[i].name
|
||||
}, function(rowsChanged)
|
||||
cb()
|
||||
end)
|
||||
end)
|
||||
|
||||
table.insert(asyncTasks, function(cb)
|
||||
ESX.LastPlayerData[xPlayer.source].accounts[xPlayer.accounts[i].name] = xPlayer.accounts[i].money
|
||||
|
||||
MySQL.Async.execute(
|
||||
'UPDATE user_accounts SET `money` = @money WHERE identifier = @identifier AND name = @name',
|
||||
{
|
||||
['@money'] = xPlayer.accounts[i].money,
|
||||
['@identifier'] = xPlayer.identifier,
|
||||
['@name'] = xPlayer.accounts[i].name
|
||||
},
|
||||
function(rowsChanged)
|
||||
cb()
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
end)
|
||||
end
|
||||
|
||||
ESX.LastPlayerData[xPlayer.source].accounts[xPlayer.accounts[i].name] = xPlayer.accounts[i].money
|
||||
-- Inventory items
|
||||
for i=1, #xPlayer.inventory, 1 do
|
||||
|
||||
end
|
||||
if ESX.LastPlayerData[xPlayer.source].items[xPlayer.inventory[i].name] ~= xPlayer.inventory[i].count then
|
||||
|
||||
end
|
||||
table.insert(asyncTasks, function(cb)
|
||||
MySQL.Async.execute('UPDATE user_inventory SET `count` = @count WHERE identifier = @identifier AND item = @item',
|
||||
{
|
||||
['@count'] = xPlayer.inventory[i].count,
|
||||
['@identifier'] = xPlayer.identifier,
|
||||
['@item'] = xPlayer.inventory[i].name
|
||||
}, function(rowsChanged)
|
||||
cb()
|
||||
end)
|
||||
end)
|
||||
|
||||
-- Inventory items
|
||||
for i=1, #xPlayer.inventory, 1 do
|
||||
ESX.LastPlayerData[xPlayer.source].items[xPlayer.inventory[i].name] = xPlayer.inventory[i].count
|
||||
|
||||
if ESX.LastPlayerData[xPlayer.source].items[xPlayer.inventory[i].name] ~= xPlayer.inventory[i].count then
|
||||
end
|
||||
|
||||
table.insert(asyncTasks, function(cb)
|
||||
end
|
||||
|
||||
MySQL.Async.execute(
|
||||
'UPDATE user_inventory SET `count` = @count WHERE identifier = @identifier AND item = @item',
|
||||
{
|
||||
['@count'] = xPlayer.inventory[i].count,
|
||||
['@identifier'] = xPlayer.identifier,
|
||||
['@item'] = xPlayer.inventory[i].name
|
||||
},
|
||||
function(rowsChanged)
|
||||
cb()
|
||||
end
|
||||
)
|
||||
-- Job, loadout and position
|
||||
table.insert(asyncTasks, function(cb)
|
||||
MySQL.Async.execute('UPDATE users SET `job` = @job, `job_grade` = @job_grade, `loadout` = @loadout, `position` = @position WHERE identifier = @identifier',
|
||||
{
|
||||
['@job'] = xPlayer.job.name,
|
||||
['@job_grade'] = xPlayer.job.grade,
|
||||
['@loadout'] = json.encode(xPlayer.loadout),
|
||||
['@position'] = json.encode(xPlayer.lastPosition),
|
||||
['@identifier'] = xPlayer.identifier
|
||||
}, function(rowsChanged)
|
||||
cb()
|
||||
end)
|
||||
end)
|
||||
|
||||
end)
|
||||
Async.parallel(asyncTasks, function(results)
|
||||
RconPrint('[SAVED] ' .. xPlayer.name .. "\n")
|
||||
|
||||
ESX.LastPlayerData[xPlayer.source].items[xPlayer.inventory[i].name] = xPlayer.inventory[i].count
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- Job, loadout and position
|
||||
table.insert(asyncTasks, function(cb)
|
||||
|
||||
MySQL.Async.execute(
|
||||
'UPDATE users SET `job` = @job, `job_grade` = @job_grade, `loadout` = @loadout, `position` = @position WHERE identifier = @identifier',
|
||||
{
|
||||
['@job'] = xPlayer.job.name,
|
||||
['@job_grade'] = xPlayer.job.grade,
|
||||
['@loadout'] = json.encode(xPlayer.loadout),
|
||||
['@position'] = json.encode(xPlayer.lastPosition),
|
||||
['@identifier'] = xPlayer.identifier
|
||||
},
|
||||
function(rowsChanged)
|
||||
cb()
|
||||
end
|
||||
)
|
||||
|
||||
end)
|
||||
|
||||
Async.parallel(asyncTasks, function(results)
|
||||
|
||||
RconPrint('[SAVED] ' .. xPlayer.name .. "\n")
|
||||
|
||||
if cb ~= nil then
|
||||
cb()
|
||||
end
|
||||
|
||||
end)
|
||||
if cb ~= nil then
|
||||
cb()
|
||||
end
|
||||
end)
|
||||
|
||||
end
|
||||
|
||||
ESX.SavePlayers = function(cb)
|
||||
local asyncTasks = {}
|
||||
local xPlayers = ESX.GetPlayers()
|
||||
|
||||
local asyncTasks = {}
|
||||
local xPlayers = ESX.GetPlayers()
|
||||
for i=1, #xPlayers, 1 do
|
||||
table.insert(asyncTasks, function(cb)
|
||||
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
|
||||
ESX.SavePlayer(xPlayer, cb)
|
||||
end)
|
||||
end
|
||||
|
||||
for i=1, #xPlayers, 1 do
|
||||
table.insert(asyncTasks, function(cb)
|
||||
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
|
||||
ESX.SavePlayer(xPlayer, cb)
|
||||
end)
|
||||
end
|
||||
|
||||
Async.parallelLimit(asyncTasks, 8, function(results)
|
||||
|
||||
RconPrint('[SAVED] All players' .. "\n")
|
||||
|
||||
if cb ~= nil then
|
||||
cb()
|
||||
end
|
||||
|
||||
end)
|
||||
Async.parallelLimit(asyncTasks, 8, function(results)
|
||||
RconPrint('[SAVED] All players' .. "\n")
|
||||
|
||||
if cb ~= nil then
|
||||
cb()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
ESX.StartDBSync = function()
|
||||
function saveData()
|
||||
ESX.SavePlayers()
|
||||
SetTimeout(10 * 60 * 1000, saveData)
|
||||
end
|
||||
|
||||
function saveData()
|
||||
ESX.SavePlayers()
|
||||
SetTimeout(10 * 60 * 1000, saveData)
|
||||
end
|
||||
|
||||
SetTimeout(10 * 60 * 1000, saveData)
|
||||
|
||||
SetTimeout(10 * 60 * 1000, saveData)
|
||||
end
|
||||
|
||||
ESX.GetPlayers = function()
|
||||
local sources = {}
|
||||
|
||||
local sources = {}
|
||||
for k,v in pairs(ESX.Players) do
|
||||
table.insert(sources, k)
|
||||
end
|
||||
|
||||
for k,v in pairs(ESX.Players) do
|
||||
table.insert(sources, k)
|
||||
end
|
||||
|
||||
return sources
|
||||
return sources
|
||||
end
|
||||
|
||||
|
||||
ESX.GetPlayerFromId = function(source)
|
||||
return ESX.Players[tonumber(source)]
|
||||
return ESX.Players[tonumber(source)]
|
||||
end
|
||||
|
||||
ESX.GetPlayerFromIdentifier = function(identifier)
|
||||
|
||||
for k,v in pairs(ESX.Players) do
|
||||
if v.identifier == identifier then
|
||||
return v
|
||||
end
|
||||
end
|
||||
|
||||
for k,v in pairs(ESX.Players) do
|
||||
if v.identifier == identifier then
|
||||
return v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ESX.RegisterUsableItem = function(item, cb)
|
||||
ESX.UsableItemsCallbacks[item] = cb
|
||||
ESX.UsableItemsCallbacks[item] = cb
|
||||
end
|
||||
|
||||
ESX.UseItem = function(source, item)
|
||||
ESX.UsableItemsCallbacks[item](source)
|
||||
ESX.UsableItemsCallbacks[item](source)
|
||||
end
|
||||
|
||||
ESX.GetItemLabel = function(item)
|
||||
@@ -230,34 +175,29 @@ ESX.GetItemLabel = function(item)
|
||||
end
|
||||
|
||||
ESX.GetWeaponList = function()
|
||||
return Config.Weapons
|
||||
return Config.Weapons
|
||||
end
|
||||
|
||||
ESX.GetWeaponLabel = function(name)
|
||||
name = string.upper(name)
|
||||
local weapons = ESX.GetWeaponList()
|
||||
|
||||
name = string.upper(name)
|
||||
local weapons = ESX.GetWeaponList()
|
||||
|
||||
for i=1, #weapons, 1 do
|
||||
if weapons[i].name == name then
|
||||
return weapons[i].label
|
||||
end
|
||||
end
|
||||
|
||||
for i=1, #weapons, 1 do
|
||||
if weapons[i].name == name then
|
||||
return weapons[i].label
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ESX.CreatePickup = function(type, name, count, label, player)
|
||||
local pickupId = (ESX.PickupId == 65635 and 0 or ESX.PickupId + 1)
|
||||
|
||||
local pickupId = (ESX.PickupId == 65635 and 0 or ESX.PickupId + 1)
|
||||
ESX.Pickups[pickupId] = {
|
||||
type = type,
|
||||
name = name,
|
||||
count = count
|
||||
}
|
||||
|
||||
ESX.Pickups[pickupId] = {
|
||||
type = type,
|
||||
name = name,
|
||||
count = count
|
||||
}
|
||||
|
||||
TriggerClientEvent('esx:pickup', -1, pickupId, label, player)
|
||||
|
||||
ESX.PickupId = pickupId
|
||||
|
||||
end
|
||||
TriggerClientEvent('esx:pickup', -1, pickupId, label, player)
|
||||
ESX.PickupId = pickupId
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user