Skip to content

players.spawn

Spawns a player who is held (see playerSpawnRequest), dead or busted. Fields you leave out keep the server’s defaults: the spawn point, and the skin, health and armour the player had.

players.spawn(player: PlayerTarget, options?: SpawnSettings): Promise<ActionResult>
Name Type Description
player PlayerTarget The player, or their ID.
options.position Vector3 Where to spawn, [x, y, z]. x and y within ±6000, z from -500 to 2000.
options.facingAngleRadians number Facing, in radians.
options.skin number Skin model ID, 0 to 311.
options.health number More than 0, up to 1000.
options.armour number 0 to 1000.
options.interior number The interior to spawn in: 0 outside (the default), 1 to 18 an interior’s, with a position inside that interior.

A promise of an ActionResult: applied once the player’s game has spawned them, rejected with a code, or timeout after fifteen seconds.

Hold every player until they pick a team, then spawn them at the team’s base.

gamemodes/teams.ts
import { chat, commands, players, server } from "nativemp";
const bases = {
grove: [2495.3, -1687.5, 13.5],
ballas: [2000.6, -1115.1, 26.8],
} as const;
server.on("playerSpawnRequest", () => ({ decision: "hold" }) as const);
commands.register("team", async (player, args) => {
const base = bases[args.trim() as keyof typeof bases];
if (!base) return chat.sendServerMessage("Pick /team grove or /team ballas.", player);
const result = await players.spawn(player, { position: base, health: 100 });
if (result.status !== "applied") chat.sendServerMessage("Could not spawn you, try again.", player);
});
Code Why
already-alive The player is alive and not held. Use setPosition instead.
spawn-pending An earlier spawn for this player has not finished.
invalid-position The position or facing angle is out of range.
invalid-skin The skin is not 0 to 311.
invalid-health, invalid-armour The value is out of range.
invalid-area The interior is not 0 to 18.
invalid-options A field has the wrong type.
player-not-found No player with that ID is connected.

A captured Player keeps this effect bound to its connection across awaits; see Async handlers.