OnEntityDeath
OnEntityDeath is called when a BaseCombatEntity dies, right after its health is set to zero and before the mission/statistics handling that follows in BaseCombatEntity.Die. It also fires for resource entities from ResourceEntity.OnDied.
void OnEntityDeath(BaseCombatEntity entity, HitInfo info)Parameters
| Parameter | Type | Description |
|---|---|---|
entity | BaseCombatEntity | The combat entity that died. Its life state is already Dead and health is 0 by the time the hook fires. Narrow the declared type (for example BasePlayer, BaseAnimalNPC or ResourceEntity) to only receive deaths of that kind. |
info | HitInfo | The HitInfo that caused the death. Can be null, for example when an entity is killed programmatically or dies without damage. Check Initiator and InitiatorPlayer before using them. |
Return value
Returning anything has no effect. The call site is Interface.CallHook("OnEntityDeath", this, info) with an ignored result, and the original code runs on regardless, so a returned value never prevents the kill from being processed.
How it works
The hook fires inside BaseCombatEntity.Die after health is zeroed and the life state is set to Dead, but before the game records kill credit and mission progress. It also fires from ResourceEntity.OnDied for nodes and other resources, so a plain OnEntityDeath(BaseCombatEntity entity, HitInfo info) catches nodes, animals, NPCs, players and deployed structures that die.
Use entity to inspect what died: type check with as for players, NPCs, animals, or use ShortPrefabName for prefab-level filtering. Use info for cause of death: info.InitiatorPlayer is the player that got the kill (null for environment kills, decay, or NPC kills), info.damageTypes.GetMajorityDamageType() tells you the damage source, and info.isHeadshot distinguishes headshot kills.
Declaring a more specific parameter type narrows dispatch: a BasePlayer parameter means the hook only runs for player deaths, a ResourceEntity parameter only for resource deaths. info can legitimately be null, and so can InitiatorPlayer.
The return value is ignored here, so you cannot cancel a death from this hook.
Other signatures
Oxide also calls OnEntityDeath from other places in the game with these parameter types. Declare the overload you need, or several:
void OnEntityDeath(ResourceEntity resourceEntity, HitInfo info)
Example plugin: Reward players with a configurable item for player kills
using System.Linq;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
namespace Oxide.Plugins
{
[Info("Kill Reward Items", "RustPluginGenerator", "1.0.0")]
[Description("Gives players a configurable item stack when they kill another player")]
public class KillRewardItems : RustPlugin
{
private const string PermEnabled = "killrewarditems.enabled";
private class PluginConfig
{
[JsonProperty("Item shortname")]
public string Shortname = "scrap";
[JsonProperty("Item amount")]
public int Amount = 10;
[JsonProperty("Only for players with permission")]
public bool PermissionOnly = false;
}
private PluginConfig config;
private bool shortnameWarningSent;
protected override void LoadDefaultConfig() => config = new PluginConfig();
protected override void LoadConfig()
{
base.LoadConfig();
try
{
config = Config.ReadObject<PluginConfig>();
if (config == null) throw new Exception();
}
catch
{
PrintWarning("Configuration file is invalid, using defaults");
LoadDefaultConfig();
}
SaveConfig();
}
protected override void SaveConfig() => Config.WriteObject(config);
protected override void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>
{
["Reward"] = "You received {0}x {1} for killing {2}.",
["InvalidItem"] = "The configured reward item shortname is not valid."
}, this);
}
private void Init()
{
permission.RegisterPermission(PermEnabled, this);
}
private string Msg(string key, string userId = null, params object[] args)
=> string.Format(lang.GetMessage(key, this, userId), args);
private void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
{
var victim = entity as BasePlayer;
if (victim == null || info == null || info.InitiatorPlayer == null) return;
var killer = info.InitiatorPlayer;
if (killer == victim || killer.IsNpc || killer.IsDead() || !killer.IsConnected) return;
if (config.PermissionOnly && !permission.UserHasPermission(killer.UserIDString, PermEnabled)) return;
var itemDefinition = ItemManager.FindItemDefinition(config.Shortname);
if (itemDefinition == null)
{
if (!shortnameWarningSent)
{
shortnameWarningSent = true;
PrintWarning(Msg("InvalidItem"));
}
return;
}
var item = ItemManager.CreateByItemID(itemDefinition.itemid, Math.Max(1, config.Amount));
if (item == null) return;
killer.GiveItem(item);
killer.ChatMessage(Msg("Reward", killer.UserIDString, item.amount, item.info.displayName.english, victim.displayName));
}
}
}The plugin registers a player-facing hook and gives the killer a configured item stack whenever they kill another player. In OnEntityDeath, a plain BaseCombatEntity parameter is declared, then the entity is cast with as BasePlayer to skip everything that is not a player. A null-safe info check, an InitiatorPlayer check, and a InitiatorPlayer == entity guard skip environment kills and suicides. ItemManager.CreateByName builds the configured shortname; a null result means the shortname is invalid, so it is warned once and skipped. The item goes through GiveItem, which drops it if the inventory is full. Msg sends a localized chat line, and shortname/amount come from a validated config class.
Common use cases
Kill rewards for PvP
Give the killing player scrap, a keycard or an item stack after every player kill, keyed off
info.InitiatorPlayer, with team and suicide checks fromentityandcurrentTeam.Track NPC and animal kills
Record ScientistNPC and animal kills per player into oxide/data for stats or a leaderboard, since the hook fires for every BaseCombatEntity death and covers the whole server.
Resource node death detection
Detect when a ResourceEntity dies to award a bonus item or broadcast an event, using the same hook with a
ResourceEntityfirst parameter to only receive resource deaths.
Pitfalls
info can be null
Entities killed programmatically or dying from decay or environment damage can call into this hook with a null HitInfo. Dereference
info.InitiatorPlayeronly after a null check, or the plugin throws on the first such death.It fires for everything that can die
All BaseCombatEntities enter here, including nodes, animals, NPCs and structures. Filter with
ascasts or narrower parameter types, or you will process every death on the server.The return value is ignored
You cannot prevent death or damage here. Use
OnEntityTakeDamagefor pre-damage logic, and use this hook for consequences only, so you do not double-award rewards.
Plugin recipes that use OnEntityDeath
- How to make a Rust barrel scrap bonus plugin (Oxide/Carbon)Awards bonus scrap when a player destroys a loot barrel, with a configurable chance and a VIP multiplier permission. It uses the OnEntityDeath hook to detect barrel deaths and the killing player.
- How to make a Rust bounty plugin (scrap bounty pool)A scrap bounty system where players fund a pool on a target and the killer collects it, using the OnEntityDeath hook plus a data file for persistence and team checks to block friendly claims.
- How to make a Rust Bradley APC and patrol helicopter kill announcer pluginTracks damage dealt to the Bradley APC and patrol helicopter, then announces in chat which player did the most damage and the map grid where the boss died. Uses OnEntityTakeDamage and OnEntityDeath.
- How to make a Rust duels plugin (1v1 challenge system)Adds a player-vs-player duel system where /duel <player> sends a challenge, /duel accept starts it, and damage outside the duel pair is blocked. Uses OnEntityTakeDamage, OnEntityDeath and OnPlayerDisconnected.
- How to make a Rust first blood plugin (announce + reward first kill)Announces the first player kill after a restart as First Blood and pays the killer a configured reward. It listens to OnEntityDeath, stores the claim time in oxide/data so it survives restarts, and optionally wipes that data on a new save via OnNewSave.
- How to make a Rust headshot announcement plugin (bonus item on headshot kill)Announces headshot kills in chat with killer, victim, weapon and distance, and grants a configurable bonus item when the shot traveled at least a minimum distance. Uses OnEntityDeath and reads HitInfo.isHeadshot.
- How to make a Rust heli and Bradley loot lock plugin (PvE ownership)Tracks damage dealt to the Patrol Helicopter and Bradley APC per player and locks the crates they drop for a configurable time, allowing only the top damager and their team to loot. Uses OnEntityTakeDamage, OnEntityDeath, OnEntitySpawned and CanLootEntity.
- How to make a Rust kill feed plugin (CUI, last 5 kills)Draws a CUI kill feed on the right side of every player's screen showing the last 5 player kills with killer, weapon and victim, using OnEntityDeath. Entries expire after a configurable number of seconds.
- How to make a Rust kill rewards plugin (scrap per kill, Oxide)Awards a configurable item (scrap by default) to the killer on every player kill, with a separate headshot bonus and optional permission gate. It hooks OnEntityDeath, reads info.InitiatorPlayer, and skips NPC victims, suicides and team kills.
- How to make a Rust kill streak plugin (Oxide/Carbon)Tracks consecutive player kills per user, announces configurable milestones in global chat and grants item rewards, then resets the streak when the player dies or disconnects. Uses OnEntityDeath and OnPlayerDisconnected.
- How to make a Rust leaderboard UI plugin (CUI top 10)Tracks kills, deaths and K/D per player in oxide/data and renders a CUI top-10 board with /top. Uses OnEntityDeath to record kills/deaths and OnServerSave to flush data.
- How to make a Rust NPC kill counter plugin (scientists and animals)Tracks how many NPCs each player kills, split into scientist and animal totals, stores them in oxide/data, and announces every 100th kill. It uses the OnEntityDeath hook and the /npckills chat command.
- How to make a Rust NPC kill rewards plugin (economy payouts)Pays a configurable item or Economics reward when a player lands the killing blow on a scientist, animal, Bradley APC or patrol helicopter, using OnEntityDeath with a prefab-name reward table.
- How to make a Rust NPC loot lock plugin (owner + team only)Locks NPC corpses to the killer and their team for a configurable number of seconds after death, then opens them to everyone. Uses OnEntityDeath to record ownership and CanLootEntity to gate looting.
- How to make a Rust NPC spawn points plugin (respawn timers)This plugin lets admins record NPC spawn points with a chat command and keeps a scientist spawned at each point, respawning it N seconds after death. It uses OnEntityDeath to detect kills, OnServerInitialized to respawn saved points, and the Oxide data file system plus a timers-based respawn loop.
- How to make a Rust patrol helicopter event plugin (admin calls + timer)This plugin spawns a patrol helicopter on demand with /callheli or on a repeating timer, announces the spawn to chat, and broadcasts who destroyed it using OnEntityDeath.
- How to make a Rust player stats plugin (K/D tracker)A plugin that records kills, deaths, headshots and NPC kills per player in oxide/data, shows them with /stats [player], and optionally wipes the data on a new save. It uses OnEntityDeath to detect who killed whom and OnNewSave to reset on wipe.
- How to make a Rust top players command plugin (stat leaderboard)Tracks kills, deaths and playtime per player and prints a top 10 leaderboard in chat through /top kills|deaths|playtime. Uses OnEntityDeath and OnPlayerDisconnected.
Build a plugin with OnEntityDeath
Describe what should happen and get a compiled plugin that uses this hook.
Edit the prompt on the next screen. 2 free plugins a month, no card.
Last updated Oct 26, 2026. Found a mistake? Email support@rustplugingenerator.com.
Build a plugin with OnEntityDeath
Generate