Skip to main content

PlayerDeath

This event is triggered when a player dies.

Server-side event

C#​

See OnPlayerDeath.

JavaScript​

Parameters​

  • player: Player - victim, the player which died.
  • reason: Number - cause hash of death (list causes: Causes).
  • killer: Player - who killed the player.

Example​

This example outputs chat message, when player dies.

function playerDeathHandler(player, reason, killer) {
const deathName = player.name;
const killerName = killer.name;
if(reason == 341774354) {
mp.players.broadcast(`${deathName} died in a chopper!`);
return;
}
mp.players.broadcast(`${killerName} killed ${deathName}. Reason: ${reason}`);
}

mp.events.add("playerDeath", playerDeathHandler);
Client-side event

C#​

public delegate void OnPlayerDeathDelegate(Player player, uint reason, Player killer, CancelEventArgs cancel);

Parameters​

  • player: the player that died, expects RAGE.Elements.Player type.
  • reason: the reason for death, expects System.UInt32 type.
  • killer: killer, expects RAGE.Elements.Player type.
  • cancel: cancel, expects RAGE.Events.CancelEventArgs type.

Example​

The example below shows a chat message to the client when a player dies.

Events.OnPlayerDeath += OnPlayerDeath;
public void OnPlayerDeath(RAGE.Elements.Player player, uint reason, RAGE.Elements.Player killer, RAGE.Events.CancelEventArgs cancel)
{
if (killer == null)
{
RAGE.Chat.Output($"{player.Name} just died ");
}
else if (reason == 539292904)
{
RAGE.Chat.Output($"{player.Name} was killed by {killer.Name} in an explosion");
}
else
{
RAGE.Chat.Output($"{player.Name} was killed by {killer.Name} ");
}
}

JavaScript​

Parameters​

  • player: Player - local player who died.
  • reason: Number - cause hash of death (list causes: Causes).
  • killer: Player - who killed the player.

Example​

This example sets up death camera effect for 5 seconds

mp.events.add("playerDeath", (player, reason, killer) => {
mp.game.graphics.startScreenEffect("DeathFailNeutralIn", 5000, false);
});