Skip to content
RustPluginGenerator

OnTurretIdentifierSet

OnTurretIdentifierSet is called when an auto turret is about to have its computer station identifier changed, right before the new ID is written. Returning a non-null value cancels the change.

Signature
object OnTurretIdentifierSet(AutoTurret autoTurret, BasePlayer player, string newID)

Parameters

Hook parameters
ParameterTypeDescription
autoTurretAutoTurretThe AutoTurret whose identifier is being changed. Use it to read the current identifier, owner, or position for range and ownership checks.
playerBasePlayerThe BasePlayer attempting the rename. This is the player passed to AutoTurret.SetID, normally the one interacting with the computer station. It can be null for internal or bypassed calls, so always null-check it.
newIDstringThe identifier string the turret would receive. It has already passed ComputerStation.IsValidIdentifier before the hook fires, so it is non-empty and syntactically valid.

Return value

Return null to allow the identifier change and let the game write the new ID. Return any non-null object to stop the original code path, which leaves the turret's identifier unchanged and skips the success log.

How it works

The hook fires inside AutoTurret.SetID, after every guard has been evaluated: the caller can change the ID (or bypassed the check), the old ID matches the turret's current identifier, and both old and new IDs are valid computer station identifiers. If your hook returns null, the method continues, logs the success and calls UpdateIdentifier(newID), so the turret becomes linked to that ID.

Use autoTurret to inspect the target turret (owner, position, current GetIdentifier()), player to identify who is renaming it, and newID to validate or rewrite policy around identifier naming. player may be null when the game calls SetID without a real player, so guard before reading UserIDString.

Oxide picks your hook method by parameter type, so declaring BaseEntity or BasePlayer covers more cases; keep AutoTurret when you only care about turrets. The hook fires on every rename attempt that reaches this point, including automated ones, so avoid chat spam or heavy work here — store a flag and act on it elsewhere.

Example plugin: Reject turret renames from unauthorized players

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

namespace Oxide.Plugins
{
    [Info("Turret Identifier Guard", "RustPluginGenerator", "1.0.0")]
    [Description("Restricts who can change auto turret identifiers and blocks reserved names")]
    public class TurretIdentifierGuard : RustPlugin
    {
        private const string PermUse = "turretidentifierguard.use";

        private PluginConfig config;

        private class PluginConfig
        {
            [JsonProperty("Require permission to rename turrets")]
            public bool RequirePermission = true;

            [JsonProperty("Blocked identifiers")]
            public List<string> BlockedIdentifiers = new List<string>();
        }

        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 are not allowed to rename this turret.",
                ["BlockedName"] = "The identifier '{0}' is reserved on this server."
            }, 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 OnTurretIdentifierSet(AutoTurret autoTurret, BasePlayer player, string newID)
        {
            if (autoTurret == null || string.IsNullOrEmpty(newID))
                return null;

            if (config.BlockedIdentifiers != null && config.BlockedIdentifiers.Contains(newID))
            {
                if (player != null && player.IsConnected)
                    player.ChatMessage(Msg("BlockedName", player.UserIDString, newID));
                return false;
            }

            if (!config.RequirePermission)
                return null;

            if (player == null || !player.IsConnected)
                return false;

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

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

The plugin checks the player argument and the permission turretidentifierguard.use before allowing a rename. If the caller is missing, lacks the permission, or the new ID is on a blocked list from the config, it sends a chat message through the language file and returns false, which cancels SetID. Otherwise it returns null and the game writes the identifier. A config field RequirePermission lets admins disable the check entirely, and BlockedIdentifiers holds exact strings that are always refused.

Common use cases

  • Restrict turret naming to a permission

    Only players with a registered permission may change a turret identifier, keeping the feature for VIPs or staff on large servers.

  • Block reserved identifier strings

    Reject IDs that collide with names your server uses for other systems, such as shared storage or event turrets, so they cannot be hijacked.

  • Audit renames to a data file

    Record the turret owner, the caller and the requested ID in an oxide/data file when a change is accepted, for later admin review.

Pitfalls

  • player can be null

    The game can call AutoTurret.SetID without a real player for internal changes. Always null-check the parameter before reading it, or you will throw inside the hook.

  • The new ID is already validated

    ComputerStation.IsValidIdentifier(newID) has passed before the hook fires, so validating format again is redundant. Use the hook for permission and policy checks instead.

  • Returning true still cancels the change

    Any non-null return, including true, stops the original code path. Return null to allow the write and any non-null value to deny it.

Build a plugin with OnTurretIdentifierSet

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

Prompt: Restrict turret naming to a permission using the OnTurretIdentifierSet 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 OnTurretIdentifierSet

Generate