Skip to content
RustPluginGenerator

OnTurretAuthorize

OnTurretAuthorize is called when a player tries to authorize themselves on an AutoTurret through its control panel, before the player's userID is written into the turret's authorized list.

Signature
object OnTurretAuthorize(AutoTurret autoTurret, BasePlayer player)

Parameters

Hook parameters
ParameterTypeDescription
autoTurretAutoTurretThe AutoTurret entity the player is being added to. Always non-null when the hook fires.
playerBasePlayerThe BasePlayer attempting to authorize themselves on the turret via the turret's auth UI. Non-null in practice, but null-check anyway.

Return value

Returning null (or any value of an incompatible type) lets the game continue and adds the player to the turret's authorized list. Returning any non-null value cancels the addition; the player is not authorized and no network update or analytics event is sent.

How it works

The hook fires inside AutoTurret.AddSelfAuthorize, which runs when a player presses the authorize button on a turret's auth screen. The game has already passed several internal gates by the time the hook is reached: the turret must be online, the player must satisfy CanBuild(), and the turret must not be at its max auth capacity. Once those pass, Oxide calls OnTurretAuthorize with the turret and the player, and only adds the player to authorizedPlayers (plus updates auth capacity and sends a network update) if the hook returns null. This is a pre-authorization gate, not a notification: by the time you see it, the request is valid and would otherwise succeed. Use autoTurret.OwnerID or autoTurret.GetBuildingPrivilege() to decide whether the requester should be allowed, and use player.UserIDString for permission checks. Declaring a more specific parameter type (for example a subclass) narrows dispatch, but there is no useful subtype of AutoTurret here, so keep the declared types as given. The hook does not fire for deauthorization or for programmatic list changes that bypass the UI.

Example plugin: Restrict turret authorization to building owners and teammates

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

namespace Oxide.Plugins
{
    [Info("Turret Auth Guard", "RustPluginGenerator", "1.0.0")]
    [Description("Restricts who may authorize themselves on an AutoTurret using building privilege, owner and team checks.")]
    public class TurretAuthGuard : RustPlugin
    {
        private const string PermBypass = "turretauthguard.bypass";

        private PluginConfig config;

        private class PluginConfig
        {
            [JsonProperty("Allow building privilege users")]
            public bool AllowAuthed { get; set; } = true;

            [JsonProperty("Allow teammates of the turret owner")]
            public bool AllowTeammates { get; set; } = 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);

        protected override void LoadDefaultMessages()
        {
            lang.RegisterMessages(new Dictionary<string, string>
            {
                ["Denied"] = "You are not allowed to authorize on this turret."
            }, this);
        }

        private string Msg(string key, string userId = null) => lang.GetMessage(key, this, userId);

        private void Init()
        {
            permission.RegisterPermission(PermBypass, this);
        }

        private object OnTurretAuthorize(AutoTurret autoTurret, BasePlayer player)
        {
            if (autoTurret == null || player == null) return null;
            if (permission.UserHasPermission(player.UserIDString, PermBypass)) return null;

            if (autoTurret.OwnerID == player.userID.Get()) return null;

            if (config.AllowTeammates && autoTurret.OwnerID != 0)
            {
                BasePlayer owner = BasePlayer.FindByID(autoTurret.OwnerID);
                if (owner != null && owner.currentTeam != 0 && player.currentTeam == owner.currentTeam)
                    return null;
            }

            if (config.AllowAuthed)
            {
                BuildingPrivlidge privilege = autoTurret.GetBuildingPrivilege();
                if (privilege != null && privilege.IsAuthed(player))
                    return null;
            }

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

The plugin blocks self-authorization on an AutoTurret unless the requesting player passes a check we control. It reads the turret's owning building privilege with GetBuildingPrivilege() and compares the player against it, while also allowing the turret's OwnerID and, optionally, members of the owner's team when AllowTeammates is enabled in the config. When a player is blocked, the hook returns a non-null value so the game skips adding them to the authorized list, and the plugin sends a chat message from the language file. Allowed players get a null return so vanilla behavior runs unchanged. Config toggles live in oxide/config/TurretAuthGuard.json, and the message text lives in the language file.

Common use cases

  • Block turret griefing

    Deny authorization for players who cannot build in the turret's area, stopping raiders from taking over a turret they did not place.

  • Team-only turrets

    Allow the turret owner and their teammates to authorize, while rejecting everyone else even if they can build.

  • Paid or ranked access

    Gate authorization behind an Oxide permission so only donators or a specific group can operate turrets on your server.

Pitfalls

  • Hook fires after vanilla checks

    The turret must already be online, the player must pass CanBuild(), and the auth list must have room. Your hook cannot override those; it only adds one more gate.

  • Not the deauthorize path

    OnTurretAuthorize never fires when a player is removed. Use OnTurretDeauthorize for removal, and OnTurretClearList for list wipes.

  • Privilege can be null

    GetBuildingPrivilege() returns null for turrets outside a cupboard's range, so null-check it before calling IsAuthed.

Build a plugin with OnTurretAuthorize

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

Prompt: Block turret griefing using the OnTurretAuthorize 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 OnTurretAuthorize

Generate