Skip to content
RustPluginGenerator

OnRackedWeaponMount

OnRackedWeaponMount is called when a player places a weapon into a wall-mounted Weapon Rack, before the mount is applied. Returning a non-null value cancels the mount.

Signature
object OnRackedWeaponMount(Item item, BasePlayer player, WeaponRack weaponRack)

Parameters

Hook parameters
ParameterTypeDescription
itemItemThe weapon item being placed on the rack. It is the actual Item instance, so you can inspect its shortname, skin, condition, and the player owner before the mount completes.
playerBasePlayerThe player who triggered the mount. Never null at this point because the game returns false before calling the hook if the player is missing, but still guard against unexpected states.
weaponRackWeaponRackThe WeaponRack entity the weapon is being mounted on. Use it to read the rack's position, owner, building privilege, or which slots are already occupied.

Return value

Return null to let the mount proceed normally. Returning any non-null value stops MountWeapon before the weapon is placed on the rack; the method then reports failure to the caller. Returning a non-bool value also causes the mount to fail rather than succeed, so always return a real bool or null.

How it works

The hook fires inside WeaponRack.MountWeapon, after the game has confirmed a valid player but before the weapon is actually stored on the rack. Any action that attempts a rack mount goes through this path: dragging a weapon from the inventory onto the rack's loot panel, and the server-side mount calls that back such interactions. Because it runs per mount attempt, it is a low-frequency hook compared to damage or input callbacks.

Use item to inspect the weapon (shortname, skin, condition, owning player via GetOwnerPlayer()), player to check permissions, team, building authorization, or admin status, and weaponRack to read the rack entity, its OwnerID, position, and surrounding building privilege. To narrow by weapon type, declare a more specific parameter type only if you are certain the rack will always receive that type - a BaseProjectile parameter would skip melee weapons, for example. A common pattern is to allow only whitelisted shortnames, block skins, or restrict mounts to the rack owner or authorized players.

Example plugin: Restrict weapon racks to allowed weapon types

RackWeaponGuard.cs
using System.Linq;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;

namespace Oxide.Plugins
{
    [Info("Rack Weapon Guard", "RustPluginGenerator", "1.0.0")]
    [Description("Restricts which weapon shortnames can be placed on weapon racks.")]
    public class RackWeaponGuard : RustPlugin
    {
        private const string PermBypass = "rackweaponguard.bypass";

        private PluginConfig config;

        private class PluginConfig
        {
            [JsonProperty("Allowed weapon shortnames")]
            public List<string> AllowedShortnames = new List<string>
            {
                "rifle.ak",
                "rifle.bolt",
                "rifle.l96",
                "smg.thompson",
                "shotgun.pump",
                "lmg.m249"
            };

            [JsonProperty("Bypass permission skips restriction")]
            public bool UseBypassPermission = 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>
            {
                ["NotAllowed"] = "You cannot mount that weapon on a rack. Allowed: {0}",
                ["NoPermission"] = "You do not have permission to mount weapons on this 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(PermBypass, this);
        }

        private object OnRackedWeaponMount(Item item, BasePlayer player, WeaponRack weaponRack)
        {
            if (item?.info == null || player == null || weaponRack == null) return null;

            if (config.UseBypassPermission && permission.UserHasPermission(player.UserIDString, PermBypass))
                return null;

            if (config.AllowedShortnames != null && config.AllowedShortnames.Contains(item.info.shortname))
                return null;

            string allowed = config.AllowedShortnames == null ? "none" : string.Join(", ", config.AllowedShortnames);
            player.ChatMessage(Msg("NotAllowed", player.UserIDString, allowed));
            return false;
        }
    }
}

The plugin adds a configurable whitelist of shortnames that may be placed on a weapon rack, plus an optional permission check so admins can bypass the list. OnRackedWeaponMount inspects the incoming item.info.shortname; if it is not in the allowed set and the player lacks the bypass permission, it sends a localized chat message and returns false, which cancels the mount. Everything else returns null so the default MountWeapon path continues. Config is loaded and validated with a fallback to defaults, and player-facing text goes through the language system so it can be translated per player.

Common use cases

  • Whitelist weapons per rack

    Only permit sniper rifles and assault rifles to be mounted, blocking things like tools or low-tier weapons from being stored on decorative racks.

  • Rack ownership enforcement

    Block mounting if the player is not the rack owner and not building-authorized, preventing raiders from filling a rack with their own weapons.

  • Skin-based restrictions

    Inspect item.skin to disallow specific cosmetic skins or require a premium skin before a weapon can be displayed.

Pitfalls

  • Returning true does not allow

    Any non-null value cancels the mount, including true. Return null for the default behavior and false when you want to block.

  • Specific parameter types narrow dispatch

    Declaring item as a more specific type, or narrowing the hook parameter types, makes Oxide skip calls where the argument does not match. If you only want to police firearms, filter inside the hook instead of changing the parameter type.

  • Not the same as OnRackedWeaponMounted

    This hook runs before the mount; use OnRackedWeaponMounted if you need to react after the weapon is actually stored, for example to fire effects or grant rewards.

Build a plugin with OnRackedWeaponMount

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

Prompt: Whitelist weapons per rack using the OnRackedWeaponMount 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 OnRackedWeaponMount

Generate