DamagePlayer
damagePlayer
Applies authoritative script damage to a living player.
Syntax
bool damagePlayer(int playerId, number amount [, int attackerId = 0, string damageType = "script"])
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
playerId |
int |
yes | The connected player identifier. |
amount |
number |
yes | Positive damage amount, up to 100000. |
attackerId |
int |
no | Optional connected attacker id; use 0 for server or environment damage. |
damageType |
string |
no | A safe damage-type key up to 32 characters; defaults to script. |
Returns
Returns true when damage is accepted and applied; otherwise returns false.
Examples
Apply environmental fire damage:
damagePlayer(playerId, 15, 0, "fire")
Notes
- Available only in server-side resource scripts.
- The function updates authoritative health and emits
onPlayerDamage. A non-zero attacker also producesonPlayerHit. - When health reaches zero, the normal
onPlayerDeathpolicy is executed. - Damage is rejected while the target is already downed or dead.