Skip to content

players.setSurvivalPolicy

Sets what may kill or arrest one player. Use it for spawn protection, safe zones, an admin god mode, a “downed” state instead of death, minigames where losing should not kill, or a jail of your own instead of the game’s Busted screen.

The player’s own game applies it to every hit as it lands, so a one-shot kill is stopped too, and nothing waits for your gamemode. With nothing set, a player dies and gets busted as in the game.

players.setSurvivalPolicy(player: PlayerTarget, policy: PlayerSurvivalPolicy): Promise<ActionResult>
Name Type Description
player PlayerTarget The player, or their ID.
policy PlayerSurvivalPolicy The whole policy. A field you leave out goes back to its default; {} is the game’s own behaviour.

A promise of an ActionResult: applied once the server has it, rejected with invalid-policy (a field out of range, an empty or unknown protectedFrom) or player-not-found.

  • isInvulnerable: true: a protected hit takes no health and no armour.
  • minimumHealth: 20: a protected hit never takes health below 20 (a floor under 1 counts as 1). It does not raise health that is already lower. playerHealthOrArmourDecreased still fires as health drops to the floor, so you can put the player in a downed state there.
  • protectedFrom picks the hits both of these cover; see DamageCause. A hit is protected when who did it or how is in the list, so ["players"] covers another player’s bullets, grenades and car.
  • A protected hit still knocks the player over or throws them. playerDied never fires for a death the policy stopped.

With arrestHandling: "gamemode", a cop’s arrest shows no Busted screen and does not move the player: they stay where they were, alive and still wanted, and playerArrested tells you. Cops keep trying while the player is wanted, so clear the wanted level or move the player there. With "game" (the default) the game busts them and they respawn through playerSpawnRequest, as before.

Ten seconds of spawn protection, and a jail of your own.

gamemodes/my-mode.ts
import { players, server } from "nativemp";
const JAIL: [number, number, number] = [264.6, 77.6, 1001.0];
server.on("playerSpawned", async ({ player }) => {
await players.setSurvivalPolicy(player, { isInvulnerable: true, arrestHandling: "gamemode" });
setTimeout(() => void players.setSurvivalPolicy(player, { arrestHandling: "gamemode" }), 10_000);
});
server.on("playerArrested", async ({ player, isHandledByGamemode }) => {
if (!isHandledByGamemode) return;
await players.setWantedLevel(player, 0);
await players.setPosition(player, JAIL, 0, 6);
});

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