diff --git a/[core]/es_extended/server/bridge/inventory/oxinventory.lua b/[core]/es_extended/server/bridge/inventory/oxinventory.lua index 62b4c2afd..f3771968c 100644 --- a/[core]/es_extended/server/bridge/inventory/oxinventory.lua +++ b/[core]/es_extended/server/bridge/inventory/oxinventory.lua @@ -3,12 +3,12 @@ if Config.CustomInventory ~= "ox" then return end MySQL.ready(function() TriggerEvent("__cfx_export_ox_inventory_Items", function(ref) if ref then - ESX.Items = ref() + Core.Items = ref() end end) AddEventHandler("ox_inventory:itemList", function(items) - ESX.Items = items + Core.Items = items end) end) diff --git a/[core]/es_extended/server/classes/player.lua b/[core]/es_extended/server/classes/player.lua index b5e66e7b8..5a4463e9c 100644 --- a/[core]/es_extended/server/classes/player.lua +++ b/[core]/es_extended/server/classes/player.lua @@ -464,8 +464,8 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, ---@param count number ---@return boolean function self.canCarryItem(itemName, count) - if ESX.Items[itemName] then - local currentWeight, itemWeight = self.weight, ESX.Items[itemName].weight + if Core.Items[itemName] then + local currentWeight, itemWeight = self.weight, Core.Items[itemName].weight local newWeight = currentWeight + (itemWeight * count) return newWeight <= self.maxWeight @@ -527,7 +527,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, onDuty = Config.DefaultJobDuty end - local jobObject, gradeObject = ESX.Jobs[newJob], ESX.Jobs[newJob].grades[grade] + local jobObject, gradeObject = Core.Jobs[newJob], Core.Jobs[newJob].grades[grade] self.job = { id = jobObject.id, diff --git a/[core]/es_extended/server/common.lua b/[core]/es_extended/server/common.lua index edbc39529..281e94391 100644 --- a/[core]/es_extended/server/common.lua +++ b/[core]/es_extended/server/common.lua @@ -1,8 +1,8 @@ -ESX.Players = {} -ESX.Jobs = {} -ESX.JobsPlayerCount = {} -ESX.Items = {} Core = {} +Core.Players = {} +Core.Items = {} +Core.Jobs = {} +Core.JobsPlayerCount = {} Core.UsableItemsCallbacks = {} Core.RegisteredCommands = {} Core.Pickups = {} @@ -14,7 +14,7 @@ Core.playersByIdentifier = {} Core.vehicleTypesByModel = {} RegisterNetEvent("esx:onPlayerSpawn", function() - ESX.Players[source].spawned = true + Core.Players[source].spawned = true end) if Config.CustomInventory then @@ -37,7 +37,7 @@ MySQL.ready(function() if not Config.CustomInventory then local items = MySQL.query.await("SELECT * FROM items") for _, v in ipairs(items) do - ESX.Items[v.name] = { label = v.label, weight = v.weight, rare = v.rare, canRemove = v.can_remove } + Core.Items[v.name] = { label = v.label, weight = v.weight, rare = v.rare, canRemove = v.can_remove } end end diff --git a/[core]/es_extended/server/functions.lua b/[core]/es_extended/server/functions.lua index 884ef4a57..399b5761c 100644 --- a/[core]/es_extended/server/functions.lua +++ b/[core]/es_extended/server/functions.lua @@ -64,7 +64,7 @@ function ESX.RegisterCommand(name, group, cb, allowConsole, suggestion) if not command.allowConsole and playerId == 0 then print(("[^3WARNING^7] ^5%s"):format(TranslateCap("commanderror_console"))) else - local xPlayer, error = ESX.Players[playerId], nil + local xPlayer, error = Core.Players[playerId], nil if command.suggestion then if command.suggestion.validate then @@ -116,7 +116,7 @@ function ESX.RegisterCommand(name, group, cb, allowConsole, suggestion) error = TranslateCap("commanderror_argumentmismatch_string", k) end elseif v.type == "item" then - if ESX.Items[args[k]] then + if Core.Items[args[k]] then newArgs[v.name] = args[k] else error = TranslateCap("commanderror_invaliditem") @@ -234,7 +234,7 @@ end ---@param cb? function ---@return nil function Core.SavePlayers(cb) - local xPlayers = ESX.Players + local xPlayers = Core.Players if not next(xPlayers) then return end @@ -242,7 +242,7 @@ function Core.SavePlayers(cb) local startTime = os.time() local parameters = {} - for _, xPlayer in pairs(ESX.Players) do + for _, xPlayer in pairs(Core.Players) do updateHealthAndArmorInMetadata(xPlayer) parameters[#parameters + 1] = { json.encode(xPlayer.getAccounts(true)), @@ -294,19 +294,19 @@ end ---@return table function ESX.GetExtendedPlayers(key, val) if not key then - return ESX.Table.ToArray(ESX.Players) + return ESX.Table.ToArray(Core.Players) end local xPlayers = {} if type(val) == "table" then - for _, xPlayer in pairs(ESX.Players) do + for _, xPlayer in pairs(Core.Players) do checkTable(key, val, xPlayer, xPlayers) end return xPlayers end - for _, xPlayer in pairs(ESX.Players) do + for _, xPlayer in pairs(Core.Players) do if (key == "job" and xPlayer.job.name == val) or xPlayer[key] == val then xPlayers[#xPlayers + 1] = xPlayer end @@ -327,7 +327,7 @@ function ESX.GetNumPlayers(key, val) local numPlayers = {} if key == "job" then for _, v in ipairs(val) do - numPlayers[v] = (ESX.JobsPlayerCount[v] or 0) + numPlayers[v] = (Core.JobsPlayerCount[v] or 0) end return numPlayers end @@ -340,7 +340,7 @@ function ESX.GetNumPlayers(key, val) end if key == "job" then - return (ESX.JobsPlayerCount[val] or 0) + return (Core.JobsPlayerCount[val] or 0) end return #ESX.GetExtendedPlayers(key, val) @@ -349,7 +349,7 @@ end ---@param source number ---@return table function ESX.GetPlayerFromId(source) - return ESX.Players[tonumber(source)] + return Core.Players[tonumber(source)] end ---@param identifier string @@ -495,9 +495,9 @@ function ESX.RefreshJobs() 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 = {} } } } + Core.Jobs["unemployed"] = { label = "Unemployed", grades = { ["0"] = { grade = 0, label = "Unemployed", salary = 200, skin_male = {}, skin_female = {} } } } else - ESX.Jobs = Jobs + Core.Jobs = Jobs end end @@ -513,7 +513,7 @@ end ---@param ... any ---@return nil function ESX.UseItem(source, item, ...) - if ESX.Items[item] then + if Core.Items[item] then local itemCallback = Core.UsableItemsCallbacks[item] if itemCallback then @@ -549,8 +549,8 @@ end ---@return string? ---@diagnostic disable-next-line: duplicate-set-field function ESX.GetItemLabel(item) - if ESX.Items[item] then - return ESX.Items[item].label + if Core.Items[item] then + return Core.Items[item].label else print(("[^3WARNING^7] Attemting to get invalid Item -> ^5%s^7"):format(item)) end @@ -558,7 +558,7 @@ end ---@return table function ESX.GetJobs() - return ESX.Jobs + return Core.Jobs end ---@return table @@ -582,7 +582,7 @@ if not Config.CustomInventory then ---@return nil function ESX.CreatePickup(itemType, name, count, label, playerId, components, tintIndex, coords) local pickupId = (Core.PickupId == 65635 and 0 or Core.PickupId + 1) - local xPlayer = ESX.Players[playerId] + local xPlayer = Core.Players[playerId] coords = ((type(coords) == "vector3" or type(coords) == "vector4") and coords.xyz or xPlayer.getCoords(true)) Core.Pickups[pickupId] = { type = itemType, name = name, count = count, label = label, coords = coords } @@ -601,7 +601,7 @@ end ---@param grade string ---@return boolean function ESX.DoesJobExist(job, grade) - return (ESX.Jobs[job] and ESX.Jobs[job].grades[tostring(grade)] ~= nil) or false + return (Core.Jobs[job] and Core.Jobs[job].grades[tostring(grade)] ~= nil) or false end ---@param playerId string | number @@ -612,6 +612,6 @@ function Core.IsPlayerAdmin(playerId) return true end - local xPlayer = ESX.Players[playerId] + local xPlayer = Core.Players[playerId] return (xPlayer and Config.AdminGroups[xPlayer.group] and true) or false end diff --git a/[core]/es_extended/server/main.lua b/[core]/es_extended/server/main.lua index 61fbe78ed..814caef30 100644 --- a/[core]/es_extended/server/main.lua +++ b/[core]/es_extended/server/main.lua @@ -69,11 +69,11 @@ end if Config.Multichar then AddEventHandler("esx:onPlayerJoined", function(src, char, data) - while not next(ESX.Jobs) do + while not next(Core.Jobs) do Wait(50) end - if not ESX.Players[src] then + if not Core.Players[src] then local identifier = char .. ":" .. ESX.GetIdentifier(src) if data then createESXPlayer(identifier, src, data) @@ -85,11 +85,11 @@ if Config.Multichar then else RegisterNetEvent("esx:onPlayerJoined", function() local _source = source - while not next(ESX.Jobs) do + while not next(Core.Jobs) do Wait(50) end - if not ESX.Players[_source] then + if not Core.Players[_source] then onPlayerJoined(_source) end end) @@ -171,7 +171,7 @@ function loadESXPlayer(identifier, playerId, isNew) job, grade = "unemployed", "0" end - local jobObject, gradeObject = ESX.Jobs[job], ESX.Jobs[job].grades[grade] + local jobObject, gradeObject = Core.Jobs[job], Core.Jobs[job].grades[grade] userData.job = { id = jobObject.id, @@ -191,7 +191,7 @@ function loadESXPlayer(identifier, playerId, isNew) if not Config.CustomInventory then local inventory = (result.inventory and result.inventory ~= "") and json.decode(result.inventory) or {} - for name, item in pairs(ESX.Items) do + for name, item in pairs(Core.Items) do local count = inventory[name] or 0 userData.weight += (count * item.weight) @@ -258,7 +258,7 @@ function loadESXPlayer(identifier, playerId, isNew) local xPlayer = CreateExtendedPlayer(playerId, identifier, userData.group, userData.accounts, userData.inventory, userData.weight, userData.job, userData.loadout, GetPlayerName(playerId), userData.coords, userData.metadata) GlobalState["playerCount"] = GlobalState["playerCount"] + 1 - ESX.Players[playerId] = xPlayer + Core.Players[playerId] = xPlayer Core.playersByIdentifier[identifier] = xPlayer -- Identity @@ -318,15 +318,15 @@ AddEventHandler("playerDropped", function(reason) if xPlayer then TriggerEvent("esx:playerDropped", playerId, reason) local job = xPlayer.getJob().name - local currentJob = ESX.JobsPlayerCount[job] - ESX.JobsPlayerCount[job] = ((currentJob and currentJob > 0) and currentJob or 1) - 1 + local currentJob = Core.JobsPlayerCount[job] + Core.JobsPlayerCount[job] = ((currentJob and currentJob > 0) and currentJob or 1) - 1 - GlobalState[("%s:count"):format(job)] = ESX.JobsPlayerCount[job] + GlobalState[("%s:count"):format(job)] = Core.JobsPlayerCount[job] Core.playersByIdentifier[xPlayer.identifier] = nil Core.SavePlayer(xPlayer, function() GlobalState["playerCount"] = GlobalState["playerCount"] - 1 - ESX.Players[playerId] = nil + Core.Players[playerId] = nil end) end end) @@ -335,20 +335,20 @@ AddEventHandler("esx:playerLoaded", function(_, xPlayer) local job = xPlayer.getJob().name local jobKey = ("%s:count"):format(job) - ESX.JobsPlayerCount[job] = (ESX.JobsPlayerCount[job] or 0) + 1 - GlobalState[jobKey] = ESX.JobsPlayerCount[job] + Core.JobsPlayerCount[job] = (Core.JobsPlayerCount[job] or 0) + 1 + GlobalState[jobKey] = Core.JobsPlayerCount[job] end) AddEventHandler("esx:setJob", function(_, job, lastJob) local lastJobKey = ("%s:count"):format(lastJob.name) local jobKey = ("%s:count"):format(job.name) - local currentLastJob = ESX.JobsPlayerCount[lastJob.name] + local currentLastJob = Core.JobsPlayerCount[lastJob.name] - ESX.JobsPlayerCount[lastJob.name] = ((currentLastJob and currentLastJob > 0) and currentLastJob or 1) - 1 - ESX.JobsPlayerCount[job.name] = (ESX.JobsPlayerCount[job.name] or 0) + 1 + Core.JobsPlayerCount[lastJob.name] = ((currentLastJob and currentLastJob > 0) and currentLastJob or 1) - 1 + Core.JobsPlayerCount[job.name] = (Core.JobsPlayerCount[job.name] or 0) + 1 - GlobalState[lastJobKey] = ESX.JobsPlayerCount[lastJob.name] - GlobalState[jobKey] = ESX.JobsPlayerCount[job.name] + GlobalState[lastJobKey] = Core.JobsPlayerCount[lastJob.name] + GlobalState[jobKey] = Core.JobsPlayerCount[job.name] end) AddEventHandler("esx:playerLogout", function(playerId, cb) @@ -359,7 +359,7 @@ AddEventHandler("esx:playerLogout", function(playerId, cb) Core.playersByIdentifier[xPlayer.identifier] = nil Core.SavePlayer(xPlayer, function() GlobalState["playerCount"] = GlobalState["playerCount"] - 1 - ESX.Players[playerId] = nil + Core.Players[playerId] = nil if cb then cb() end diff --git a/[core]/es_extended/server/modules/createJob.lua b/[core]/es_extended/server/modules/createJob.lua index c4c09eff6..866b6d5c7 100644 --- a/[core]/es_extended/server/modules/createJob.lua +++ b/[core]/es_extended/server/modules/createJob.lua @@ -6,7 +6,7 @@ local NOTIFY_TYPES = { } local function doesJobAndGradesExist(name, grades) - if not ESX.Jobs[name] then + if not Core.Jobs[name] then return false end @@ -86,7 +86,7 @@ function ESX.CreateJob(name, label, grades) return success end - ESX.Jobs[name] = generateNewJobTable(name, label, grades) + Core.Jobs[name] = generateNewJobTable(name, label, grades) notify("SUCCESS", currentResourceName, 'Job created successfully: `%s`', name) diff --git a/[core]/es_extended/server/modules/npwd.lua b/[core]/es_extended/server/modules/npwd.lua index 78aa863de..f119ddb8b 100644 --- a/[core]/es_extended/server/modules/npwd.lua +++ b/[core]/es_extended/server/modules/npwd.lua @@ -10,7 +10,7 @@ AddEventHandler("onServerResourceStart", function(resource) if not npwd then return end - for _, xPlayer in pairs(ESX.Players) do + for _, xPlayer in pairs(Core.Players) do npwd:newPlayer({ source = xPlayer.source, identifier = xPlayer.identifier, diff --git a/[core]/es_extended/server/modules/onesync.lua b/[core]/es_extended/server/modules/onesync.lua index de4f4eb8d..731ad18c9 100644 --- a/[core]/es_extended/server/modules/onesync.lua +++ b/[core]/es_extended/server/modules/onesync.lua @@ -39,7 +39,7 @@ local function getNearbyPlayers(source, closest, distance, ignore) end end - for _, xPlayer in pairs(ESX.Players) do + for _, xPlayer in pairs(Core.Players) do if not ignore or not ignore[xPlayer.source] then local entity = GetPlayerPed(xPlayer.source) local coords = GetEntityCoords(entity) diff --git a/[core]/es_extended/server/modules/paycheck.lua b/[core]/es_extended/server/modules/paycheck.lua index f80c7f12e..4bba19487 100644 --- a/[core]/es_extended/server/modules/paycheck.lua +++ b/[core]/es_extended/server/modules/paycheck.lua @@ -2,7 +2,7 @@ function StartPayCheck() CreateThread(function() while true do Wait(Config.PaycheckInterval) - for player, xPlayer in pairs(ESX.Players) do + for player, xPlayer in pairs(Core.Players) do local jobLabel = xPlayer.job.label local job = xPlayer.job.grade_name local salary = xPlayer.job.grade_salary diff --git a/[core]/esx_multicharacter/server/modules/database.lua b/[core]/esx_multicharacter/server/modules/database.lua index 96294523e..0f3d7a3e4 100644 --- a/[core]/esx_multicharacter/server/modules/database.lua +++ b/[core]/esx_multicharacter/server/modules/database.lua @@ -64,6 +64,7 @@ MySQL.ready(function() Database.connected = true + ESX.Jobs = ESX.GetJobs() while not next(ESX.Jobs) do Wait(500) ESX.Jobs = ESX.GetJobs() diff --git a/[core]/esx_multicharacter/server/modules/functions.lua b/[core]/esx_multicharacter/server/modules/functions.lua index f1750e2fb..8792cec14 100644 --- a/[core]/esx_multicharacter/server/modules/functions.lua +++ b/[core]/esx_multicharacter/server/modules/functions.lua @@ -1,3 +1,5 @@ +ESX.Players = {} + function Server:GetIdentifier(source) local fxDk = GetConvarInt("sv_fxdkMode", 0) if fxDk == 1 then