Skip to content
RustPluginGenerator

CanAdministerVending

CanAdministerVending is called when the game checks whether a player may open a vending machine's admin (stock/price editing) screen, before the normal owner and building-privilege checks run.

Signature
object CanAdministerVending(BasePlayer player, VendingMachine vendingMachine)

Parameters

Hook parameters
ParameterTypeDescription
playerBasePlayerThe player attempting to open the vending machine's admin/stock-editing interface. Can be null in edge cases, so null-check it.
vendingMachineVendingMachineThe VendingMachine being administered. For the NPC variant, the same hook fires with an NPCVendingMachine argument, so check the concrete type if your behavior differs.

Return value

Return true to force admin access and skip the vanilla owner/privilege check, or false to deny it. Return null (any non-bool) to let the game's own ownership and building-privilege logic decide.

How it works

The hook fires inside VendingMachine.CanPlayerAdmin, which the game runs when a player tries to open the admin/stock-editing UI of a vending machine, and inside NPCVendingMachine.CanPlayerAdmin for the NPC machine variant. player is who is requesting access; vendingMachine is the machine being opened. The same hook name is called from both sites, so the argument may be a VendingMachine or an NPCVendingMachine. Declaring a more specific second parameter type is not enough here because the game passes the concrete instance; the cleanest approach is to accept VendingMachine on the main signature and handle the NPC case separately as an overload, or simply inspect the object. Note the NPC machine's vanilla method always returns false, so NPC stock editing is normally locked out — returning true from the hook is the only reliable way to open it. The default owner/privilege path runs only if your hook returns a non-bool value (typically null).

Other signatures

Oxide also calls CanAdministerVending from other places in the game with these parameter types. Declare the overload you need, or several:

  • object CanAdministerVending(BasePlayer player, NPCVendingMachine nPCVendingMachine)

Example plugin: Restrict vending admin access to a permission group

VendingAdminPermission.cs
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("Vending Admin Permission", "RustPluginGenerator", "1.0.0")]
    [Description("Restricts vending machine admin access to players with a permission.")]
    public class VendingAdminPermission : RustPlugin
    {
        private const string PermUse = "vendingadminpermission.use";

        private PluginConfig config;

        private class PluginConfig
        {
            [JsonProperty("Allow NPC vending machine editing")]
            public bool AllowNpcEditing { get; set; } = false;
        }

        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 do not have permission to edit this vending machine."
            }, 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(PermUse, this);
        }

        private object CanAdministerVending(BasePlayer player, VendingMachine vendingMachine)
        {
            if (player == null || vendingMachine == null) return null;

            if (vendingMachine is NPCVendingMachine)
            {
                if (!config.AllowNpcEditing) return null;
            }

            if (permission.UserHasPermission(player.UserIDString, PermUse))
                return null;

            player.ChatMessage(Msg("NoPermission", player.UserIDString));
            return false;
        }
    }
}

The plugin registers a permission and, in CanAdministerVending, checks whether the requesting player holds it. If they do, the hook returns null and the normal owner and privilege rules still apply, so a member without ownership cannot edit a machine they do not own. If they lack the permission, the hook returns false and access is denied even when they are the owner. The NPC variant is handled by the same method because the second parameter is declared as VendingMachine, but the check is written to work for both. Permission checks run on the player's user ID string and are cheap enough for this call site.

Common use cases

  • Gate admin access behind a permission

    Only members of a staff or moderator permission may edit any vending machine's stock, regardless of ownership.

  • Allow NPC machine editing

    NPC vending machines normally refuse admin access; return true for trusted players to let them configure NPC shops.

  • Lock machines during an event

    Return false for everyone while a server event is active, then stop overriding once it ends.

Pitfalls

  • Both parameter types reach one hook

    The game calls the same hook name for VendingMachine and NPCVendingMachine. If you only handle one type you may block or allow the other by accident.

  • Returning true ignores ownership

    A true return bypasses the vanilla owner and building-privilege check entirely. Only return true when you have validated the player yourself.

Build a plugin with CanAdministerVending

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

Prompt: Gate admin access behind a permission using the CanAdministerVending 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 CanAdministerVending

Generate