Skip to content
RustPluginGenerator

CanUseVending

CanUseVending is called when a player tries to open a vending machine's loot panel. Returning a bool overrides the game's own access check.

Signature
object CanUseVending(BasePlayer player, VendingMachine vendingMachine)

Parameters

Hook parameters
ParameterTypeDescription
playerBasePlayerThe BasePlayer who is trying to open the vending machine's loot panel. Check permissions, team, distance or state on this object.
vendingMachineVendingMachineThe VendingMachine entity the player interacted with. Use its position, OwnerID, shop state or flags to decide whether access should be allowed.

Return value

Return true to force the loot panel open, or false to block it. Any other return value (including null) is ignored and the game's normal CanOpenLootPanel logic runs, deciding based on ownership, admin status and panel name.

How it works

The hook fires inside VendingMachine.CanOpenLootPanel, which the game calls whenever a player interacts with a vending machine to open its UI. Because the method is also the gate for the customer shop panel and the admin admin panel, the hook runs before the game decides which panel the player gets. Use player for permission checks, distance, team membership or combat state, and vendingMachine for ownership (OwnerID), position, or a flag set elsewhere in your plugin.

Returning a bool replaces the game's result entirely: true lets the player open the panel, false blocks it, regardless of normal rules such as admin status or ownership. Returning null (or any non-bool) lets the original logic continue, so the machine behaves normally.

Narrowing parameters is not useful here since both arguments are already specific types. Note that the hook fires for both the customer and admin panel attempts, so if you only want to gate customer shopping you must check whether the player owns the machine.

Example plugin: Restrict vending machines to a whitelisted zone

VendingZoneGuard.cs
using System;
using Newtonsoft.Json;
using UnityEngine;
using Oxide.Core;

namespace Oxide.Plugins
{
    [Info("Vending Zone Guard", "RustPluginGenerator", "1.0.0")]
    [Description("Blocks vending machine interaction outside a configured radius.")]
    public class VendingZoneGuard : RustPlugin
    {
        private PluginConfig config;

        private class PluginConfig
        {
            [JsonProperty("Anchor X")]
            public float AnchorX = 0f;

            [JsonProperty("Anchor Y")]
            public float AnchorY = 0f;

            [JsonProperty("Anchor Z")]
            public float AnchorZ = 0f;

            [JsonProperty("Allowed radius")]
            public float Radius = 50f;

            [JsonProperty("Allow owners outside radius")]
            public bool AllowOwners = 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);

        private object CanUseVending(BasePlayer player, VendingMachine vendingMachine)
        {
            if (player == null || vendingMachine == null || vendingMachine.IsDestroyed) return null;
            if (player.IsAdmin) return null;

            var anchor = new Vector3(config.AnchorX, config.AnchorY, config.AnchorZ);
            if (Vector3.Distance(anchor, vendingMachine.transform.position) <= config.Radius) return null;

            if (config.AllowOwners && vendingMachine.OwnerID == player.userID.Get()) return null;

            player.ChatMessage("This vending machine is outside the trading zone.");
            return false;
        }
    }
}

The plugin stores a configurable radius around a single point in config. Every time a player interacts with a vending machine, CanUseVending measures the distance from that anchor to the machine. If the machine sits outside the radius, the hook returns false and the loot panel never opens for that player. Machines inside the radius behave normally because the hook returns null. The example also shows how to distinguish owner access from customer access via OwnerID, which you can extend into per-team or per-permission rules.

Common use cases

  • Premium shops

    Gate interaction behind a permission so only players with a VIP group can browse vending machines in a designated area.

  • Combat restrictions

    Return false when the player has been damaged recently, preventing out-of-combat UI abuse during fights.

  • Owner-only kiosks

    Block the admin panel access for non-owners by comparing player.userID with vendingMachine.OwnerID.

Pitfalls

  • Admins bypass is removed

    Returning false blocks access for everyone including admins, because the hook result is returned before the method checks IsAdmin.

  • Fires for both panels

    CanOpenLootPanel is called for the customer panel and the admin panel, so a broad permission block can lock owners out of restocking their own machine.

  • No message sent by the game

    When you block access nothing tells the player why. Send a chat message inside the hook so the interaction does not silently fail.

Build a plugin with CanUseVending

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

Prompt: Premium shops using the CanUseVending 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 CanUseVending

Generate