Skip to content
RustPluginGenerator

OnTurretClearList

OnTurretClearList is called when a player uses the clear-auth action on an AutoTurret, right before the game wipes the turret's authorizedPlayers list.

Signature
object OnTurretClearList(AutoTurret autoTurret, BasePlayer player)

Parameters

Hook parameters
ParameterTypeDescription
autoTurretAutoTurretThe AutoTurret entity whose authorization list is about to be cleared. Use it to read the turret's position, owner, identifier or current authorized player count.
playerBasePlayerThe BasePlayer who triggered the clear, taken from the RPC message. The game has already confirmed it is non-null and passes a CanBuild() check before the hook fires.

Return value

Return null to let the game clear authorizedPlayers and mark auth dirty as usual. Return any non-null object (for example true) to abort the clear entirely — the list stays untouched, no analytics event is written, and the auth capacity is not recalculated.

How it works

AutoTurret.ClearList runs when the owner-side clear authorization RPC is processed. Before the hook fires, the game has already checked that the RPC carries a player, that the turret is not booting and not online, and that the player passes CanBuild() on the turret's building privilege. The hook fires last in that chain, so returning a non-null value cancels the wipe.

Use autoTurret to inspect or record which turret is affected (position, OwnerID, authorizedPlayers, net.ID.Value). Use player to log who issued the clear, to route the action through your own permission check, or to build a custom confirmation flow.

Only null lets the original code run. If you want normal clearing to proceed, return null. If you want to stop it, return any non-null value such as true.

Narrowing by parameter type does not help here because there is a single signature with AutoTurret and BasePlayer. This hook only covers the manual clear action; changes the game makes on its own (decay, kill, owner swap) do not route through it.

Example plugin: Require a chat confirmation before wiping turret auth

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

namespace Oxide.Plugins
{
    [Info("Turret Clear Confirm", "RustPluginGenerator", "1.0.0")]
    [Description("Requires a chat confirmation before a player can wipe an AutoTurret's authorized players.")]
    public class TurretClearConfirm : RustPlugin
    {
        private const string PermUse = "turretclearconfirm.use";

        private class PluginConfig
        {
            [JsonProperty("Confirmation window (seconds)")]
            public float ConfirmWindow = 20f;
        }

        private PluginConfig config;
        private readonly Dictionary<ulong, ulong> pending = new Dictionary<ulong, ulong>();

        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 do not have permission to clear turret authorization.",
                ["Confirm"] = "Clearing turret authorization is paused. Type /tc confirm within {0} seconds.",
                ["NoPending"] = "You have no pending turret clear to confirm.",
                ["Confirmed"] = "Turret authorization cleared.",
                ["Expired"] = "That confirmation has expired or the turret is gone."
            }, 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 OnTurretClearList(AutoTurret autoTurret, BasePlayer player)
        {
            if (autoTurret == null || player == null) return null;
            if (!permission.UserHasPermission(player.UserIDString, PermUse))
            {
                player.ChatMessage(Msg("Denied", player.UserIDString));
                return true;
            }

            pending[player.userID.Get()] = autoTurret.net.ID.Value;
            player.ChatMessage(Msg("Confirm", player.UserIDString, (int)config.ConfirmWindow));

            ulong key = player.userID.Get();
            timer.Once(config.ConfirmWindow, () =>
            {
                ulong stored;
                if (pending.TryGetValue(key, out stored) && stored == autoTurret.net.ID.Value)
                    pending.Remove(key);
            });

            return true;
        }

        [ChatCommand("tc")]
        private void CmdTurretClear(BasePlayer player, string command, string[] args)
        {
            if (player == null) return;
            if (args.Length == 0 || args[0].ToLowerInvariant() != "confirm")
            {
                player.ChatMessage(Msg("NoPending", player.UserIDString));
                return;
            }

            ulong userId = player.userID.Get();
            ulong turretId;
            if (!pending.TryGetValue(userId, out turretId))
            {
                player.ChatMessage(Msg("NoPending", player.UserIDString));
                return;
            }
            pending.Remove(userId);

            AutoTurret turret = null;
            foreach (var entity in BaseNetworkable.serverEntities)
            {
                var candidate = entity as AutoTurret;
                if (candidate == null) continue;
                if (candidate.net.ID.Value == turretId)
                {
                    turret = candidate;
                    break;
                }
            }

            if (turret == null || turret.IsDestroyed)
            {
                player.ChatMessage(Msg("Expired", player.UserIDString));
                return;
            }

            turret.authorizedPlayers.Clear();
            turret.authDirty = true;
            turret.UpdateMaxAuthCapacity();
            turret.SendNetworkUpdate();
            player.ChatMessage(Msg("Confirmed", player.UserIDString));
        }

        private void Unload()
        {
            pending.Clear();
        }
    }
}

TurretClearConfirm intercepts OnTurretClearList so a wipe does not happen immediately. Players without the turretclearconfirm.use permission get a denial message; everyone else has the turret's network id stored keyed by their user id and receives a prompt to type /tc confirm within the configured window. The hook always returns true, so the vanilla clear is blocked either way.

When the player runs /tc confirm, the plugin looks up the stored turret id, finds the live AutoTurret, clears authorizedPlayers, marks auth dirty and calls UpdateMaxAuthCapacity. If the turret is gone or the entry missing, the player is told the confirmation expired or that nothing is pending. A timer removes stale pending entries so the confirmation cannot be reused later. Messages live in the language file and the confirmation window is configurable.

Common use cases

  • Add a two-step confirmation for clearing turret auth

    Block the immediate wipe, store the turret id per player, and require a second command or UI click before the list is actually cleared.

  • Audit who wipes turret authorization

    Record the turret position, owner id, authorizer count and player id to a data file so admins can review suspicious clears after a raid.

  • Gate clearing behind a permission node

    Return a non-null value for players who lack a turretclear.use permission, so only trusted groups can wipe turret auth on your server.

Pitfalls

  • The game already applied CanBuild and turret state checks

    Your hook only runs when the RPC reached ClearList with a non-null player, the turret is off, not booting, and the caller can build there. Returning non-null cannot grant access the game would have denied.

  • Return value type does not matter, only null vs non-null

    Because ClearList returns void, false also blocks the clear. Always return null explicitly when you want default behavior; a stray return true; silently blocks.

  • Pending confirmations must be invalidated

    If you store turret ids between the hook and a later command, expire them. Otherwise a player can confirm against a turret that has been destroyed, replaced or had its owner changed.

Build a plugin with OnTurretClearList

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

Prompt: Add a two-step confirmation for clearing turret auth using the OnTurretClearList 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 OnTurretClearList

Generate