mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-03 11:48:53 +00:00
es_extended -> formatting
This commit is contained in:
@@ -13,115 +13,101 @@ Core.PickupId = 0
|
||||
Core.PlayerFunctionOverrides = {}
|
||||
|
||||
AddEventHandler('esx:getSharedObject', function(cb)
|
||||
cb(ESX)
|
||||
cb(ESX)
|
||||
end)
|
||||
|
||||
exports('getSharedObject', function()
|
||||
return ESX
|
||||
return ESX
|
||||
end)
|
||||
|
||||
if GetResourceState('ox_inventory') ~= 'missing' then
|
||||
Config.OxInventory = true
|
||||
Config.PlayerFunctionOverride = 'OxInventory'
|
||||
SetConvarReplicated('inventory:framework', 'esx')
|
||||
SetConvarReplicated('inventory:weight', Config.MaxWeight * 1000)
|
||||
Config.OxInventory = true
|
||||
Config.PlayerFunctionOverride = 'OxInventory'
|
||||
SetConvarReplicated('inventory:framework', 'esx')
|
||||
SetConvarReplicated('inventory:weight', Config.MaxWeight * 1000)
|
||||
end
|
||||
|
||||
local function StartDBSync()
|
||||
CreateThread(function()
|
||||
while true do
|
||||
Wait(10 * 60 * 1000)
|
||||
Core.SavePlayers()
|
||||
end
|
||||
end)
|
||||
CreateThread(function()
|
||||
while true do
|
||||
Wait(10 * 60 * 1000)
|
||||
Core.SavePlayers()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
MySQL.ready(function()
|
||||
if not Config.OxInventory then
|
||||
local items = MySQL.query.await('SELECT * FROM items')
|
||||
for k, v in ipairs(items) do
|
||||
ESX.Items[v.name] = {
|
||||
label = v.label,
|
||||
weight = v.weight,
|
||||
rare = v.rare,
|
||||
canRemove = v.can_remove
|
||||
}
|
||||
end
|
||||
else
|
||||
TriggerEvent('__cfx_export_ox_inventory_Items', function(ref)
|
||||
if ref then
|
||||
ESX.Items = ref()
|
||||
end
|
||||
end)
|
||||
if not Config.OxInventory then
|
||||
local items = MySQL.query.await('SELECT * FROM items')
|
||||
for k, v in ipairs(items) do
|
||||
ESX.Items[v.name] = {label = v.label, weight = v.weight, rare = v.rare, canRemove = v.can_remove}
|
||||
end
|
||||
else
|
||||
TriggerEvent('__cfx_export_ox_inventory_Items', function(ref)
|
||||
if ref then
|
||||
ESX.Items = ref()
|
||||
end
|
||||
end)
|
||||
|
||||
AddEventHandler('ox_inventory:itemList', function(items)
|
||||
ESX.Items = items
|
||||
end)
|
||||
AddEventHandler('ox_inventory:itemList', function(items)
|
||||
ESX.Items = items
|
||||
end)
|
||||
|
||||
while not next(ESX.Items) do Wait(0) end
|
||||
end
|
||||
while not next(ESX.Items) do
|
||||
Wait(0)
|
||||
end
|
||||
end
|
||||
|
||||
local Jobs = {}
|
||||
local jobs = MySQL.query.await('SELECT * FROM jobs')
|
||||
local Jobs = {}
|
||||
local jobs = MySQL.query.await('SELECT * FROM jobs')
|
||||
|
||||
for _, v in ipairs(jobs) do
|
||||
Jobs[v.name] = v
|
||||
Jobs[v.name].grades = {}
|
||||
end
|
||||
for _, v in ipairs(jobs) do
|
||||
Jobs[v.name] = v
|
||||
Jobs[v.name].grades = {}
|
||||
end
|
||||
|
||||
local jobGrades = MySQL.query.await('SELECT * FROM job_grades')
|
||||
local jobGrades = MySQL.query.await('SELECT * FROM job_grades')
|
||||
|
||||
for _, v in ipairs(jobGrades) do
|
||||
if Jobs[v.job_name] then
|
||||
Jobs[v.job_name].grades[tostring(v.grade)] = v
|
||||
else
|
||||
print(('[^3WARNING^7] Ignoring job grades for ^5"%s"^0 due to missing job'):format(v.job_name))
|
||||
end
|
||||
end
|
||||
for _, v in ipairs(jobGrades) do
|
||||
if Jobs[v.job_name] then
|
||||
Jobs[v.job_name].grades[tostring(v.grade)] = v
|
||||
else
|
||||
print(('[^3WARNING^7] Ignoring job grades for ^5"%s"^0 due to missing job'):format(v.job_name))
|
||||
end
|
||||
end
|
||||
|
||||
for _, v in pairs(Jobs) do
|
||||
if ESX.Table.SizeOf(v.grades) == 0 then
|
||||
Jobs[v.name] = nil
|
||||
print(('[^3WARNING^7] Ignoring job ^5"%s"^0 due to no job grades found'):format(v.name))
|
||||
end
|
||||
end
|
||||
for _, v in pairs(Jobs) do
|
||||
if ESX.Table.SizeOf(v.grades) == 0 then
|
||||
Jobs[v.name] = nil
|
||||
print(('[^3WARNING^7] Ignoring job ^5"%s"^0 due to no job grades found'):format(v.name))
|
||||
end
|
||||
end
|
||||
|
||||
if not Jobs then
|
||||
-- Fallback data, if no jobs exist
|
||||
ESX.Jobs['unemployed'] = {
|
||||
label = 'Unemployed',
|
||||
grades = {
|
||||
['0'] = {
|
||||
grade = 0,
|
||||
label = 'Unemployed',
|
||||
salary = 200,
|
||||
onDuty = false,
|
||||
skin_male = {},
|
||||
skin_female = {}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
ESX.Jobs = Jobs
|
||||
end
|
||||
if not Jobs then
|
||||
-- Fallback data, if no jobs exist
|
||||
ESX.Jobs['unemployed'] = {label = 'Unemployed',
|
||||
grades = {['0'] = {grade = 0, label = 'Unemployed', salary = 200, skin_male = {}, skin_female = {}}}}
|
||||
else
|
||||
ESX.Jobs = Jobs
|
||||
end
|
||||
|
||||
print('[^2INFO^7] ESX ^5Legacy^0 initialized')
|
||||
StartDBSync()
|
||||
StartPayCheck()
|
||||
print('[^2INFO^7] ESX ^5Legacy^0 initialized')
|
||||
StartDBSync()
|
||||
StartPayCheck()
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx:clientLog')
|
||||
AddEventHandler('esx:clientLog', function(msg)
|
||||
if Config.EnableDebug then
|
||||
print(('[^2TRACE^7] %s^7'):format(msg))
|
||||
end
|
||||
if Config.EnableDebug then
|
||||
print(('[^2TRACE^7] %s^7'):format(msg))
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx:triggerServerCallback')
|
||||
AddEventHandler('esx:triggerServerCallback', function(name, requestId, ...)
|
||||
local playerId = source
|
||||
local playerId = source
|
||||
|
||||
ESX.TriggerServerCallback(name, requestId, playerId, function(...)
|
||||
TriggerClientEvent('esx:serverCallback', playerId, requestId, ...)
|
||||
end, ...)
|
||||
ESX.TriggerServerCallback(name, requestId, playerId, function(...)
|
||||
TriggerClientEvent('esx:serverCallback', playerId, requestId, ...)
|
||||
end, ...)
|
||||
end)
|
||||
|
||||
@@ -1,414 +1,403 @@
|
||||
function ESX.Trace(msg)
|
||||
if Config.EnableDebug then
|
||||
print(('[^2TRACE^7] %s^7'):format(msg))
|
||||
end
|
||||
if Config.EnableDebug then
|
||||
print(('[^2TRACE^7] %s^7'):format(msg))
|
||||
end
|
||||
end
|
||||
|
||||
function ESX.SetTimeout(msec, cb)
|
||||
local id = Core.TimeoutCount + 1
|
||||
local id = Core.TimeoutCount + 1
|
||||
|
||||
SetTimeout(msec, function()
|
||||
if Core.CancelledTimeouts[id] then
|
||||
Core.CancelledTimeouts[id] = nil
|
||||
else
|
||||
cb()
|
||||
end
|
||||
end)
|
||||
SetTimeout(msec, function()
|
||||
if Core.CancelledTimeouts[id] then
|
||||
Core.CancelledTimeouts[id] = nil
|
||||
else
|
||||
cb()
|
||||
end
|
||||
end)
|
||||
|
||||
Core.TimeoutCount = id
|
||||
Core.TimeoutCount = id
|
||||
|
||||
return id
|
||||
return id
|
||||
end
|
||||
|
||||
function ESX.RegisterCommand(name, group, cb, allowConsole, suggestion)
|
||||
if type(name) == 'table' then
|
||||
for k,v in ipairs(name) do
|
||||
ESX.RegisterCommand(v, group, cb, allowConsole, suggestion)
|
||||
end
|
||||
if type(name) == 'table' then
|
||||
for k, v in ipairs(name) do
|
||||
ESX.RegisterCommand(v, group, cb, allowConsole, suggestion)
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if Core.RegisteredCommands[name] then
|
||||
print(('[^3WARNING^7] Command ^5"%s" ^7already registered, overriding command'):format(name))
|
||||
if Core.RegisteredCommands[name] then
|
||||
print(('[^3WARNING^7] Command ^5"%s" ^7already registered, overriding command'):format(name))
|
||||
|
||||
if Core.RegisteredCommands[name].suggestion then
|
||||
TriggerClientEvent('chat:removeSuggestion', -1, ('/%s'):format(name))
|
||||
end
|
||||
end
|
||||
if Core.RegisteredCommands[name].suggestion then
|
||||
TriggerClientEvent('chat:removeSuggestion', -1, ('/%s'):format(name))
|
||||
end
|
||||
end
|
||||
|
||||
if suggestion then
|
||||
if not suggestion.arguments then suggestion.arguments = {} end
|
||||
if not suggestion.help then suggestion.help = '' end
|
||||
if suggestion then
|
||||
if not suggestion.arguments then
|
||||
suggestion.arguments = {}
|
||||
end
|
||||
if not suggestion.help then
|
||||
suggestion.help = ''
|
||||
end
|
||||
|
||||
TriggerClientEvent('chat:addSuggestion', -1, ('/%s'):format(name), suggestion.help, suggestion.arguments)
|
||||
end
|
||||
TriggerClientEvent('chat:addSuggestion', -1, ('/%s'):format(name), suggestion.help, suggestion.arguments)
|
||||
end
|
||||
|
||||
Core.RegisteredCommands[name] = {group = group, cb = cb, allowConsole = allowConsole, suggestion = suggestion}
|
||||
Core.RegisteredCommands[name] = {group = group, cb = cb, allowConsole = allowConsole, suggestion = suggestion}
|
||||
|
||||
RegisterCommand(name, function(playerId, args, rawCommand)
|
||||
local command = Core.RegisteredCommands[name]
|
||||
RegisterCommand(name, function(playerId, args, rawCommand)
|
||||
local command = Core.RegisteredCommands[name]
|
||||
|
||||
if not command.allowConsole and playerId == 0 then
|
||||
print(('[^3WARNING^7] ^5%s'):format(_U('commanderror_console')))
|
||||
else
|
||||
local xPlayer, error = ESX.Players[playerId], nil
|
||||
if not command.allowConsole and playerId == 0 then
|
||||
print(('[^3WARNING^7] ^5%s'):format(_U('commanderror_console')))
|
||||
else
|
||||
local xPlayer, error = ESX.Players[playerId], nil
|
||||
|
||||
if command.suggestion then
|
||||
if command.suggestion.validate then
|
||||
if #args ~= #command.suggestion.arguments then
|
||||
error = _U('commanderror_argumentmismatch', #args, #command.suggestion.arguments)
|
||||
end
|
||||
end
|
||||
if command.suggestion then
|
||||
if command.suggestion.validate then
|
||||
if #args ~= #command.suggestion.arguments then
|
||||
error = _U('commanderror_argumentmismatch', #args, #command.suggestion.arguments)
|
||||
end
|
||||
end
|
||||
|
||||
if not error and command.suggestion.arguments then
|
||||
local newArgs = {}
|
||||
if not error and command.suggestion.arguments then
|
||||
local newArgs = {}
|
||||
|
||||
for k,v in ipairs(command.suggestion.arguments) do
|
||||
if v.type then
|
||||
if v.type == 'number' then
|
||||
local newArg = tonumber(args[k])
|
||||
for k, v in ipairs(command.suggestion.arguments) do
|
||||
if v.type then
|
||||
if v.type == 'number' then
|
||||
local newArg = tonumber(args[k])
|
||||
|
||||
if newArg then
|
||||
newArgs[v.name] = newArg
|
||||
else
|
||||
error = _U('commanderror_argumentmismatch_number', k)
|
||||
end
|
||||
elseif v.type == 'player' or v.type == 'playerId' then
|
||||
local targetPlayer = tonumber(args[k])
|
||||
if newArg then
|
||||
newArgs[v.name] = newArg
|
||||
else
|
||||
error = _U('commanderror_argumentmismatch_number', k)
|
||||
end
|
||||
elseif v.type == 'player' or v.type == 'playerId' then
|
||||
local targetPlayer = tonumber(args[k])
|
||||
|
||||
if args[k] == 'me' then targetPlayer = playerId end
|
||||
if args[k] == 'me' then
|
||||
targetPlayer = playerId
|
||||
end
|
||||
|
||||
if targetPlayer then
|
||||
local xTargetPlayer = ESX.GetPlayerFromId(targetPlayer)
|
||||
if targetPlayer then
|
||||
local xTargetPlayer = ESX.GetPlayerFromId(targetPlayer)
|
||||
|
||||
if xTargetPlayer then
|
||||
if v.type == 'player' then
|
||||
newArgs[v.name] = xTargetPlayer
|
||||
else
|
||||
newArgs[v.name] = targetPlayer
|
||||
end
|
||||
else
|
||||
error = _U('commanderror_invalidplayerid')
|
||||
end
|
||||
else
|
||||
error = _U('commanderror_argumentmismatch_number', k)
|
||||
end
|
||||
elseif v.type == 'string' then
|
||||
newArgs[v.name] = args[k]
|
||||
elseif v.type == 'item' then
|
||||
if ESX.Items[args[k]] then
|
||||
newArgs[v.name] = args[k]
|
||||
else
|
||||
error = _U('commanderror_invaliditem')
|
||||
end
|
||||
elseif v.type == 'weapon' then
|
||||
if ESX.GetWeapon(args[k]) then
|
||||
newArgs[v.name] = string.upper(args[k])
|
||||
else
|
||||
error = _U('commanderror_invalidweapon')
|
||||
end
|
||||
elseif v.type == 'any' then
|
||||
newArgs[v.name] = args[k]
|
||||
end
|
||||
end
|
||||
|
||||
if v.validate == false then
|
||||
error = nil
|
||||
end
|
||||
if xTargetPlayer then
|
||||
if v.type == 'player' then
|
||||
newArgs[v.name] = xTargetPlayer
|
||||
else
|
||||
newArgs[v.name] = targetPlayer
|
||||
end
|
||||
else
|
||||
error = _U('commanderror_invalidplayerid')
|
||||
end
|
||||
else
|
||||
error = _U('commanderror_argumentmismatch_number', k)
|
||||
end
|
||||
elseif v.type == 'string' then
|
||||
newArgs[v.name] = args[k]
|
||||
elseif v.type == 'item' then
|
||||
if ESX.Items[args[k]] then
|
||||
newArgs[v.name] = args[k]
|
||||
else
|
||||
error = _U('commanderror_invaliditem')
|
||||
end
|
||||
elseif v.type == 'weapon' then
|
||||
if ESX.GetWeapon(args[k]) then
|
||||
newArgs[v.name] = string.upper(args[k])
|
||||
else
|
||||
error = _U('commanderror_invalidweapon')
|
||||
end
|
||||
elseif v.type == 'any' then
|
||||
newArgs[v.name] = args[k]
|
||||
end
|
||||
end
|
||||
|
||||
if error then break end
|
||||
end
|
||||
if v.validate == false then
|
||||
error = nil
|
||||
end
|
||||
|
||||
args = newArgs
|
||||
end
|
||||
end
|
||||
if error then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if error then
|
||||
if playerId == 0 then
|
||||
print(('[^3WARNING^7] %s^7'):format(error))
|
||||
else
|
||||
xPlayer.showNotification(error)
|
||||
end
|
||||
else
|
||||
cb(xPlayer or false, args, function(msg)
|
||||
if playerId == 0 then
|
||||
print(('[^3WARNING^7] %s^7'):format(msg))
|
||||
else
|
||||
xPlayer.showNotification(msg)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
end, true)
|
||||
args = newArgs
|
||||
end
|
||||
end
|
||||
|
||||
if type(group) == 'table' then
|
||||
for k,v in ipairs(group) do
|
||||
ExecuteCommand(('add_ace group.%s command.%s allow'):format(v, name))
|
||||
end
|
||||
else
|
||||
ExecuteCommand(('add_ace group.%s command.%s allow'):format(group, name))
|
||||
end
|
||||
if error then
|
||||
if playerId == 0 then
|
||||
print(('[^3WARNING^7] %s^7'):format(error))
|
||||
else
|
||||
xPlayer.showNotification(error)
|
||||
end
|
||||
else
|
||||
cb(xPlayer or false, args, function(msg)
|
||||
if playerId == 0 then
|
||||
print(('[^3WARNING^7] %s^7'):format(msg))
|
||||
else
|
||||
xPlayer.showNotification(msg)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
end, true)
|
||||
|
||||
if type(group) == 'table' then
|
||||
for k, v in ipairs(group) do
|
||||
ExecuteCommand(('add_ace group.%s command.%s allow'):format(v, name))
|
||||
end
|
||||
else
|
||||
ExecuteCommand(('add_ace group.%s command.%s allow'):format(group, name))
|
||||
end
|
||||
end
|
||||
|
||||
function ESX.ClearTimeout(id)
|
||||
Core.CancelledTimeouts[id] = true
|
||||
Core.CancelledTimeouts[id] = true
|
||||
end
|
||||
|
||||
function ESX.RegisterServerCallback(name, cb)
|
||||
Core.ServerCallbacks[name] = cb
|
||||
Core.ServerCallbacks[name] = cb
|
||||
end
|
||||
|
||||
function ESX.TriggerServerCallback(name, requestId, source, cb, ...)
|
||||
if Core.ServerCallbacks[name] then
|
||||
Core.ServerCallbacks[name](source, cb, ...)
|
||||
else
|
||||
print(('[^3WARNING^7] Server callback ^5"%s"^0 does not exist. ^1Please Check The Server File for Errors!'):format(name))
|
||||
end
|
||||
if Core.ServerCallbacks[name] then
|
||||
Core.ServerCallbacks[name](source, cb, ...)
|
||||
else
|
||||
print(('[^3WARNING^7] Server callback ^5"%s"^0 does not exist. ^1Please Check The Server File for Errors!'):format(name))
|
||||
end
|
||||
end
|
||||
|
||||
function Core.SavePlayer(xPlayer, cb)
|
||||
MySQL.prepare('UPDATE `users` SET `accounts` = ?, `job` = ?, `job_grade` = ?, `group` = ?, `position` = ?, `inventory` = ?, `loadout` = ? WHERE `identifier` = ?', {
|
||||
json.encode(xPlayer.getAccounts(true)),
|
||||
xPlayer.job.name,
|
||||
xPlayer.job.grade,
|
||||
xPlayer.group,
|
||||
json.encode(xPlayer.getCoords()),
|
||||
json.encode(xPlayer.getInventory(true)),
|
||||
json.encode(xPlayer.getLoadout(true)),
|
||||
xPlayer.identifier
|
||||
}, function(affectedRows)
|
||||
if affectedRows == 1 then
|
||||
print(('[^2INFO^7] Saved player ^5"%s^7"'):format(xPlayer.name))
|
||||
TriggerEvent('esx:playerSaved', xPlayer.playerId, xPlayer)
|
||||
end
|
||||
if cb then cb() end
|
||||
end)
|
||||
MySQL.prepare(
|
||||
'UPDATE `users` SET `accounts` = ?, `job` = ?, `job_grade` = ?, `group` = ?, `position` = ?, `inventory` = ?, `loadout` = ? WHERE `identifier` = ?',
|
||||
{json.encode(xPlayer.getAccounts(true)), xPlayer.job.name, xPlayer.job.grade, xPlayer.group, json.encode(xPlayer.getCoords()),
|
||||
json.encode(xPlayer.getInventory(true)), json.encode(xPlayer.getLoadout(true)), xPlayer.identifier}, function(affectedRows)
|
||||
if affectedRows == 1 then
|
||||
print(('[^2INFO^7] Saved player ^5"%s^7"'):format(xPlayer.name))
|
||||
TriggerEvent('esx:playerSaved', xPlayer.playerId, xPlayer)
|
||||
end
|
||||
if cb then
|
||||
cb()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function Core.SavePlayers(cb)
|
||||
local xPlayers = ESX.GetExtendedPlayers()
|
||||
local count = #xPlayers
|
||||
if count > 0 then
|
||||
local parameters = {}
|
||||
local time = os.time()
|
||||
for i=1, count do
|
||||
local xPlayer = xPlayers[i]
|
||||
parameters[#parameters+1] = {
|
||||
json.encode(xPlayer.getAccounts(true)),
|
||||
xPlayer.job.name,
|
||||
xPlayer.job.grade,
|
||||
xPlayer.group,
|
||||
json.encode(xPlayer.getCoords()),
|
||||
json.encode(xPlayer.getInventory(true)),
|
||||
json.encode(xPlayer.getLoadout(true)),
|
||||
xPlayer.identifier
|
||||
}
|
||||
end
|
||||
MySQL.prepare("UPDATE `users` SET `accounts` = ?, `job` = ?, `job_grade` = ?, `group` = ?, `position` = ?, `inventory` = ?, `loadout` = ? WHERE `identifier` = ?", parameters,
|
||||
function(results)
|
||||
if results then
|
||||
if type(cb) == 'function' then cb() else print(('[^2INFO^7] Saved %s %s over %s ms'):format(count, count > 1 and 'players' or 'player', (os.time() - time) / 1000000)) end
|
||||
end
|
||||
end)
|
||||
end
|
||||
local xPlayers = ESX.GetExtendedPlayers()
|
||||
local count = #xPlayers
|
||||
if count > 0 then
|
||||
local parameters = {}
|
||||
local time = os.time()
|
||||
for i = 1, count do
|
||||
local xPlayer = xPlayers[i]
|
||||
parameters[#parameters + 1] = {json.encode(xPlayer.getAccounts(true)), xPlayer.job.name, xPlayer.job.grade, xPlayer.group,
|
||||
json.encode(xPlayer.getCoords()), json.encode(xPlayer.getInventory(true)), json.encode(xPlayer.getLoadout(true)),
|
||||
xPlayer.identifier}
|
||||
end
|
||||
MySQL.prepare(
|
||||
"UPDATE `users` SET `accounts` = ?, `job` = ?, `job_grade` = ?, `group` = ?, `position` = ?, `inventory` = ?, `loadout` = ? WHERE `identifier` = ?",
|
||||
parameters, function(results)
|
||||
if results then
|
||||
if type(cb) == 'function' then
|
||||
cb()
|
||||
else
|
||||
print(('[^2INFO^7] Saved %s %s over %s ms'):format(count, count > 1 and 'players' or 'player', (os.time() - time) / 1000000))
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
function ESX.GetPlayers()
|
||||
local sources = {}
|
||||
local sources = {}
|
||||
|
||||
for k,v in pairs(ESX.Players) do
|
||||
sources[#sources + 1] = k
|
||||
end
|
||||
for k, v in pairs(ESX.Players) do
|
||||
sources[#sources + 1] = k
|
||||
end
|
||||
|
||||
return sources
|
||||
return sources
|
||||
end
|
||||
|
||||
function ESX.GetExtendedPlayers(key, val)
|
||||
local xPlayers = {}
|
||||
for k, v in pairs(ESX.Players) do
|
||||
if key then
|
||||
if (key == 'job' and v.job.name == val) or v[key] == val then
|
||||
xPlayers[#xPlayers + 1] = v
|
||||
end
|
||||
else
|
||||
xPlayers[#xPlayers + 1] = v
|
||||
end
|
||||
end
|
||||
return xPlayers
|
||||
local xPlayers = {}
|
||||
for k, v in pairs(ESX.Players) do
|
||||
if key then
|
||||
if (key == 'job' and v.job.name == val) or v[key] == val then
|
||||
xPlayers[#xPlayers + 1] = v
|
||||
end
|
||||
else
|
||||
xPlayers[#xPlayers + 1] = v
|
||||
end
|
||||
end
|
||||
return xPlayers
|
||||
end
|
||||
|
||||
function ESX.GetPlayerFromId(source)
|
||||
return ESX.Players[tonumber(source)]
|
||||
return ESX.Players[tonumber(source)]
|
||||
end
|
||||
|
||||
function ESX.GetPlayerFromIdentifier(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
|
||||
|
||||
function ESX.GetIdentifier(playerId)
|
||||
for k,v in ipairs(GetPlayerIdentifiers(playerId)) do
|
||||
if string.match(v, 'license:') then
|
||||
local identifier = string.gsub(v, 'license:', '')
|
||||
return identifier
|
||||
end
|
||||
end
|
||||
for k, v in ipairs(GetPlayerIdentifiers(playerId)) do
|
||||
if string.match(v, 'license:') then
|
||||
local identifier = string.gsub(v, 'license:', '')
|
||||
return identifier
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ESX.RefreshJobs()
|
||||
local Jobs = {}
|
||||
local jobs = MySQL.query.await('SELECT * FROM jobs')
|
||||
function ESX.RefreshJobs()
|
||||
local Jobs = {}
|
||||
local jobs = MySQL.query.await('SELECT * FROM jobs')
|
||||
|
||||
for _, v in ipairs(jobs) do
|
||||
Jobs[v.name] = v
|
||||
Jobs[v.name].grades = {}
|
||||
end
|
||||
for _, v in ipairs(jobs) do
|
||||
Jobs[v.name] = v
|
||||
Jobs[v.name].grades = {}
|
||||
end
|
||||
|
||||
local jobGrades = MySQL.query.await('SELECT * FROM job_grades')
|
||||
local jobGrades = MySQL.query.await('SELECT * FROM job_grades')
|
||||
|
||||
for _, v in ipairs(jobGrades) do
|
||||
if Jobs[v.job_name] then
|
||||
Jobs[v.job_name].grades[tostring(v.grade)] = v
|
||||
else
|
||||
print(('[^3WARNING^7] Ignoring job grades for ^5"%s"^0 due to missing job'):format(v.job_name))
|
||||
end
|
||||
end
|
||||
for _, v in ipairs(jobGrades) do
|
||||
if Jobs[v.job_name] then
|
||||
Jobs[v.job_name].grades[tostring(v.grade)] = v
|
||||
else
|
||||
print(('[^3WARNING^7] Ignoring job grades for ^5"%s"^0 due to missing job'):format(v.job_name))
|
||||
end
|
||||
end
|
||||
|
||||
for _, v in pairs(Jobs) do
|
||||
if ESX.Table.SizeOf(v.grades) == 0 then
|
||||
Jobs[v.name] = nil
|
||||
print(('[^3WARNING^7] Ignoring job ^5"%s"^0 due to no job grades found'):format(v.name))
|
||||
end
|
||||
end
|
||||
for _, v in pairs(Jobs) do
|
||||
if ESX.Table.SizeOf(v.grades) == 0 then
|
||||
Jobs[v.name] = nil
|
||||
print(('[^3WARNING^7] Ignoring job ^5"%s"^0 due to no job grades found'):format(v.name))
|
||||
end
|
||||
end
|
||||
|
||||
if not Jobs then
|
||||
-- Fallback data, if no jobs exist
|
||||
ESX.Jobs['unemployed'] = {
|
||||
label = 'Unemployed',
|
||||
grades = {
|
||||
['0'] = {
|
||||
grade = 0,
|
||||
label = 'Unemployed',
|
||||
salary = 200,
|
||||
skin_male = {},
|
||||
skin_female = {}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
ESX.Jobs = Jobs
|
||||
end
|
||||
if not Jobs then
|
||||
-- Fallback data, if no jobs exist
|
||||
ESX.Jobs['unemployed'] = {label = 'Unemployed',
|
||||
grades = {['0'] = {grade = 0, label = 'Unemployed', salary = 200, skin_male = {}, skin_female = {}}}}
|
||||
else
|
||||
ESX.Jobs = Jobs
|
||||
end
|
||||
end
|
||||
|
||||
function ESX.RegisterUsableItem(item, cb)
|
||||
Core.UsableItemsCallbacks[item] = cb
|
||||
Core.UsableItemsCallbacks[item] = cb
|
||||
end
|
||||
|
||||
function ESX.UseItem(source, item, ...)
|
||||
if ESX.Items[item] then
|
||||
local itemCallback = Core.UsableItemsCallbacks[item]
|
||||
if ESX.Items[item] then
|
||||
local itemCallback = Core.UsableItemsCallbacks[item]
|
||||
|
||||
if itemCallback then
|
||||
local success, result = pcall(itemCallback, source, item, ...)
|
||||
if itemCallback then
|
||||
local success, result = pcall(itemCallback, source, item, ...)
|
||||
|
||||
if not success then
|
||||
return result and print(result) or print(('[^3WARNING^7] An error occured when using item ^5"%s"^7! This was not caused by ESX.'):format(item))
|
||||
end
|
||||
end
|
||||
else
|
||||
print(('[^3WARNING^7] Item ^5"%s"^7 was used but does not exist!'):format(item))
|
||||
end
|
||||
if not success then
|
||||
return result and print(result) or
|
||||
print(('[^3WARNING^7] An error occured when using item ^5"%s"^7! This was not caused by ESX.'):format(item))
|
||||
end
|
||||
end
|
||||
else
|
||||
print(('[^3WARNING^7] Item ^5"%s"^7 was used but does not exist!'):format(item))
|
||||
end
|
||||
end
|
||||
|
||||
function ESX.RegisterPlayerFunctionOverrides(index,overrides)
|
||||
Core.PlayerFunctionOverrides[index] = overrides
|
||||
function ESX.RegisterPlayerFunctionOverrides(index, overrides)
|
||||
Core.PlayerFunctionOverrides[index] = overrides
|
||||
end
|
||||
|
||||
function ESX.SetPlayerFunctionOverride(index)
|
||||
if not index
|
||||
or not Core.PlayerFunctionOverrides[index]
|
||||
then
|
||||
return print('[^3WARNING^7] No valid index provided.')
|
||||
end
|
||||
if not index or not Core.PlayerFunctionOverrides[index] then
|
||||
return print('[^3WARNING^7] No valid index provided.')
|
||||
end
|
||||
|
||||
Config.PlayerFunctionOverride = index
|
||||
Config.PlayerFunctionOverride = index
|
||||
end
|
||||
|
||||
function ESX.GetItemLabel(item)
|
||||
if Config.OxInventory then
|
||||
item = exports.ox_inventory:Items(item)
|
||||
if item then return item.label end
|
||||
end
|
||||
|
||||
if ESX.Items[item] then
|
||||
return ESX.Items[item].label
|
||||
else
|
||||
print('[^3WARNING^7] Attemting to get invalid Item -> '..item )
|
||||
end
|
||||
if Config.OxInventory then
|
||||
item = exports.ox_inventory:Items(item)
|
||||
if item then
|
||||
return item.label
|
||||
end
|
||||
end
|
||||
|
||||
if ESX.Items[item] then
|
||||
return ESX.Items[item].label
|
||||
else
|
||||
print('[^3WARNING^7] Attemting to get invalid Item -> ' .. item)
|
||||
end
|
||||
end
|
||||
|
||||
function ESX.GetJobs()
|
||||
return ESX.Jobs
|
||||
return ESX.Jobs
|
||||
end
|
||||
|
||||
function ESX.GetUsableItems()
|
||||
local Usables = {}
|
||||
for k in pairs(Core.UsableItemsCallbacks) do
|
||||
Usables[k] = true
|
||||
end
|
||||
return Usables
|
||||
local Usables = {}
|
||||
for k in pairs(Core.UsableItemsCallbacks) do
|
||||
Usables[k] = true
|
||||
end
|
||||
return Usables
|
||||
end
|
||||
|
||||
if not Config.OxInventory then
|
||||
function ESX.CreatePickup(type, name, count, label, playerId, components, tintIndex)
|
||||
local pickupId = (Core.PickupId == 65635 and 0 or Core.PickupId + 1)
|
||||
local xPlayer = ESX.Players[playerId]
|
||||
local coords = xPlayer.getCoords()
|
||||
function ESX.CreatePickup(type, name, count, label, playerId, components, tintIndex)
|
||||
local pickupId = (Core.PickupId == 65635 and 0 or Core.PickupId + 1)
|
||||
local xPlayer = ESX.Players[playerId]
|
||||
local coords = xPlayer.getCoords()
|
||||
|
||||
Core.Pickups[pickupId] = {
|
||||
type = type, name = name,
|
||||
count = count, label = label,
|
||||
coords = coords
|
||||
}
|
||||
Core.Pickups[pickupId] = {type = type, name = name, count = count, label = label, coords = coords}
|
||||
|
||||
if type == 'item_weapon' then
|
||||
Core.Pickups[pickupId].components = components
|
||||
Core.Pickups[pickupId].tintIndex = tintIndex
|
||||
end
|
||||
if type == 'item_weapon' then
|
||||
Core.Pickups[pickupId].components = components
|
||||
Core.Pickups[pickupId].tintIndex = tintIndex
|
||||
end
|
||||
|
||||
TriggerClientEvent('esx:createPickup', -1, pickupId, label, coords, type, name, components, tintIndex)
|
||||
Core.PickupId = pickupId
|
||||
end
|
||||
TriggerClientEvent('esx:createPickup', -1, pickupId, label, coords, type, name, components, tintIndex)
|
||||
Core.PickupId = pickupId
|
||||
end
|
||||
end
|
||||
|
||||
function ESX.DoesJobExist(job, grade)
|
||||
grade = tostring(grade)
|
||||
grade = tostring(grade)
|
||||
|
||||
if job and grade then
|
||||
if ESX.Jobs[job] and ESX.Jobs[job].grades[grade] then
|
||||
return true
|
||||
end
|
||||
end
|
||||
if job and grade then
|
||||
if ESX.Jobs[job] and ESX.Jobs[job].grades[grade] then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
return false
|
||||
end
|
||||
|
||||
function Core.IsPlayerAdmin(playerId)
|
||||
if (IsPlayerAceAllowed(playerId, 'command') or GetConvar('sv_lan', '') == 'true') and true or false then
|
||||
return true
|
||||
end
|
||||
if (IsPlayerAceAllowed(playerId, 'command') or GetConvar('sv_lan', '') == 'true') and true or false then
|
||||
return true
|
||||
end
|
||||
|
||||
local xPlayer = ESX.Players[playerId]
|
||||
local xPlayer = ESX.Players[playerId]
|
||||
|
||||
if xPlayer then
|
||||
if xPlayer.group == 'admin' then
|
||||
return true
|
||||
end
|
||||
end
|
||||
if xPlayer then
|
||||
if xPlayer.group == 'admin' then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
return false
|
||||
end
|
||||
|
||||
+493
-555
File diff suppressed because it is too large
Load Diff
@@ -1,41 +1,45 @@
|
||||
function StartPayCheck()
|
||||
CreateThread(function()
|
||||
while true do
|
||||
Wait(Config.PaycheckInterval)
|
||||
local xPlayers = ESX.GetExtendedPlayers()
|
||||
for i=1, #(xPlayers) do
|
||||
local xPlayer = xPlayers[i]
|
||||
local job = xPlayer.job.grade_name
|
||||
local salary = xPlayer.job.grade_salary
|
||||
CreateThread(function()
|
||||
while true do
|
||||
Wait(Config.PaycheckInterval)
|
||||
local xPlayers = ESX.GetExtendedPlayers()
|
||||
for i = 1, #(xPlayers) do
|
||||
local xPlayer = xPlayers[i]
|
||||
local job = xPlayer.job.grade_name
|
||||
local salary = xPlayer.job.grade_salary
|
||||
|
||||
if salary > 0 then
|
||||
if job == 'unemployed' then -- unemployed
|
||||
xPlayer.addAccountMoney('bank', salary)
|
||||
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_help', salary), 'CHAR_BANK_MAZE', 9)
|
||||
elseif Config.EnableSocietyPayouts then -- possibly a society
|
||||
TriggerEvent('esx_society:getSociety', xPlayer.job.name, function (society)
|
||||
if society ~= nil then -- verified society
|
||||
TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function (account)
|
||||
if account.money >= salary then -- does the society money to pay its employees?
|
||||
xPlayer.addAccountMoney('bank', salary)
|
||||
account.removeMoney(salary)
|
||||
if salary > 0 then
|
||||
if job == 'unemployed' then -- unemployed
|
||||
xPlayer.addAccountMoney('bank', salary)
|
||||
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_help', salary),
|
||||
'CHAR_BANK_MAZE', 9)
|
||||
elseif Config.EnableSocietyPayouts then -- possibly a society
|
||||
TriggerEvent('esx_society:getSociety', xPlayer.job.name, function(society)
|
||||
if society ~= nil then -- verified society
|
||||
TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function(account)
|
||||
if account.money >= salary then -- does the society money to pay its employees?
|
||||
xPlayer.addAccountMoney('bank', salary)
|
||||
account.removeMoney(salary)
|
||||
|
||||
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_salary', salary), 'CHAR_BANK_MAZE', 9)
|
||||
else
|
||||
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), '', _U('company_nomoney'), 'CHAR_BANK_MAZE', 1)
|
||||
end
|
||||
end)
|
||||
else -- not a society
|
||||
xPlayer.addAccountMoney('bank', salary)
|
||||
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_salary', salary), 'CHAR_BANK_MAZE', 9)
|
||||
end
|
||||
end)
|
||||
else -- generic job
|
||||
xPlayer.addAccountMoney('bank', salary)
|
||||
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_salary', salary), 'CHAR_BANK_MAZE', 9)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'),
|
||||
_U('received_salary', salary), 'CHAR_BANK_MAZE', 9)
|
||||
else
|
||||
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), '', _U('company_nomoney'), 'CHAR_BANK_MAZE', 1)
|
||||
end
|
||||
end)
|
||||
else -- not a society
|
||||
xPlayer.addAccountMoney('bank', salary)
|
||||
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_salary', salary),
|
||||
'CHAR_BANK_MAZE', 9)
|
||||
end
|
||||
end)
|
||||
else -- generic job
|
||||
xPlayer.addAccountMoney('bank', salary)
|
||||
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_salary', salary),
|
||||
'CHAR_BANK_MAZE', 9)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user