OnTurretShutdown
OnTurretShutdown is called when an AutoTurret runs its shutdown routine, right before it cancels its boot timer, plays the offline sound and switches itself offline.
object OnTurretShutdown(AutoTurret autoTurret)Parameters
| Parameter | Type | Description |
|---|---|---|
autoTurret | AutoTurret | The AutoTurret entity that is shutting down. It is still online at the moment the hook fires, so you can read its flags, authorized players, owner and position before the game turns it off. |
Return value
Returning null (or nothing) lets the game continue: the boot timer is cancelled, the offline sound plays and SetIsOnline(false) runs. Returning any non-null value stops the original method body, so the turret stays online and skips the sound and online check.
How it works
The hook fires inside AutoTurret.InitiateShutdown, which the game runs whenever a turret should go offline: a player switching it off, the owner authorization changing, the entity being damaged into an error state, running out of power on a powered turret, or any other internal path that calls InitiateShutdown. The call only happens when the turret is not already offline or is still booting; an already-off turret has nothing to shut down. The single parameter is the turret entity itself, which is still online when you receive the call, so you can inspect IsOn(), its authorization list and its position. Declaring the parameter as AutoTurret is the only useful type; a base type would still receive the same object because the argument is always an AutoTurret instance. Because the same method is used by the game for unplanned shutdowns, the hook cannot distinguish an admin toggle from an internal failure, so you should not assume the cause. Returning a non-null value stops the original shutdown code, which leaves the turret in its current state.
Example plugin: Keep turrets online during a night lockdown
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
namespace Oxide.Plugins
{
[Info("Turret Night Lockdown", "RustPluginGenerator", "1.0.0")]
[Description("Prevents player-owned AutoTurrets from shutting down while lockdown mode is enabled")]
public class TurretNightLockdown : RustPlugin
{
private const string PermUse = "turretnightlockdown.use";
private PluginConfig config;
private class PluginConfig
{
[JsonProperty("Lockdown enabled")]
public bool LockdownEnabled { get; set; } = true;
[JsonProperty("Exempt admins")]
public bool ExemptAdmins { 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>
{
["LockdownOn"] = "Turret lockdown is now ON. Player turrets cannot shut down.",
["LockdownOff"] = "Turret lockdown is now OFF.",
["NoPermission"] = "You do not have permission to use this command.",
["Usage"] = "Usage: /turretlock <on|off|status>",
["Status"] = "Turret lockdown is currently {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(PermUse, this);
}
private void Unload()
{
SaveConfig();
}
[ChatCommand("turretlock")]
private void CmdTurretLock(BasePlayer player, string command, string[] args)
{
if (player == null) return;
if (!permission.UserHasPermission(player.UserIDString, PermUse))
{
player.ChatMessage(Msg("NoPermission", player.UserIDString));
return;
}
if (args == null || args.Length == 0)
{
player.ChatMessage(Msg("Usage", player.UserIDString));
return;
}
switch (args[0].ToLower())
{
case "on":
config.LockdownEnabled = true;
SaveConfig();
player.ChatMessage(Msg("LockdownOn", player.UserIDString));
break;
case "off":
config.LockdownEnabled = false;
SaveConfig();
player.ChatMessage(Msg("LockdownOff", player.UserIDString));
break;
case "status":
player.ChatMessage(Msg("Status", player.UserIDString, config.LockdownEnabled ? "ON" : "OFF"));
break;
default:
player.ChatMessage(Msg("Usage", player.UserIDString));
break;
}
}
private object OnTurretShutdown(AutoTurret autoTurret)
{
if (autoTurret == null || !config.LockdownEnabled) return null;
var owner = BasePlayer.FindByID(autoTurret.OwnerID);
if (owner != null && config.ExemptAdmins && owner.IsAdmin) return null;
return true; // non-null stops the shutdown, turret stays online
}
}
}The plugin adds a chat command that toggles a lockdown flag stored in the config. While the flag is on, OnTurretShutdown returns a non-null value for turrets owned by players who are not admins, which prevents the game from running the rest of InitiateShutdown, so those turrets stay online and skip the offline sound. Admins are exempt so they can still service or disable turrets themselves. The unlock command turns the flag off again, and the current state is saved to the config so a restart keeps the setting. The command checks the turretnightlockdown.use permission, registered in Init, so only trusted staff can flip the switch.
Common use cases
Night-time base defence
Block turret shutdowns during a defined in-game window so raiders cannot simply power off or toggle defences while the owners are offline.
Owner change protection
Log or block shutdowns that happen while a turret has authorized players, which can catch griefing attempts where someone clears the auth list.
Discord or staff alerts
Notify admins that a specific turret went offline, including its owner and position, so staff can look into suspicious activity.
Pitfalls
Blocking leaves the turret online permanently
A non-null return skips the whole method body, so the turret keeps its current online state. If your block condition stays true, the turret can never be switched off by its owner either.
The hook does not tell you why
InitiateShutdownis used for manual toggles, damage, power loss and other internal paths. If you need the cause, check the turret's health and power state yourself rather than guessing.Already-offline turrets are skipped
The game only calls the hook when the turret is online or booting. If you rely on it to track every offline transition, an already-off turret never triggers your code.
Build a plugin with OnTurretShutdown
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 OnTurretShutdown
Generate