class Player
package fivem.server.core
A connected player, addressed by their server ID.
The server ID (source) is the single identifier that means the same thing
everywhere — in events, in state bags, and on every client. It is assigned
on connect and reused after that player leaves, so never use it as a
database key; use an identifier for that.
Events.onNet("shop:buy", (item:String) -> {
var player = Player.fromSource(Events.source());
if (player == null) return;
if (player.coords.distance(shopPoint) > 5) return; // always re-check
grant(player.identifier("license"), item);
});
Most server player natives take the source as a string rather than a
number — a longstanding FiveM quirk. This class holds an Int and does the
conversion for you.
Static methods
staticfromSource(source:Int):Player
Wraps a server ID, or returns null if no such player is connected.
Always use this rather than new Player(...) on anything derived from
a network event: a client can send whatever it likes, and a stale or
invented source would otherwise sail straight through.
Constructor
Variables
read onlyisConnected:Bool
Whether the player is still connected.
Tested through the name because there is no direct native for it.
FXServer answers for a source that has gone with either nil or the
literal "**Invalid**" depending on how far through disconnecting it
is, so both count as gone.
routingBucket:Int
The routing bucket the player is in. Players in different buckets are completely invisible to one another — the mechanism behind instanced interiors and per-player worlds.
Methods
inlineidentifier(type:String = "license"):String
A stable identifier of the given type, or null if the player has
none.
Common types are "license", "license2", "steam", "discord",
"fivem", "ip". "license" is the usual database key: it is always
present and doesn't depend on the player linking an external account.
The returned value includes its prefix ("license:abc123...").
inlineisAceAllowed(object:String):Bool
Whether the player is granted an ACE permission — the server's built-in
authorisation system, configured with add_ace / add_principal in
server.cfg.