OnRackedWeaponTake
OnRackedWeaponTake is called when a player takes a weapon out of a WeaponRack, before the rack clears the slot and gives the item to the player. Returning a non-null value cancels the take and leaves the weapon on the rack.
object OnRackedWeaponTake(Item slot, BasePlayer player, WeaponRack weaponRack)Parameters
| Parameter | Type | Description |
|---|---|---|
slot | Item | The Item currently occupying the weapon rack slot that is about to be handed to the player. Its info (shortname, skin, condition) identifies the weapon. |
player | BasePlayer | The BasePlayer receiving the weapon from the rack. Use it for permission checks, notifications or to give whatever the rack returns instead. |
weaponRack | WeaponRack | The WeaponRack entity the player is interacting with. Useful for position-based logic, ownership checks and to inspect the rack's inventory or stored weapons. |
Return value
Returning null lets the original code run: the rack clears the slot and gives the weapon to the player. Returning any non-null value aborts GivePlayerWeapon before ClearSlot is called, so the weapon stays on the rack and the player receives nothing.
How it works
The hook fires inside WeaponRack.GivePlayerWeapon, right after the rack resolves the item in the requested slot. At that point the game has validated the slot index, fetched base.inventory.GetSlot(...) and is about to call ClearSlot and move the item to the player. The slot parameter is the live Item still parented to the rack inventory, player is the taking player, and weaponRack is the entity, so you can read its position, owner and full contents. This is the only injection point for the hook, so it covers every weapon removal that goes through the normal rack interaction path. Because Oxide dispatches by parameter type, declaring player as BasePlayer is the natural choice here; there is no narrower subtype to rely on. Return a non-null object (any value works) to stop the take and keep the weapon racked. Return null to let the vanilla flow proceed. Do not call ClearSlot or move items yourself while returning null, since the game will do it immediately after.
Example plugin: Block players without a permission from taking racked weapons
using System.Linq;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
namespace Oxide.Plugins
{
[Info("Racked Weapon Permission", "RustPluginGenerator", "1.0.0")]
[Description("Requires a permission (or rack ownership) before a player can take a weapon off a weapon rack.")]
public class RackedWeaponPermission : RustPlugin
{
private const string PermTake = "rackedweaponpermission.take";
private PluginConfig config;
private class PluginConfig
{
[JsonProperty("Require permission for everyone")]
public bool RequirePermission { get; set; } = true;
[JsonProperty("Rack owner can always take")]
public bool OwnerBypass { get; set; } = true;
[JsonProperty("Blocked shortnames")]
public List<string> BlockedShortnames { get; set; } = new List<string>();
}
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>
{
["NoPermission"] = "You are not allowed to take weapons from this rack.",
["Blocked"] = "That weapon cannot be removed from the rack."
}, 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(PermTake, this);
}
private object OnRackedWeaponTake(Item slot, BasePlayer player, WeaponRack weaponRack)
{
if (slot == null || slot.info == null || player == null || weaponRack == null)
return null;
if (config.BlockedShortnames != null && config.BlockedShortnames.Contains(slot.info.shortname))
{
player.ChatMessage(Msg("Blocked", player.UserIDString));
return true;
}
if (!config.RequirePermission)
return null;
if (config.OwnerBypass && weaponRack.OwnerID == player.userID.Get())
return null;
if (permission.UserHasPermission(player.UserIDString, PermTake))
return null;
player.ChatMessage(Msg("NoPermission", player.UserIDString));
return true;
}
}
}The plugin registers a single permission and denies the take when the player lacks it. OnRackedWeaponTake checks the perk first, then inspects slot.info.condition style data by shortname against a configurable blacklist, and finally cancels with a non-null return and a localized chat message so the player knows why. The config holds the permission-free shortname list and a toggle for messaging, loaded through the standard Oxide config pattern. LoadDefaultMessages registers the denial text and OnRackedWeaponTake sends it via the language helper. No timers or saved data are needed; Unload is omitted because there is nothing to clean up beyond the base implementation.
Common use cases
Rack access control
Only allow players with a permission (or the rack owner) to pull weapons off a weapon rack, keeping public racks readable but not lootable.
Raid protection for racks
Cancel the take while the rack sits inside a building the player is not authorized on, so raiders cannot freely strip racks they cannot access.
Weapon swap gating
Block taking a weapon if the player already holds a weapon in that category, forcing an unequip first and preventing instant hot-swap abuse.
Pitfalls
Non-null means cancel
Unlike many Oxide hooks, any non-null return aborts the take. Do not return a boolean or a message string as a side effect; return null explicitly on the allow path.
Do not move the item yourself
If you return null, the game clears the slot and gives the weapon on its own. Manually calling MoveToContainer before returning null leaves the rack slot cleared but the item in an unexpected state.
slot may be gone later
The Item reference is only meaningful during the call. Any deferred logic (timers, callbacks) should re-fetch the weapon through weaponRack.inventory rather than caching the Item.
Build a plugin with OnRackedWeaponTake
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 OnRackedWeaponTake
Generate