Skip to content

damage.setPlayerDamagePolicy

Sets what players’ hits on each other do. The server applies it to each hit as it arrives, so there is no decision to answer per hit: an ask on every bullet would hold every bullet back.

Renamed in 0.28 from damage.setPolicy; see renamed names.

damage.setPlayerDamagePolicy(policy: DamagePolicy): Promise<ActionResult>
Name Type Description
policy DamagePolicy The whole policy. It replaces the one before; {} is the default.

A promise of an ActionResult: applied, or invalid-policy for a field of the wrong type, a player id outside 1-65535, a team that is not a whole number or a scale outside 0-100.

The policy applies to the hits another player’s game reports on a player: shots, punches, explosions and cars running the player over. That is every hit one player lands on another, and the hits of NPCs that another player’s game runs. The NPCs a player’s own game runs (the police chasing that player, a gang it walked into) hurt the player in that game directly; the policy does not reach them.

A hit the policy turns off never reaches the player’s game: no damage, no reaction. A scale of 0 leaves a hit that does no damage. playerHealthOrArmourDecreased still reports every health and armour loss, whatever caused it, and playerHitEntity reports each hit that passed, with the amount after the policy.

A gamemode that loads or reloads starts with the default policy: every hit at full damage.

Two teams, no friendly fire, and the first player in takes half damage.

gamemodes/teams.ts
import { damage, server } from "nativemp";
const teams: Record<number, number> = {};
let vip = 0;
server.on("playerSpawned", async ({ player }) => {
teams[player.id] = player.id % 2;
if (!vip) vip = player.id;
await damage.setPlayerDamagePolicy({ friendlyFire: false, teams, playerDamagePercent: { [vip]: 0.5 } });
});