players.getById
Returns the latest snapshot of one player.
Renamed in 0.28 from players.get; see renamed names.
Signature
Section titled “Signature”players.getById(id: number): PlayerSnapshot | undefinedParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
id |
number |
The player’s ID, as in player.id. |
Returns
Section titled “Returns”The player’s PlayerSnapshot snapshot, or undefined when no player with that ID is connected.
Example
Section titled “Example”A /hp command that reads the player’s own health.
import { chat, commands, players } from "nativemp";
commands.register("hp", (player) => { const health = players.getById(player.id)?.health; chat.sendServerMessage(health === null || health === undefined ? "No health reading yet." : `Health: ${health}`, player);});Related
Section titled “Related”players.listOnline: every playerPlayerSnapshot: the snapshot’s fields