OnCupboardAssign
OnCupboardAssign is called when one player authorizes another player on a tool cupboard, right before the authorization is written. Returning a non-null value stops the authorization.
object OnCupboardAssign(BuildingPrivlidge privlidge, ulong userID, BasePlayer player)Parameters
| Parameter | Type | Description |
|---|---|---|
privlidge | BuildingPrivlidge | The BuildingPrivlidge (tool cupboard) the authorization is being added to. Use it to read OwnerID, the authorized list or its position. |
userID | ulong | Steam ID of the player being authorized. Differs from player.userID whenever one player authorizes another. |
player | BasePlayer | The BasePlayer who performed the authorization action (the one standing at the cupboard and pressing use), not necessarily the player being authorized. |
Return value
Returning null (or doing nothing) lets the authorization proceed. Returning any non-null value makes the patched method return true early, which tells the game the authorization succeeded while skipping the write to the cupboard's authorized list, so the target player is not added.
How it works
Oxide calls this hook from RustCore.IOnCupboardAuthorize, which runs when a player adds someone else to a cupboard's authorized list (typically by holding a building plan and pressing use on the cupboard while another player stands nearby, or through the authorization UI). It never fires for self-authorization: when userID == player.userID the game calls OnCupboardAuthorize instead, so both hooks together cover every authorization.
privlidge is the BuildingPrivlidge being modified, useful for checking OwnerID, team membership or position. userID is the account being authorized, while player is the one performing the action. This distinction matters for rules like "owners may only authorize their own team" or "only admins may authorize other players": compare player against the cupboard owner and inspect userID separately.
Declaring a more specific parameter type does not narrow anything here, because both players in this path are humans at a cupboard; checking player.IsNpc in the body is enough. Team checks use player.currentTeam and RelationshipManager.ServerInstance.FindTeam.
Example plugin: Restrict cupboard authorization to team members
using System.Linq;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
namespace Oxide.Plugins
{
[Info("Cupboard Team Auth", "RustPluginGenerator", "1.0.0")]
[Description("Restricts tool cupboard authorizations to players on the same team as the authorizer.")]
public class CupboardTeamAuth : RustPlugin
{
private class PluginConfig
{
[JsonProperty("Only allow team members")]
public bool TeamOnly { get; set; } = true;
[JsonProperty("Block NPC authorizers")]
public bool BlockNpcs { get; set; } = true;
}
private PluginConfig config;
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>
{
["NotTeam"] = "You can only authorize players on your own team.",
["NpcBlocked"] = "You cannot authorize a player from this source."
}, 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.TeamOnly)
Puts("Team-only cupboard authorization is enabled.");
}
private object OnCupboardAssign(BuildingPrivlidge privlidge, ulong userID, BasePlayer player)
{
if (privlidge == null || player == null) return null;
if (config.BlockNpcs && player.IsNpc)
{
return true;
}
if (!config.TeamOnly) return null;
ulong teamId = player.currentTeam;
if (teamId == 0)
{
SendReply(player, Msg("NotTeam", player.UserIDString));
return true;
}
if (userID == player.userID)
{
// Self-authorization goes through OnCupboardAuthorize, not this hook.
return null;
}
var team = RelationshipManager.ServerInstance.FindTeam(teamId);
if (team == null || !team.members.Contains(userID))
{
SendReply(player, Msg("NotTeam", player.UserIDString));
return true;
}
return null;
}
}
}The plugin lets server owners decide who may authorize whom on a tool cupboard. In OnCupboardAssign it loads the config flags: authorization can be limited to players sharing the authorizer's team, and NPC authorizers can be rejected outright. When the authorizer has no team (currentTeam == 0) or the target is not in that team, the hook returns true, which stops the game from adding the target to the authorized list. The action's performer receives a localized chat message explaining the refusal, and a short warning is written with Puts at startup instead of inside the hook. Because self-authorization goes through OnCupboardAuthorize, that path is untouched.
Common use cases
Team-only authorizations
Block cubboards from being shared with players outside the authorizer's team, keeping base access tied to the team roster.
Anti-grief whitelist
Refuse authorizations on cupboards whose ownerID belongs to a restricted list, or when the target player is on a server ban list for building access.
Cupboard count limits
Track how many players each cupboard has authorized and stop new additions once a per-cupboard cap is reached.
Pitfalls
Returning false still blocks
The check is for a non-null return, so returning
falsealso cancels the authorization. Returnnullto allow it.Self-authorization is a different hook
When a player authorizes themselves the game calls OnCupboardAuthorize, not OnCupboardAssign. Enforcement rules need both hooks to be complete.
player is not always userID
The authorizer and the authorized player are different when one player adds another. Rules that compare
player.userIDtouserIDmust account for this.
Build a plugin with OnCupboardAssign
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 OnCupboardAssign
Generate