OnTurretDeauthorize
OnTurretDeauthorize is called when a player removes their own authorization from an AutoTurret using the turret's control panel, before the entry is deleted from the authorized list.
object OnTurretDeauthorize(AutoTurret autoTurret, BasePlayer player)Parameters
| Parameter | Type | Description |
|---|---|---|
autoTurret | AutoTurret | The AutoTurret entity the player is removing their own authorization from. Use it to read turret state such as IsOnline(), authorizedPlayers or its position. |
player | BasePlayer | The BasePlayer who pressed the deauthorize button on the turret's UI. This is the same player the original method passed into the authorization check. |
Return value
Returning null lets the game continue: the player's user ID is removed from authorizedPlayers, the auth list is marked dirty and the analytics event is sent. Returning any non-null object cancels the whole sequence, so the player stays authorized and nothing is updated.
How it works
The hook fires inside AutoTurret.RemoveSelfAuthorize, the RPC handler that runs when a player clicks the deauthorize button on a turret they are authorized on. The game only reaches the hook when the turret is not booting, is offline (IsOnline() is false), and the player is currently in authorizedPlayers — so the call always represents a real self-removal, never a rejected request.
autoTurret gives you the entity itself: check authorizedPlayers, IsOnline(), OwnerID or transform.position. player is the person performing the removal; compare player.userID against the turret owner if the rule depends on who is leaving.
Injecting at this point lets you veto the change, because the authorized list has not been modified yet. The default flow removes the user ID, flags the auth list dirty, writes an analytics event and recalculates max auth capacity — all of that is skipped when you return a non-null value.
Because the hook only fires on a deliberate button press on an offline turret, it is not a hot path; lightweight checks and messages are fine here. Use OnTurretAuthorize for the opposite direction.
Example plugin: Keep the owner authorized on their own turret
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
namespace Oxide.Plugins
{
[Info("Turret Owner Lock", "RustPluginGenerator", "1.0.0")]
[Description("Prevents the owner of an AutoTurret from removing their own authorization.")]
public class TurretOwnerLock : RustPlugin
{
private const string PermBypass = "turretownerlock.bypass";
private PluginConfig config;
private class PluginConfig
{
[JsonProperty("Prevent owner deauthorize")]
public bool PreventOwnerDeauthorize { get; set; } = true;
[JsonProperty("Notify player when blocked")]
public bool NotifyPlayer { 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>
{
["OwnerCannotDeauthorize"] = "You own this turret and cannot remove your own authorization.",
["Blocked"] = "You are not allowed to deauthorize this turret."
}, 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 OnTurretDeauthorize(AutoTurret autoTurret, BasePlayer player)
{
if (autoTurret == null || player == null) return null;
if (!config.PreventOwnerDeauthorize) return null;
if (autoTurret.OwnerID != player.userID.Get()) return null;
if (permission.UserHasPermission(player.UserIDString, PermBypass)) return null;
if (config.NotifyPlayer)
player.ChatMessage(Msg("OwnerCannotDeauthorize", player.UserIDString));
return true;
}
}
}The plugin reads a config flag PreventOwnerDeauthorize (default true) and, in OnTurretDeauthorize, compares player.userID with autoTurret.OwnerID. When they match and the option is enabled, it sends the localized OwnerCannotDeauthorize message to that player and returns true, which blocks the removal. Any other player — a team member or a guest granted authorization — is left to the vanilla flow, so normal turret management still works. The config class and messages are loaded at startup, and a permission turretownerlock.bypass lets admins remove themselves anyway.
Common use cases
Protect owners from accidental lockout
Stop the turret owner from removing themselves so they cannot lose control of the base defences by a misclick. Other authorized players can still leave normally.
Log authorization changes for auditing
Record who removed themselves from which turret, with position and time, so admins can trace who had access to a base during a raid.
Require an item check before leaving
Only allow deauthorization while the player holds a specific tool or has a permission, otherwise return a non-null value and send a chat hint.
Pitfalls
The turret is always offline at this point
The handler only runs when
IsOnline()is false, so online-turret logic is irrelevant here. Do not branch on online state to decide whether the hook fires.Blocking also skips analytics
Returning a value skips the Azure auth-change event and the max auth capacity recalculation along with the list removal. That is fine for denials, but do not return a value just to appear in logs.
Only fires for self-removal
An owner clearing someone else's authorization goes through a different code path, so this hook will not observe that. Use
OnTurretAuthorizeand related turret hooks to cover the other direction.
Build a plugin with OnTurretDeauthorize
Describe what should happen and get a compiled plugin that uses this hook.
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 OnTurretDeauthorize
Generate