playerDisconnected
Tells your gamemode when a player leaves, for any reason: they quit, timed out, were kicked or banned.
Renamed in 0.28 from disconnect; see renamed names.
Signature
Section titled “Signature”server.on("playerDisconnected", async ({ player, reason }, { signal }) => void)Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
player |
PlayerSnapshot |
The player. |
reason |
string |
Why, as the server recorded it: disconnected when they simply left. |
Example
Section titled “Example”Save a player’s data when they leave.
The session retires immediately. Cleanup runs once through reserved capacity and can overlap an old handler’s
uncooperative I/O. It may save external state and broadcast a departure; targeting the departed PlayerSnapshot fails.
Its signal follows the runtime lifetime. Cancellation cannot roll back a query or your own map writes.
See Async handlers and player sessions.
import { server } from "nativemp";
server.on("playerDisconnected", async ({ player, reason }) => { server.log(`${player.name} left (${reason})`); // await saveAccount(player.name);});Related
Section titled “Related”playerConnected: a player has joined