Skip to content
RustPluginGenerator

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.

Signature
void OnEntityDeath(BaseCombatEntity entity, HitInfo info)

Parameters

Hook parameters
ParameterTypeDescription
entityBaseCombatEntityThe 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.
infoHitInfoThe 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

KillRewardItems.cs
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 from entity and currentTeam.

  • 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 ResourceEntity first 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.InitiatorPlayer only 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 as casts 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 OnEntityTakeDamage for pre-damage logic, and use this hook for consequences only, so you do not double-award rewards.

Plugin recipes that use OnEntityDeath

Build a plugin with OnEntityDeath

Describe what should happen and get a compiled plugin that uses this hook.

Prompt: Kill rewards for PvP using the OnEntityDeath hook, with a config file and a permission
Generate this plugin

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