PlayerDeath: Difference between revisions

From RAGE Multiplayer Wiki
mNo edit summary
No edit summary
Line 1: Line 1:
This event is triggered when a player dies.
This event is triggered when a player dies.
{{ServersideCsJsEvent}}
{{ServersideCsJsEvent}}
{{CSharpContainer|1=
See [https://wiki.gtanet.work/index.php?title=OnPlayerDeath on GTA Network Wiki].
}}
{{JSContainer|
{{JSContainer|
{{Parameters}}
{{Parameters}}
* '''player''' - player, which died.
* '''player''': {{RageType|Player}} - victim, the player which died.
* '''reason ''' - cause hash of death ('''list causes:''' [[Causes of death| Causes]]).
* '''reason''': {{RageType|Number}} - cause hash of death ('''list causes:''' [[Causes of death| Causes]]).
* '''killer''' - who killed the player.
* '''killer''': {{RageType|Player}} - who killed the player.


{{Example}}
{{Example}}
Line 23: Line 28:
</syntaxhighlight>
</syntaxhighlight>
}}
}}
{{ClientsideCsJsEvent}}
{{ClientsideCsJsEvent}}
{{CSharpContainer|
{{CSharpContainer|
<syntaxhighlight lang="c#">
<syntaxhighlight lang="csharp">
public delegate void OnPlayerDeathDelegate(Player player, uint reason, Player killer, CancelEventArgs cancel);
public delegate void OnPlayerDeathDelegate(Player player, uint reason, Player killer, CancelEventArgs cancel);
</syntaxhighlight>
</syntaxhighlight>
Line 38: Line 45:
The example below shows a chat message to the client when a player dies.
The example below shows a chat message to the client when a player dies.


<syntaxhighlight lang="c#">
<syntaxhighlight lang="csharp">
Events.OnPlayerDeath += OnPlayerDeath;
Events.OnPlayerDeath += OnPlayerDeath;
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang="c#">
<syntaxhighlight lang="csharp">
public void OnPlayerDeath(RAGE.Elements.Player player, uint reason, RAGE.Elements.Player killer, RAGE.Events.CancelEventArgs cancel)
public void OnPlayerDeath(RAGE.Elements.Player player, uint reason, RAGE.Elements.Player killer, RAGE.Events.CancelEventArgs cancel)
{
{
Line 59: Line 66:
</syntaxhighlight>
</syntaxhighlight>
}}
}}
{{JSContainer|
{{Parameters}}
* '''player''': {{RageType|Player}} - local player who died.
* '''reason''': {{RageType|Number}} - cause hash of death ('''list causes:''' [[Causes of death| Causes]]).
* '''killer''': {{RageType|Player}} - who killed the player.
{{Example}}
This example sets up death camera effect for 5 seconds
<syntaxhighlight lang="javascript" style="width: 98%; background-color: #E4F1FE;">
mp.events.add("playerDeath", (player, reason, killer) => {
    mp.game.graphics.startScreenEffect("DeathFailNeutralIn", 5000, false);
});
</syntaxhighlight>
}}
==See also==
==See also==
{{Player_events}}
{{Player_events}}

Revision as of 13:02, 23 May 2019

This event is triggered when a player dies.

Server-Side
Event

 C#  JavaScript



C# Syntax


JavaScript Syntax

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#  JavaScript



C# Syntax

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 Syntax

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);
});


See also

Checkpoint

Colshape

Entity

Player

Streaming

Vehicle

Waypoint