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.
Signature
Section titled “Signature”players.setSurvivalPolicy(player: PlayerTarget, policy: PlayerSurvivalPolicy): Promise<ActionResult>Parameters
Section titled “Parameters”| 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. |
Returns
Section titled “Returns”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.
Protection
Section titled “Protection”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.playerHealthOrArmourDecreasedstill fires as health drops to the floor, so you can put the player in a downed state there.protectedFrompicks the hits both of these cover; seeDamageCause. 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.
playerDiednever fires for a death the policy stopped.
Arrests
Section titled “Arrests”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.
Example
Section titled “Example”Ten seconds of spawn protection, and a jail of your own.
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);});Related
Section titled “Related”playerArrested: a cop arrested a playerdamage.setPlayerDamagePolicy: what players’ hits on each other doplayers.setHealth: set health directly
A captured Player keeps this effect bound to its connection across awaits; see Async handlers.