mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 04:01:22 +00:00
refactor!(es_extended): move players into core
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
ESX.Players = {}
|
||||
Core = {}
|
||||
Core.Players = {}
|
||||
Core.Items = {}
|
||||
Core.Jobs = {}
|
||||
Core.JobsPlayerCount = {}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -234,7 +234,7 @@ end
|
||||
---@param cb? function
|
||||
---@return nil
|
||||
function Core.SavePlayers(cb)
|
||||
local xPlayers <const> = ESX.Players
|
||||
local xPlayers <const> = Core.Players
|
||||
if not next(xPlayers) then
|
||||
return
|
||||
end
|
||||
@@ -242,7 +242,7 @@ function Core.SavePlayers(cb)
|
||||
local startTime <const> = 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
|
||||
@@ -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
|
||||
@@ -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 }
|
||||
@@ -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
|
||||
|
||||
@@ -73,7 +73,7 @@ if Config.Multichar then
|
||||
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)
|
||||
@@ -89,7 +89,7 @@ else
|
||||
Wait(50)
|
||||
end
|
||||
|
||||
if not ESX.Players[_source] then
|
||||
if not Core.Players[_source] then
|
||||
onPlayerJoined(_source)
|
||||
end
|
||||
end)
|
||||
@@ -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
|
||||
@@ -326,7 +326,7 @@ AddEventHandler("playerDropped", function(reason)
|
||||
|
||||
Core.SavePlayer(xPlayer, function()
|
||||
GlobalState["playerCount"] = GlobalState["playerCount"] - 1
|
||||
ESX.Players[playerId] = nil
|
||||
Core.Players[playerId] = nil
|
||||
end)
|
||||
end
|
||||
end)
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user