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

new(source:Int)

Variables

read onlycoords:Vector3

read onlyendpoint:String

The player's IP endpoint. Personal data — handle it accordingly.

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.

read onlylastMessageMs:Int

Milliseconds since the last packet from this player.

read onlyname:String

read onlyped:Ped

The player's ped, or null before they've spawned.

read onlyping:Int

Round-trip latency in milliseconds.

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.

finalsource:Int

The server ID, also called the source.

read onlystate:StateBag

The player's replicated state bag.

read onlyteam:Int

read onlyvehicle:Vehicle

The vehicle the player is in, or null.

Methods

@:value({ reason : "Dropped" })inlinedrop(reason:String = "Dropped"):Void

Disconnects the player with a reason shown to them.

inlineemit(eventName:String, args:Rest<Dynamic>):Void

Sends an event to this player.

@:value({ type : "license" })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...").

identifiers():Array<String>

Every identifier the player presented.

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.

toString():String