OnTurretStartup
OnTurretStartup is called when an AutoTurret entity runs its startup routine (AutoTurret.InitiateStartup), before the turret plays its online sound and schedules the transition to the online state.
object OnTurretStartup(AutoTurret autoTurret)Parameters
| Parameter | Type | Description |
|---|---|---|
autoTurret | AutoTurret | The AutoTurret entity that is about to power on. It is the same object passed as the `this` argument to the game's startup routine, so you can read its owner, position, flags and attached power state. |
Return value
Returning null (or nothing after the hook runs) lets the turret continue startup: the online sound plays, the two-second online invoke is scheduled and booting is set. Returning any non-null value aborts the rest of InitiateStartup, so the turret stays offline and no sound or invoke is triggered.
How it works
Oxide fires this hook inside AutoTurret.InitiateStartup, which the game calls when a turret is turned on (for example by sending the power-on input, by a nearby player pressing use, or by an authorized player toggling it). The call happens before the online sound plays and before the two-second Invoke that sets the turret online and sets booting. The only parameter is the AutoTurret instance, so you can inspect its OwnerID, net.ID.Value, transform.position, its GetBuildingPrivilege() if relevant, and any BaseEntity flags such as Flags.On.
Because a return value stops the startup, you can use the hook to block turrets from powering on: return any non-null object (the game code only checks != null) and the sound, the Invoke and the booting flag are skipped entirely. This is a blocking check only — it does not stop turrets that are already online, and it does not prevent an admin from toggling them.
If you only want to observe startups, declare the parameter as AutoTurret (the given type) and return null, so the original method continues normally. Narrowing to a more specific type is not useful here because AutoTurret is already the concrete class and subclasses are not common in vanilla.
Example plugin: Keep bunker turrets disabled until the server has finished loading
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
namespace Oxide.Plugins
{
[Info("Turret Lockdown On Startup", "RustPluginGenerator", "1.0.0")]
[Description("Blocks AutoTurret startup during maintenance or event windows via OnTurretStartup.")]
public class TurretLockdownOnStartup : RustPlugin
{
private const string PermToggle = "turretlockdownonstartup.toggle";
private PluginConfig config;
public class PluginConfig
{
[JsonProperty("Block turrets")]
public bool BlockTurrets { get; set; } = false;
[JsonProperty("Log blocked startups")]
public bool LogBlocked { 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>
{
["Blocked"] = "Turret startup is currently blocked across the server.",
["Allowed"] = "Turret startup is now allowed.",
["Denied"] = "You don't have permission to toggle turret startup.",
["BlockedCount"] = "Blocked turret startup at {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(PermToggle, this);
}
private object OnTurretStartup(AutoTurret autoTurret)
{
if (autoTurret == null) return null;
if (!config.BlockTurrets) return null;
if (config.LogBlocked)
{
PrintWarning(Msg("BlockedCount", null, autoTurret.transform.position));
}
return false;
}
[ChatCommand("turret.toggle")]
private void CmdToggle(BasePlayer player, string command, string[] args)
{
if (player == null) return;
if (!permission.UserHasPermission(player.UserIDString, PermToggle))
{
player.ChatMessage(Msg("Denied", player.UserIDString));
return;
}
config.BlockTurrets = !config.BlockTurrets;
SaveConfig();
player.ChatMessage(Msg(config.BlockTurrets ? "Blocked" : "Allowed", player.UserIDString));
}
}
}This plugin demonstrates blocking OnTurretStartup by returning a non-null object. It reads a config flag BlockTurrets and, when enabled, returns false from the hook so every AutoTurret that tries to power on is left offline. A chat command turret.toggle lets an admin flip the flag at runtime, and the plugin logs each blocked startup through a batched counter so it does not spam the console. The default config keeps turrets working normally, so installing the plugin without changes has no effect; admins enable it during maintenance or when an exploit is being abused.
Common use cases
Freeze raiding turrets during an event
Return a non-null value while a server event is active so players cannot power on AutoTurrets, then stop blocking when the event ends. Useful for PvE events where observers would otherwise be shot.
Log turret activations per player
Return
nulland recordautoTurret.OwnerIDand position in a data file to track which turrets are being turned on and when. This gives admins a history without changing gameplay.Delay turrets on wipe day
Block startup for a fixed period after a wipe so raiders have time to build before defenses come online. Store the deadline in config and return a non-null value only before it passes.
Pitfalls
Any non-null return blocks startup
The game checks only
!= null, so returningfalseor0is enough to abort the routine. If you intend to allow startup, returnnullexplicitly or let the method exit without a return statement.Does not affect already-online turrets
The hook only fires inside
InitiateStartup. If a turret is already online, blocking the next startup will not turn it off; you also needOnTurretShutdownor a manual shutdown.Called for every turret including NPC and test turrets
AutoTurrets placed by the map or by other plugins also call this hook. If you only want to affect player-owned turrets, check
autoTurret.OwnerIDor the building privilege before returning a value.
Build a plugin with OnTurretStartup
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 OnTurretStartup
Generate