CanLockerAcceptItem
CanLockerAcceptItem is called when a player drags an item into a Locker and the game checks its ItemFilter. Returning true or false overrides the default filter; returning null keeps vanilla behavior.
object CanLockerAcceptItem(Locker locker, Item item, int targetSlot, BasePlayer player)Parameters
| Parameter | Type | Description |
|---|---|---|
locker | Locker | The Locker entity the item is being moved into. Its inventory is the container receiving the item. |
item | Item | The Item instance being checked. Read info.shortname, skin, amount or category to decide whether it belongs in the locker. |
targetSlot | int | Index of the slot the item would occupy inside the locker's container. |
player | BasePlayer | The BasePlayer performing the move. Use it for permission checks or per-player limits. |
Return value
Returning a bool forces Locker.ItemFilter to return that value — true allows the item into the locker, false blocks it, and the vanilla filter is skipped either way. Returning null runs the original locker filter and the item is accepted or rejected by the game's own rules.
How it works
The hook fires inside Locker.ItemFilter(BasePlayer, Item, int), which the game runs whenever an item is moved into a locker's inventory — including drag-drop from the player's belt, main inventory, or another container. The locker's own rules (weapon restrictions, mounted weapon handling) run only if you do not return a bool.
Each parameter is useful for a different check: locker gives you the container, item gives you shortname/skin/amount, targetSlot lets you reserve specific slots, and player lets you gate the move per user or team. You do not need to narrow types here — all four arguments are passed exactly as declared, so narrowing the player type would only cause Oxide to skip your method on some calls.
Practical notes: the hook runs per item, so a stack move fires once per Item instance, not once per full stack. It fires for both manual drags and programmatic loot moves that go through the same filter path. Your player argument can be null in some entity-driven paths, so guard it before reading permissions.
Example plugin: Restrict lockers to whitelisted items per permission
using System.Linq;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("LockerItemRestrict", "RustPluginGenerator", "1.0.0")]
[Description("Restricts which items can be placed into lockers unless the player has a bypass permission")]
public class LockerItemRestrict : RustPlugin
{
private const string PermAllow = "lockeritemrestrict.allow";
private PluginConfig config;
private class PluginConfig
{
[JsonProperty("Allowed shortnames (empty = block all except bypass)")]
public List<string> AllowedShortnames = new List<string>
{
"box.wooden.large",
"metal.fragments",
"metal.refined",
"scrap",
"sulfur",
"charcoal",
"stone",
"wood",
"lowgradefuel",
"gunpowder"
};
}
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"] = "{0} cannot be stored in this locker."
}, this);
}
private string Msg(string key, string userId = null, params object[] args)
{
return string.Format(lang.GetMessage(key, this, userId), args);
}
private void Init()
{
permission.RegisterPermission(PermAllow, this);
}
private object CanLockerAcceptItem(Locker locker, Item item, int targetSlot, BasePlayer player)
{
if (locker == null || item == null || item.info == null) return null;
if (player != null && !player.IsNpc && permission.UserHasPermission(player.UserIDString, PermAllow))
return null;
if (config.AllowedShortnames != null && config.AllowedShortnames.Contains(item.info.shortname))
return null;
if (player != null && player.IsConnected)
player.ChatMessage(Msg("Blocked", player.UserIDString, item.info.displayName.english));
return false;
}
}
}The plugin defines a shortname whitelist in its config and a lockeritemrestrict.allow permission. When a player drags an item into a locker, CanLockerAcceptItem checks the shortname against the list. Players with the permission bypass the filter entirely; everyone else gets a boolean back, so the vanilla floor filter runs only when the item is whitelisted. A blocked move returns false and the item stays where it was, with a chat message telling the player the item is not allowed. The hook guards against a null player and a null item before touching the config.
Common use cases
Block weapons above a grade in public lockers
Return false for items whose shortname is in a configured list, or when a per-player permission is missing, to keep lockers as pure storage on PvE-style servers.
Enforce slot-based storage layouts
Use targetSlot to reserve specific slots for specific categories — for example, keep the first six slots for resources and reject other items there.
Team-scoped storage rules
Check player.currentTeam against the locker owner's team to let team members insert items that non-members cannot.
Pitfalls
Returning a value runs for every item
Whenever your method returns a bool, the vanilla filter is skipped. If you only mean to add a restriction, return the bool only when your check fails and null otherwise.
The player argument can be null
Entity-driven or programmatic moves may not have an interactive player. Always null-check before calling permission or team lookups.
This does not stop stacks from being split
The hook runs per Item instance, so splitting a stack fires once for the new piece. Repeat rules in another path (or a client-side UI) if you need stricter enforcement.
Build a plugin with CanLockerAcceptItem
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 CanLockerAcceptItem
Generate