Skip to content
RustPluginGenerator

CanWearItem

CanWearItem is called when the game decides whether an item may be placed into a player's wear container (clothing and armor slots). Returning false blocks the move; any other return keeps the game's normal check.

Signature
object CanWearItem(PlayerInventory playerInventory, Item item, int targetSlot, BasePlayer player)

Parameters

Hook parameters
ParameterTypeDescription
playerInventoryPlayerInventoryThe PlayerInventory instance the item is being worn from. Use it to reach the owning player's containers or to compare against a specific inventory.
itemItemThe Item being moved into a wear slot. Check its info.shortname, skin or condition to decide whether to allow it.
targetSlotintThe wear slot index the game wants to place the item in (0-7 for the wear container). Use it to allow only certain slots.
playerBasePlayerThe BasePlayer wearing the item. Null-check it and use UserIDString or permission checks here.

Return value

Return a bool to override the result: false blocks the wear, true forces it to be treated as wearable in that slot. Return null (or any non-bool value) to let Rust's own CanWearItem logic decide.

How it works

The hook fires inside PlayerInventory.CanWearItem(BasePlayer, Item, int), the private method Rust uses to validate wearing before a move into containerWear completes. It runs whenever the game evaluates the wear rules for an item: dragging gear into a clothing/armor slot, auto-equipping on pickup where the game attempts it, and any other code path that calls the same check. The four arguments give you the inventory, the exact Item, the target slot index and the player involved, so you can key decisions on shortname, skin, slot or permission.

Because Oxide only dispatches parameters whose types match, you can leave item and playerInventory as declared and still null-check both; skipping the hook entirely for unrelated inventories is not possible since the argument types are fixed here. Declaring a more specific type for item is not useful because it is declared as the base Item. Keep the method cheap: it can run every time a player clicks gear into a slot. Never call Puts or PrintWarning from inside it.

Example plugin: Restrict specific gear to a permission group

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

namespace Oxide.Plugins
{
    [Info("Wear Permission Gate", "RustPluginGenerator", "1.0.0")]
    [Description("Blocks wearing of configured items unless the player has the matching permission.")]
    public class WearPermissionGate : RustPlugin
    {
        private const string PermPrefix = "wearpermissiongate.";

        private PluginConfig config;

        private class PluginConfig
        {
            [JsonProperty("Restricted items (shortname -> permission suffix)")]
            public Dictionary<string, string> RestrictedItems = new Dictionary<string, string>
            {
                ["metal.facemask"] = "facemask",
                ["coffeecan.helmet"] = "helmet"
            };
        }

        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>
            {
                ["NoWearPermission"] = "You do not have permission to wear {0}."
            }, this);
        }

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

        private void Init()
        {
            if (config.RestrictedItems == null) return;

            foreach (var entry in config.RestrictedItems)
            {
                if (string.IsNullOrEmpty(entry.Value)) continue;
                permission.RegisterPermission(PermPrefix + entry.Value, this);
            }
        }

        private object CanWearItem(PlayerInventory playerInventory, Item item, int targetSlot, BasePlayer player)
        {
            if (item == null || item.info == null || player == null) return null;
            if (config.RestrictedItems == null) return null;

            string suffix;
            if (!config.RestrictedItems.TryGetValue(item.info.shortname, out suffix)) return null;
            if (string.IsNullOrEmpty(suffix)) return null;

            if (permission.UserHasPermission(player.UserIDString, PermPrefix + suffix)) return null;

            player.ChatMessage(Msg("NoWearPermission", player.UserIDString, item.info.displayName.english));
            return false;
        }
    }
}

The plugin holds a config map of item shortnames to permission nodes. On CanWearItem it looks up the item's shortname; if the item is listed and the player lacks the matching permission, it returns false to block the move and sends a language message to the player. Items not in the map, and players without the restriction, fall through to Rust's default check by returning null. The config and messages reload cleanly and the permission node is registered in Init.

Common use cases

  • Lock premium clothing behind permissions

    Block wearing of special skins unless the player has a permission node, allowing servers to sell cosmetic or armor access without touching the base items.

  • Enforce slot rules for event sets

    Allow a specific uniform item only in the chest slot by comparing targetSlot against the expected index.

  • Prevent condition-damaged gear from being equipped

    Check item.condition before wear and reject near-broken armor so players must repair it first.

Pitfalls

  • Returning true force-equips gear

    Returning true tells Rust the item is wearable even if its own rules would reject it. Only return true when you deliberately want to bypass slot validation.

  • player can be null in edge cases

    The argument comes straight from the calling inventory. Always null-check player and item before calling UserHasPermission or reading info.

  • Fires frequently during inventory swaps

    The check runs on gear drags and related moves. Keep the body allocation-free and skip logging so it does not spam the server console.

Build a plugin with CanWearItem

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

Prompt: Lock premium clothing behind permissions using the CanWearItem 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 CanWearItem

Generate