Oxygen

OnPlayerDeath

This hook is triggered when a player dies. It provides detailed information about the cause of death, the killer (if any), and the circumstances of the event.

Definition

public override void OnPlayerDeath(PlayerBase player, DeathData info) {}

Parameters

ParameterTypeDescription
playerPlayerBaseThe instance of the player who died.
infoDeathDataA struct containing data about the death event and the killer.

DeathData Struct

The info parameter provides the following properties:

PropertyTypeDescription
KillerIdstringThe SteamID64 or identifier of the killer.
KillerNamestringThe name of the player or entity that caused the death.
DeadTypestringThe category of death .
ReasonstringThe specific cause of death.
EventboolReturns true if the death occurred during a specific server event.
DistancefloatThe distance between the killer and the victim at the time of death.

Usage Example

public override void OnPlayerDeath(PlayerBase player, DeathData info)
{
    if (!string.IsNullOrEmpty(info.KillerName))
    {
        Console.WriteLine($"{player.Name} was killed by {info.KillerName} from {info.Distance}m ({info.Reason})");
    }
    else
    {
        Console.WriteLine($"{player.Name} died due to {info.Reason}");
    }
}

On this page