mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-04 16:23:21 +00:00
refactor!(es_extended): move players into core
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
ESX.Players = {}
|
|
||||||
Core = {}
|
Core = {}
|
||||||
|
Core.Players = {}
|
||||||
Core.Items = {}
|
Core.Items = {}
|
||||||
Core.Jobs = {}
|
Core.Jobs = {}
|
||||||
Core.JobsPlayerCount = {}
|
Core.JobsPlayerCount = {}
|
||||||
@@ -14,7 +14,7 @@ Core.playersByIdentifier = {}
|
|||||||
Core.vehicleTypesByModel = {}
|
Core.vehicleTypesByModel = {}
|
||||||
|
|
||||||
RegisterNetEvent("esx:onPlayerSpawn", function()
|
RegisterNetEvent("esx:onPlayerSpawn", function()
|
||||||
ESX.Players[source].spawned = true
|
Core.Players[source].spawned = true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if Config.CustomInventory then
|
if Config.CustomInventory then
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ function ESX.RegisterCommand(name, group, cb, allowConsole, suggestion)
|
|||||||
if not command.allowConsole and playerId == 0 then
|
if not command.allowConsole and playerId == 0 then
|
||||||
print(("[^3WARNING^7] ^5%s"):format(TranslateCap("commanderror_console")))
|
print(("[^3WARNING^7] ^5%s"):format(TranslateCap("commanderror_console")))
|
||||||
else
|
else
|
||||||
local xPlayer, error = ESX.Players[playerId], nil
|
local xPlayer, error = Core.Players[playerId], nil
|
||||||
|
|
||||||
if command.suggestion then
|
if command.suggestion then
|
||||||
if command.suggestion.validate then
|
if command.suggestion.validate then
|
||||||
@@ -234,7 +234,7 @@ end
|
|||||||
---@param cb? function
|
---@param cb? function
|
||||||
---@return nil
|
---@return nil
|
||||||
function Core.SavePlayers(cb)
|
function Core.SavePlayers(cb)
|
||||||
local xPlayers <const> = ESX.Players
|
local xPlayers <const> = Core.Players
|
||||||
if not next(xPlayers) then
|
if not next(xPlayers) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -242,7 +242,7 @@ function Core.SavePlayers(cb)
|
|||||||
local startTime <const> = os.time()
|
local startTime <const> = os.time()
|
||||||
local parameters = {}
|
local parameters = {}
|
||||||
|
|
||||||
for _, xPlayer in pairs(ESX.Players) do
|
for _, xPlayer in pairs(Core.Players) do
|
||||||
updateHealthAndArmorInMetadata(xPlayer)
|
updateHealthAndArmorInMetadata(xPlayer)
|
||||||
parameters[#parameters + 1] = {
|
parameters[#parameters + 1] = {
|
||||||
json.encode(xPlayer.getAccounts(true)),
|
json.encode(xPlayer.getAccounts(true)),
|
||||||
@@ -294,19 +294,19 @@ end
|
|||||||
---@return table
|
---@return table
|
||||||
function ESX.GetExtendedPlayers(key, val)
|
function ESX.GetExtendedPlayers(key, val)
|
||||||
if not key then
|
if not key then
|
||||||
return ESX.Table.ToArray(ESX.Players)
|
return ESX.Table.ToArray(Core.Players)
|
||||||
end
|
end
|
||||||
|
|
||||||
local xPlayers = {}
|
local xPlayers = {}
|
||||||
if type(val) == "table" then
|
if type(val) == "table" then
|
||||||
for _, xPlayer in pairs(ESX.Players) do
|
for _, xPlayer in pairs(Core.Players) do
|
||||||
checkTable(key, val, xPlayer, xPlayers)
|
checkTable(key, val, xPlayer, xPlayers)
|
||||||
end
|
end
|
||||||
|
|
||||||
return xPlayers
|
return xPlayers
|
||||||
end
|
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
|
if (key == "job" and xPlayer.job.name == val) or xPlayer[key] == val then
|
||||||
xPlayers[#xPlayers + 1] = xPlayer
|
xPlayers[#xPlayers + 1] = xPlayer
|
||||||
end
|
end
|
||||||
@@ -349,7 +349,7 @@ end
|
|||||||
---@param source number
|
---@param source number
|
||||||
---@return table
|
---@return table
|
||||||
function ESX.GetPlayerFromId(source)
|
function ESX.GetPlayerFromId(source)
|
||||||
return ESX.Players[tonumber(source)]
|
return Core.Players[tonumber(source)]
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param identifier string
|
---@param identifier string
|
||||||
@@ -582,7 +582,7 @@ if not Config.CustomInventory then
|
|||||||
---@return nil
|
---@return nil
|
||||||
function ESX.CreatePickup(itemType, name, count, label, playerId, components, tintIndex, coords)
|
function ESX.CreatePickup(itemType, name, count, label, playerId, components, tintIndex, coords)
|
||||||
local pickupId = (Core.PickupId == 65635 and 0 or Core.PickupId + 1)
|
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))
|
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 }
|
Core.Pickups[pickupId] = { type = itemType, name = name, count = count, label = label, coords = coords }
|
||||||
@@ -612,6 +612,6 @@ function Core.IsPlayerAdmin(playerId)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local xPlayer = ESX.Players[playerId]
|
local xPlayer = Core.Players[playerId]
|
||||||
return (xPlayer and Config.AdminGroups[xPlayer.group] and true) or false
|
return (xPlayer and Config.AdminGroups[xPlayer.group] and true) or false
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ if Config.Multichar then
|
|||||||
Wait(50)
|
Wait(50)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not ESX.Players[src] then
|
if not Core.Players[src] then
|
||||||
local identifier = char .. ":" .. ESX.GetIdentifier(src)
|
local identifier = char .. ":" .. ESX.GetIdentifier(src)
|
||||||
if data then
|
if data then
|
||||||
createESXPlayer(identifier, src, data)
|
createESXPlayer(identifier, src, data)
|
||||||
@@ -89,7 +89,7 @@ else
|
|||||||
Wait(50)
|
Wait(50)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not ESX.Players[_source] then
|
if not Core.Players[_source] then
|
||||||
onPlayerJoined(_source)
|
onPlayerJoined(_source)
|
||||||
end
|
end
|
||||||
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)
|
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
|
GlobalState["playerCount"] = GlobalState["playerCount"] + 1
|
||||||
ESX.Players[playerId] = xPlayer
|
Core.Players[playerId] = xPlayer
|
||||||
Core.playersByIdentifier[identifier] = xPlayer
|
Core.playersByIdentifier[identifier] = xPlayer
|
||||||
|
|
||||||
-- Identity
|
-- Identity
|
||||||
@@ -326,7 +326,7 @@ AddEventHandler("playerDropped", function(reason)
|
|||||||
|
|
||||||
Core.SavePlayer(xPlayer, function()
|
Core.SavePlayer(xPlayer, function()
|
||||||
GlobalState["playerCount"] = GlobalState["playerCount"] - 1
|
GlobalState["playerCount"] = GlobalState["playerCount"] - 1
|
||||||
ESX.Players[playerId] = nil
|
Core.Players[playerId] = nil
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@@ -359,7 +359,7 @@ AddEventHandler("esx:playerLogout", function(playerId, cb)
|
|||||||
Core.playersByIdentifier[xPlayer.identifier] = nil
|
Core.playersByIdentifier[xPlayer.identifier] = nil
|
||||||
Core.SavePlayer(xPlayer, function()
|
Core.SavePlayer(xPlayer, function()
|
||||||
GlobalState["playerCount"] = GlobalState["playerCount"] - 1
|
GlobalState["playerCount"] = GlobalState["playerCount"] - 1
|
||||||
ESX.Players[playerId] = nil
|
Core.Players[playerId] = nil
|
||||||
if cb then
|
if cb then
|
||||||
cb()
|
cb()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ AddEventHandler("onServerResourceStart", function(resource)
|
|||||||
if not npwd then
|
if not npwd then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
for _, xPlayer in pairs(ESX.Players) do
|
for _, xPlayer in pairs(Core.Players) do
|
||||||
npwd:newPlayer({
|
npwd:newPlayer({
|
||||||
source = xPlayer.source,
|
source = xPlayer.source,
|
||||||
identifier = xPlayer.identifier,
|
identifier = xPlayer.identifier,
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ local function getNearbyPlayers(source, closest, distance, ignore)
|
|||||||
end
|
end
|
||||||
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
|
if not ignore or not ignore[xPlayer.source] then
|
||||||
local entity = GetPlayerPed(xPlayer.source)
|
local entity = GetPlayerPed(xPlayer.source)
|
||||||
local coords = GetEntityCoords(entity)
|
local coords = GetEntityCoords(entity)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ function StartPayCheck()
|
|||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
while true do
|
while true do
|
||||||
Wait(Config.PaycheckInterval)
|
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 jobLabel = xPlayer.job.label
|
||||||
local job = xPlayer.job.grade_name
|
local job = xPlayer.job.grade_name
|
||||||
local salary = xPlayer.job.grade_salary
|
local salary = xPlayer.job.grade_salary
|
||||||
|
|||||||
Reference in New Issue
Block a user