Skip to content
RustPluginGenerator

OnVendingShopRename

OnVendingShopRename is called when a player with admin rights over a vending machine submits a new shop name, before the name is stored. Returning a non-null value cancels the rename.

Signature
object OnVendingShopRename(VendingMachine vendingMachine, string text, BasePlayer player)

Parameters

Hook parameters
ParameterTypeDescription
vendingMachineVendingMachineThe VendingMachine entity being renamed. Use it to read the current shopName, position, OwnerID or to compare it against other machines.
textstringThe new shop name string the player submitted. It has already been read from the RPC and truncated to 32 characters by the game before the hook fires.
playerBasePlayerThe BasePlayer performing the rename. This is the player passed in the RPC message, and the game only reaches this point when that player passes its admin check.

Return value

Return null (or fall through) to accept the rename; the game then stores text as the shop name and records the player as the last editor. Return any non-null object to block the change — the method exits before shopName is modified, so the machine keeps its previous name.

How it works

The hook fires inside VendingMachine.RPC_UpdateShopName, the RPC a client sends when it edits the shop name in the vending machine admin panel. The game first reads the new name string from the message (capped at 32 characters) and confirms the caller can administer the machine; only then does it call OnVendingShopRename. This means the hook never fires for players who lack admin rights, so you do not need to repeat that check unless your policy is stricter.

If your hook returns null, the game writes the submitted text into shopName, records the editing player in nameLastEditedBy, and continues its normal update. If your hook returns anything non-null, the method returns early and the name is left untouched.

The text parameter is the raw name the client sent — inspect it for profanity, links, or length before allowing it through. The player parameter is useful for permission checks or logging. Declaring vendingMachine as VendingMachine is required; narrowing player to a subclass would only filter calls, which is pointless here since it is always a BasePlayer. Note the hook is rename-only: it does not fire for price or offer edits.

Example plugin: Enforce a shop name format and block banned words

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

namespace Oxide.Plugins
{
    [Info("Vending Name Guard", "RustPluginGenerator", "1.0.0")]
    [Description("Validates and filters vending machine shop names when players rename them.")]
    public class VendingNameGuard : RustPlugin
    {
        private const string PermBypass = "vendingnameguard.bypass";

        private PluginConfig config;

        private class PluginConfig
        {
            [JsonProperty("Maximum name length")]
            public int MaxLength = 24;

            [JsonProperty("Blocked words (case-insensitive)")]
            public List<string> BlockedWords = new List<string> { "scam", "free", "hack" };

            [JsonProperty("Allowed characters (regex pattern)")]
            public string AllowedPattern = @"^[A-Za-z0-9 _\-.,!]+$";
        }

        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>
            {
                ["TooLong"] = "That shop name is too long. Maximum length is {0} characters.",
                ["BadChars"] = "That shop name contains characters that are not allowed.",
                ["BadWord"] = "That shop name contains a blocked word.",
                ["Accepted"] = "Shop name updated to: {0}"
            }, 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 OnVendingShopRename(VendingMachine vendingMachine, string text, BasePlayer player)
        {
            if (vendingMachine == null || player == null) return null;
            if (!player.IsConnected || player.IsNpc) return null;
            if (permission.UserHasPermission(player.UserIDString, PermBypass)) return null;

            if (text == null)
            {
                player.ChatMessage(Msg("BadChars", player.UserIDString));
                return true;
            }

            if (text.Length > config.MaxLength)
            {
                player.ChatMessage(Msg("TooLong", player.UserIDString, config.MaxLength));
                return true;
            }

            string lowered = text.ToLowerInvariant();
            foreach (string word in config.BlockedWords)
            {
                if (!string.IsNullOrEmpty(word) && lowered.Contains(word.ToLowerInvariant()))
                {
                    player.ChatMessage(Msg("BadWord", player.UserIDString));
                    PrintWarning($"Blocked shop name '{text}' from {player.displayName} ({player.UserIDString})");
                    return true;
                }
            }

            if (!string.IsNullOrEmpty(config.AllowedPattern) && !System.Text.RegularExpressions.Regex.IsMatch(text, config.AllowedPattern))
            {
                player.ChatMessage(Msg("BadChars", player.UserIDString));
                return true;
            }

            player.ChatMessage(Msg("Accepted", player.UserIDString, text));
            return null;
        }
    }
}

The plugin intercepts every vending machine rename and validates the submitted text before it is stored. LoadDefaultMessages registers the feedback strings, and the config holds the banned word list plus the maximum allowed length and the permitted character pattern. When OnVendingShopRename fires, the plugin first checks the player is still connected and not an NPC, then rejects names containing banned words (case-insensitive) or characters outside the allow-list, notifying the player with a chat message and returning a non-null object to cancel. Names that pass are allowed through by returning null, so the game writes them normally. Admins with a configured bypass permission skip validation.

Common use cases

  • Profanity and link filtering

    Scan the submitted text for banned words or URLs and return a non-null value to reject the rename while messaging the player about the offending term.

  • Server naming conventions

    Force a prefix or enforce a character set so every shop name on the map matches a consistent style, blocking anything that does not fit.

  • Rename audit trail

    Log the old shopName, the new text, player Steam ID and machine position to a data file or admin log for later review before accepting the change.

Pitfalls

  • The hook only sees admin-authorized players

    The game checks CanPlayerAdmin before calling the hook, so you cannot use it to detect attempts by unauthorized players. It is not a security gate for the admin panel itself.

  • Returning false still cancels

    The patcher treats any non-null value as a block, including a boxed false. If you want to accept a rename you must return null, not a boolean result of your own check.

  • Text is already truncated

    The name is read with a 32-character limit before the hook runs, so very long input is silently shortened upstream. Validate against that limit rather than expecting the full string.

Build a plugin with OnVendingShopRename

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

Prompt: Profanity and link filtering using the OnVendingShopRename 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 OnVendingShopRename

Generate