From e08c9418643e54f1acfaa981abaeccbcf2e8cc38 Mon Sep 17 00:00:00 2001 From: Kenshin13 <63159154+Kenshiin13@users.noreply.github.com> Date: Sun, 6 Jul 2025 13:32:47 +0200 Subject: [PATCH] fix: DoesPlayerExist doesnt seem to work properly. Also fix stale cb in onPlayerDropped --- [core]/es_extended/server/main.lua | 28 +++++++++---------- .../server/modules/functions.lua | 4 +-- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/[core]/es_extended/server/main.lua b/[core]/es_extended/server/main.lua index 5745f307..2b393af9 100644 --- a/[core]/es_extended/server/main.lua +++ b/[core]/es_extended/server/main.lua @@ -71,20 +71,6 @@ end ---@param reason string ---@param cb function? local function onPlayerDropped(playerId, reason, cb) - local xPlayer = ESX.GetPlayerFromId(playerId) - - if not xPlayer then - return - end - - TriggerEvent("esx:playerDropped", playerId, reason) - local job = xPlayer.getJob().name - local currentJob = Core.JobsPlayerCount[job] - Core.JobsPlayerCount[job] = ((currentJob and currentJob > 0) and currentJob or 1) - 1 - - GlobalState[("%s:count"):format(job)] = Core.JobsPlayerCount[job] - Core.playersByIdentifier[xPlayer.identifier] = nil - local p = not cb and promise:new() local function resolve() if cb then @@ -94,6 +80,18 @@ local function onPlayerDropped(playerId, reason, cb) end end + local xPlayer = ESX.GetPlayerFromId(playerId) + if not xPlayer then + return resolve() + end + + TriggerEvent("esx:playerDropped", playerId, reason) + local job = xPlayer.getJob().name + local currentJob = Core.JobsPlayerCount[job] + Core.JobsPlayerCount[job] = ((currentJob and currentJob > 0) and currentJob or 1) - 1 + + GlobalState[("%s:count"):format(job)] = Core.JobsPlayerCount[job] + Core.SavePlayer(xPlayer, function() GlobalState["playerCount"] = GlobalState["playerCount"] - 1 ESX.Players[playerId] = nil @@ -164,7 +162,7 @@ if not Config.Multichar then return deferrals.done() end - if DoesPlayerExist(xPlayer.source --[[@as string]]) then + if GetPlayerPing(xPlayer.source --[[@as string]]) > 0 then return deferrals.done( ("[ESX] There was an error loading your character!\nError code: identifier-active\n\nThis error is caused by a player on this server who has the same identifier as you have. Make sure you are not playing on the same account.\n\nYour identifier: %s"):format(identifier) ) diff --git a/[core]/esx_multicharacter/server/modules/functions.lua b/[core]/esx_multicharacter/server/modules/functions.lua index 07451bda..69975e54 100644 --- a/[core]/esx_multicharacter/server/modules/functions.lua +++ b/[core]/esx_multicharacter/server/modules/functions.lua @@ -70,7 +70,7 @@ function Server:OnConnecting(source, deferrals) local plyRef = ESX.Players[identifier] ---@type number|string If player has not chosen character yet, plyRef = source, otherwise plyRef = identifier prefix ("char1", "char2", etc.) if type(plyRef) == "number" then - if DoesPlayerExist(plyRef --[[@as string]]) then + if GetPlayerPing(plyRef --[[@as string]]) > 0 then return reject() end @@ -83,7 +83,7 @@ function Server:OnConnecting(source, deferrals) return deferrals.done() end - if DoesPlayerExist(xPlayer.source --[[@as string]]) then + if GetPlayerPing(xPlayer.source --[[@as string]]) > 0 then return reject() end