class Players
package fivem.server.core
The connected-player registry, plus the connection lifecycle hooks.
Players.onJoined(player -> Logger.info("join", player.name));
Players.onDropped((source, reason) -> saveCharacter(source));
for (player in Players.near(robberyPoint, 100.0)) {
player.emit("alarm:triggered");
}
Unlike the client's Player.all(), this really is everyone on the server —
there is no streaming distance to limit it.
Static methods
staticclosest(position:Vector3, radius:Float = 1e9):Player
The closest player to position within radius, or null.
staticfindByIdentifier(value:String, type:String = "license"):Player
The player whose identifier of type matches value, or null.
staticonConnecting(handler:(name:String, setKickReason:(reason:String) ‑> Void, deferrals:Dynamic) ‑> Void):Void
Runs handler while a player is still connecting, before they have a
source.
Call deferrals.done("reason") to reject them, or
deferrals.done() to let them in. The handler must settle the
deferral, or the player hangs on the connecting screen.
staticonDropped(handler:(source:Int, reason:String) ‑> Void):Void
Runs handler when a player disconnects, with their source and the
stated reason.
The Player object is deliberately not passed: by the time this fires
the player is already gone, so their ped, coords and identifiers are no
longer readable. Anything needed at disconnect has to be cached while
they were still connected.
staticonJoined(handler:(player:Player) ‑> Void):Void
Runs handler once a player has fully connected and their client is
ready to receive events.
This fires on playerJoining, not playerConnecting. The difference
matters: during playerConnecting the player has no source yet and
can't be sent anything, so it is only useful for accepting or rejecting
the connection — see onConnecting.