fix: DoesPlayerExist doesnt seem to work properly. Also fix stale cb in onPlayerDropped

This commit is contained in:
Kenshin13
2025-07-06 13:32:47 +02:00
parent 70a10383a7
commit e08c941864
2 changed files with 15 additions and 17 deletions
+13 -15
View File
@@ -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)
)
@@ -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