mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 00:01:20 +00:00
refactor(server/functions): ESX.GetPlayerFromIdentifier
add new table: Core.playersByIdentifier removed for loop from GetPlayerFromIdentifier.
This commit is contained in:
@@ -14,6 +14,8 @@ Core.Pickups = {}
|
||||
Core.PickupId = 0
|
||||
Core.PlayerFunctionOverrides = {}
|
||||
|
||||
Core.playersByIdentifier = {}
|
||||
|
||||
AddEventHandler("esx:getSharedObject", function()
|
||||
local Invoke = GetInvokingResource()
|
||||
print(("[^1ERROR^7] Resource ^5%s^7 Used the ^5getSharedObject^7 Event, this event ^1no longer exists!^7 Visit https://documentation.esx-framework.org/tutorials/sharedevent for how to fix!"):format(Invoke))
|
||||
|
||||
@@ -245,11 +245,7 @@ function ESX.GetPlayerFromId(source)
|
||||
end
|
||||
|
||||
function ESX.GetPlayerFromIdentifier(identifier)
|
||||
for k, v in pairs(ESX.Players) do
|
||||
if v.identifier == identifier then
|
||||
return v
|
||||
end
|
||||
end
|
||||
return Core.playersByIdentifier[identifier]
|
||||
end
|
||||
|
||||
function ESX.GetIdentifier(playerId)
|
||||
|
||||
@@ -280,6 +280,7 @@ function loadESXPlayer(identifier, playerId, isNew)
|
||||
local xPlayer = CreateExtendedPlayer(playerId, identifier, userData.group, userData.accounts, userData.inventory, userData.weight, userData.job,
|
||||
userData.loadout, userData.playerName, userData.coords)
|
||||
ESX.Players[playerId] = xPlayer
|
||||
Core.playersByIdentifier[identifier] = xPlayer
|
||||
|
||||
if userData.firstname then
|
||||
xPlayer.set('firstName', userData.firstname)
|
||||
@@ -342,6 +343,7 @@ AddEventHandler('playerDropped', function(reason)
|
||||
if xPlayer then
|
||||
TriggerEvent('esx:playerDropped', playerId, reason)
|
||||
|
||||
Core.playersByIdentifier[xPlayer.identifier] = nil
|
||||
Core.SavePlayer(xPlayer, function()
|
||||
ESX.Players[playerId] = nil
|
||||
end)
|
||||
@@ -353,6 +355,7 @@ AddEventHandler('esx:playerLogout', function(playerId, cb)
|
||||
if xPlayer then
|
||||
TriggerEvent('esx:playerDropped', playerId)
|
||||
|
||||
Core.playersByIdentifier[xPlayer.identifier] = nil
|
||||
Core.SavePlayer(xPlayer, function()
|
||||
ESX.Players[playerId] = nil
|
||||
if cb then
|
||||
|
||||
Reference in New Issue
Block a user