refactor(server/functions): ESX.GetPlayerFromIdentifier

add new table: Core.playersByIdentifier
removed for loop from GetPlayerFromIdentifier.
This commit is contained in:
Csoki
2023-01-22 14:14:20 +01:00
parent bb868b864d
commit becdf1ec49
3 changed files with 6 additions and 5 deletions
+2
View File
@@ -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))
+1 -5
View File
@@ -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)
+3
View File
@@ -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