players.setWantedLevel
Sets a player’s wanted level, 0 to 6 stars. The player’s own game runs the police that come after them.
Signature
Section titled “Signature”players.setWantedLevel(player: PlayerTarget, level: number): Promise<ActionResult>Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
player |
PlayerTarget |
The player, or their ID. |
level |
number |
Stars, 0 to 6. 0 clears it. |
Returns
Section titled “Returns”A promise of an ActionResult: applied once the server has set it (also when the
player already had that level), or rejected with a code: vetoed when
playerWantedLevelChangeRequest refused it. A newer call
replaces one still waiting for that decision. applied means the server set it; the player’s game follows.
Example
Section titled “Example”A /surrender that clears the stars.
import { chat, commands, players } from "nativemp";
commands.register("surrender", async (player) => { const result = await players.setWantedLevel(player, 0); if (result.status !== "applied") chat.sendServerMessage(result.status === "rejected" ? result.code : "timeout", player);});Related
Section titled “Related”playerWantedLevelChanged: the level changed, for any reasonplayerWantedLevelChangeRequest: decide before it changesActionResult: the result and its codesPlayerSnapshot:wantedin the snapshot
A captured Player keeps this effect bound to its connection across awaits; see Async handlers.