Skip to content

players.getById

Returns the latest snapshot of one player.

Renamed in 0.28 from players.get; see renamed names.

players.getById(id: number): PlayerSnapshot | undefined
Name Type Description
id number The player’s ID, as in player.id.

The player’s PlayerSnapshot snapshot, or undefined when no player with that ID is connected.

A /hp command that reads the player’s own health.

gamemodes/my-mode.ts
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);
});