Skip to content

OnPlayerDisconnect

The player is gone.

reason is "disconnected" (they left), "timed out" (nothing heard for a while) or "kicked: <reason>" with the text given to Kick or Ban. Their pid may be given to the next player who joins; their SetPlayerData goes with them once this returns. The server keeps nothing of a player: this is the moment to save what the mode keeps. A horse they controlled stays in the world (a nearby player takes it over); their dog leaves with them; every fight of theirs ends. The server announces no kick or ban to the other players: a mode that wants one says it here, as the example does.

function OnPlayerDisconnect(pid, reason)
-- ...
end
Parameter Type
pid number the player
reason string why, as above

nothing

function OnPlayerDisconnect(pid, reason)
local kick = reason:match("^kicked: (.*)")
if kick then
SendClientMessageToAll(COLOR_RED, string.format("%s was kicked (%s)", GetPlayerName(pid), kick))
else
SendClientMessageToAll(COLOR_SERVER, string.format("%s left (%s)", GetPlayerName(pid), reason))
end
removeFromQueue(pid)
end

OnPlayerConnect · Kick · the Players group of the index