Skip to content
RustPluginGenerator

OnPlayerCorpseSpawn

OnPlayerCorpseSpawn is called at the start of BasePlayer.CreateCorpse, before the server builds the corpse entity for a dying or dead player. Returning a non-null object cancels the corpse entirely.

Signature
object OnPlayerCorpseSpawn(BasePlayer player)

Parameters

Hook parameters
ParameterTypeDescription
playerBasePlayerThe BasePlayer whose corpse is about to be created. Use it to read identity, inventory, position and team before the body is built.

Return value

Return null to let the server create the corpse normally. Return any non-null value to abort CreateCorpse early: the method returns null, the game gets no corpse entity, and the death inventory stays on the player object instead of being lootable on the ground.

How it works

The hook fires inside BasePlayer.CreateCorpse, which the server calls when it needs to turn a player into a lootable body. Oxide invokes it before the corpse entity is created and before the death inventory is transferred into it, so at this point there is no corpse object to modify yet. The single player argument is the player being converted; the player may already be dead, wounded or disconnected but is still valid to read for UserIDString, displayName, position and inventory.

Because the dispatch checks types, declaring BasePlayer (the given type) receives every call. There is no narrower useful overload here; a subclass would not match. This hook is the only way to veto corpse creation from a plugin. If you just want to touch the finished corpse, use OnPlayerCorpseSpawned or OnPlayerDeath instead, since the body and its inventory exist there.

Use it sparingly. It fires once per corpse per death, not per tick, so a permission check plus a small amount of logic is cheap. Anything that mutates the player's inventory should run before the corpse is built, otherwise the items may already be moved.

Example plugin: Suppress corpses for whitelisted players

NoCorpseForVips.cs
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;

namespace Oxide.Plugins
{
    [Info("No Corpse For Vips", "RustPluginGenerator", "1.0.0")]
    [Description("Lets permission holders die without leaving a lootable corpse behind")]
    public class NoCorpseForVips : RustPlugin
    {
        private const string PermNoCorpse = "nocorpseforvips.use";

        private PluginConfig config;

        private class PluginConfig
        {
            [JsonProperty("Show message to the player")]
            public bool ShowMessage { get; set; } = true;
        }

        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>
            {
                ["CorpseBlocked"] = "Your body was removed, nothing can be looted from your death."
            }, this);
        }

        private string Msg(string key, string userId = null, params object[] args) => string.Format(lang.GetMessage(key, this, userId), args);

        private void Init()
        {
            permission.RegisterPermission(PermNoCorpse, this);
        }

        private object OnPlayerCorpseSpawn(BasePlayer player)
        {
            if (player == null || player.IsNpc) return null;
            if (!permission.UserHasPermission(player.UserIDString, PermNoCorpse)) return null;

            player.inventory?.Strip();

            if (config.ShowMessage && player.IsConnected)
            {
                player.ChatMessage(Msg("CorpseBlocked", player.UserIDString));
            }

            // Non-null return aborts BasePlayer.CreateCorpse.
            return true;
        }
    }
}

The plugin grants a permission that stops selected players from leaving a lootable body. OnPlayerCorpseSpawn checks permission.UserHasPermission on the dying player's UserIDString; if the permission is present it empties the inventory with inventory.Strip() so nothing is left behind, sends a private chat line from the language file, and returns true to cancel corpse creation. Everyone else gets null and a normal corpse. Config holds the permission name and whether the message is shown. Init registers the permission, Unload is empty because no timers or UI are used, and all player-facing text is routed through lang.

Common use cases

  • VIP death without a body

    Let donors keep their gear by stripping the inventory and cancelling the corpse, so raiders gain nothing from their death.

  • Arena and event cleanup

    Suppress corpses while an event is running to keep the arena clear and stop loot from piling up between rounds.

  • Log deaths before the body exists

    Record identity, position and inventory snapshot when the hook fires, then return null so normal corpse and loot behavior is kept.

Pitfalls

  • Items are not on the ground yet

    The corpse entity and its loot container do not exist when this hook runs, so you cannot edit the body's inventory here. Strip or record the player's inventory instead, or wait for OnPlayerCorpseSpawned.

  • Stripping is permanent

    If you cancel the corpse without stripping, the death inventory stays on the player and can be recovered on respawn or lost unexpectedly. Decide deliberately whether items should be removed or kept.

  • The return value must be non-null

    Returning false or 0 still counts as a value and cancels the corpse. Return null explicitly for the default path.

Build a plugin with OnPlayerCorpseSpawn

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

Prompt: VIP death without a body using the OnPlayerCorpseSpawn 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 OnPlayerCorpseSpawn

Generate