OnBackpackDrop
OnBackpackDrop is called when a player's backpack item is about to be dropped by the game, including automatic drops such as losing the backpack on death.
object OnBackpackDrop(Item backpackItem, PlayerInventory playerInventory)Parameters
| Parameter | Type | Description |
|---|---|---|
backpackItem | Item | The backpack Item (the wearable item object) that the game is about to drop on the ground, taken from PlayerInventory.GetAnyBackpack(). Null-check it before use. |
playerInventory | PlayerInventory | The PlayerInventory (the player's inventory object) that triggered the drop. Use playerInventory.baseEntity to reach the BasePlayer who is dropping the backpack. |
Return value
Returning null (or nothing) lets the game continue and drop the backpack normally. Returning any non-null value cancels the drop so the backpack item stays in the player's inventory.
How it works
The hook fires inside PlayerInventory.TryDropBackpack, right after the game fetches the player's backpack with GetAnyBackpack(). It only runs when a backpack item actually exists and the inventory belongs to a server-authoritative entity, so there is no call when the player has no backpack equipped. The hook receives the backpack Item and the PlayerInventory that owns it; use playerInventory.baseEntity to get the BasePlayer and confirm it is a real player with as BasePlayer before acting.
The hook is a natural place to log or audit backpack drops, to announce a death drop to the team, or to react to the backpack before it leaves the inventory. Because this is a void method, the only thing you can do directly is stop the drop by returning a non-null value.
If the game only calls this when a backpack exists, returning non-null cancels Item.Drop entirely, so the backpack stays in the inventory. If you only want to modify or inspect the item, return null and the drop proceeds normally. Declaring backpackItem as Item is the only type expected here; there is no narrower variant.
Example plugin: Keep backpacks in inventory unless the player opts in with a permission
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Backpack Drop Guard", "RustPluginGenerator", "1.0.0")]
[Description("Controls who may drop their backpack and records every drop attempt.")]
public class BackpackDropGuard : RustPlugin
{
private const string PermAllow = "backpackdropguard.allow";
private const string DataFile = "BackpackDropGuard";
private PluginConfig config;
private List<DropRecord> records = new List<DropRecord>();
private class PluginConfig
{
[JsonProperty("Log drop attempts")]
public bool LogDrops { get; set; } = true;
[JsonProperty("Notify player when drop blocked")]
public bool NotifyPlayer { get; set; } = true;
}
private class DropRecord
{
[JsonProperty("Player name")]
public string Name { get; set; }
[JsonProperty("Steam ID")]
public string Id { get; set; }
[JsonProperty("Backpack skin")]
public ulong Skin { get; set; }
}
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>
{
["Blocked"] = "You are not allowed to drop your backpack here."
}, 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(PermAllow, this);
records = Interface.Oxide.DataFileSystem.ReadObject<List<DropRecord>>(DataFile)
?? new List<DropRecord>();
}
private void Unload()
{
if (config.LogDrops)
Interface.Oxide.DataFileSystem.WriteObject(DataFile, records);
}
private object OnBackpackDrop(Item backpackItem, PlayerInventory playerInventory)
{
if (backpackItem == null || playerInventory == null || playerInventory.baseEntity == null)
return null;
var player = playerInventory.baseEntity as BasePlayer;
if (player == null || player.IsNpc)
return null;
if (config.LogDrops)
{
records.Add(new DropRecord { Name = player.displayName, Id = player.UserIDString, Skin = backpackItem.skin });
}
if (permission.UserHasPermission(player.UserIDString, PermAllow))
return null;
if (config.NotifyPlayer)
player.ChatMessage(Msg("Blocked", player.UserIDString));
return true;
}
}
}The plugin cancels every backpack drop and only allows it for players who hold the backpackdropguard.allow permission. On load it registers the permission and reads config. In OnBackpackDrop it resolves the BasePlayer from playerInventory.baseEntity, writes an audit line to the BackpackDropGuard data file so admins can review who tried to drop, and checks the permission. If the player is permitted it returns null so the normal drop proceeds; otherwise it returns true to block the drop and sends a localized chat message. Data is saved on unload.
Common use cases
Audit backpack drops
Record every backpack drop with the player's name, Steam ID and the item skin into an oxide/data file for admin review.
Anonymize death drops
Cancel the drop and instead remove the backpack with
Remove(), or spawn a different container, to control what other players can loot.Permission-gated drops
Block dropping unless the player has a permission, preventing accidental loss of a loot-filled backpack.
Pitfalls
Not every backpack drop goes through this hook
Only drops routed through
PlayerInventory.TryDropBackpackfire the hook. Removing the item withRemove()or moving it viaMoveToContainerbypasses it entirely.The inventory owner can be null
playerInventory.baseEntitycan be null or not aBasePlayer; cast withas BasePlayerand return null if the cast fails so you do not block server-side inventory operations.Blocking does not alert the player
Returning non-null silently cancels the drop, so send a chat message yourself or the player will not understand why the backpack stayed equipped.
Build a plugin with OnBackpackDrop
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 OnBackpackDrop
Generate