PlayerDeath: Difference between revisions

From RAGE Multiplayer Wiki
No 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}}
==Parameters==
{{JSContainer|
{{Parameters}}
* '''player'''  - player, which died.
* '''player'''  - player, which died.
* '''reason ''' - cause hash of death ('''list causes:''' [[Causes of death| Causes]]).
* '''reason ''' - cause hash of death ('''list causes:''' [[Causes of death| Causes]]).
* '''killer'''  - who killed the player.
* '''killer'''  - who killed the player.


==Example==
{{Example}}
This example outputs chat message, when player dies.
This example outputs chat message, when player dies.
{{ServerSide}}
<syntaxhighlight lang="javascript" style="width: 98%; background-color: #E4F1FE;">
<syntaxhighlight lang="javascript" style="width: 98%; background-color: #E4F1FE;">
function playerDeathHandler(player, reason, killer) {
function playerDeathHandler(player, reason, killer) {
Line 22: Line 22:
mp.events.add("playerDeath", playerDeathHandler);
mp.events.add("playerDeath", playerDeathHandler);
</syntaxhighlight>
</syntaxhighlight>
}}
{{ClientsideCsJsEvent}}
{{CSharpContainer|
<syntaxhighlight lang="c#">
public delegate void OnPlayerDeathDelegate(Player player, uint reason, Player killer, CancelEventArgs cancel);
</syntaxhighlight>
{{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.
<syntaxhighlight lang="c#">
Events.OnPlayerDeath += OnPlayerDeath;
</syntaxhighlight>
<syntaxhighlight lang="c#">
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} ");
    }
}
</syntaxhighlight>
}}
==See also==
==See also==
{{Player_events}}
{{Player_events}}

Revision as of 10:46, 29 November 2018

This event is triggered when a player dies.

Server-Side
Event

 C#  JavaScript



JavaScript Syntax

Parameters

  • player - player, which died.
  • reason - cause hash of death (list causes: Causes).
  • killer - 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} ");
    }
}


See also

Checkpoint

Colshape

Entity

Player

Streaming

Vehicle

Waypoint