OnNearbyTurretsScan
OnNearbyTurretsScan is called by AutoTurret.AddNearbyTurrets right before the game scans for other turrets around a sentry, letting you supply your own list instead of the radius query. Returning a non-null value skips the game's own scan.
object OnNearbyTurretsScan(AutoTurret autoTurret, List<AutoTurret> nearbyTurrets)Parameters
| Parameter | Type | Description |
|---|---|---|
autoTurret | AutoTurret | The AutoTurret whose nearby-turret list is being rebuilt. Use it to read the position, owner or configuration of the turret that triggered the scan. |
nearbyTurrets | List<AutoTurret> | A pooled list the game fills with AutoTurret instances found around the scanning turret. You can add, remove or replace entries before the game iterates it to build the interference list. |
Return value
Return null and the game performs its normal Vis.Entities radius scan, appending results to the list. Return any non-null object (typically from a check or true) and the scan is skipped entirely, so the game uses only what your plugin put in the list before returning.
How it works
The hook fires inside AutoTurret.AddNearbyTurrets, the internal routine that refreshes the list of neighbouring turrets a sentry uses for interference checks. The method first clears its cached list, then asks Oxide for OnNearbyTurretsScan with the turret being processed and an empty pooled List<AutoTurret>. If no plugin returns a value, the game runs Vis.Entities with a radius of Sentry.interferenceradius and the 256 layer mask, filling the list with every AutoTurret in range (triggers ignored). Afterwards the game loops over whatever the list contains.
Because the game iterates the list even when you answer the hook, you can populate it yourself: add turrets that are farther away, add only turrets you consider authorised, or skip certain entities. The first parameter identifies the scanning sentry, so you can branch per owner, per position or per permission. Declaring autoTurret as AutoTurret (which it already is) keeps every call; there is no narrower type available. The list is pooled, so treat it as borrowed memory rather than something to keep.
Example plugin: Limit sentries to same-owner interference
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Turret Owner Scan", "RustPluginGenerator", "1.0.0")]
[Description("Replaces an AutoTurret's nearby-turret scan so only same-owner or same-team sentries count as interference")]
public class TurretOwnerScan : RustPlugin
{
private class PluginConfig
{
[JsonProperty("Scan radius")]
public float Radius = 40f;
[JsonProperty("Only turrets with a matching owner or team count")]
public bool OwnerOnly = true;
}
private PluginConfig config;
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);
private object OnNearbyTurretsScan(AutoTurret autoTurret, List<AutoTurret> nearbyTurrets)
{
if (autoTurret == null || nearbyTurrets == null) return null;
Vector3 origin = autoTurret.transform.position;
float radiusSqr = config.Radius * config.Radius;
ulong ownerId = autoTurret.OwnerID;
foreach (var entity in BaseNetworkable.serverEntities)
{
var other = entity as AutoTurret;
if (other == null || other == autoTurret || other.IsDestroyed) continue;
if ((other.transform.position - origin).sqrMagnitude > radiusSqr) continue;
if (config.OwnerOnly && ownerId != 0 && other.OwnerID != 0)
{
if (!SameOwnerOrTeam(autoTurret, other)) continue;
}
nearbyTurrets.Add(other);
}
return true;
}
private bool SameOwnerOrTeam(AutoTurret a, AutoTurret b)
{
ulong ownerA = a.OwnerID;
ulong ownerB = b.OwnerID;
if (ownerA == ownerB) return true;
var playerA = BasePlayer.FindByID(ownerA);
var playerB = BasePlayer.FindByID(ownerB);
if (playerA == null || playerB == null) return false;
if (playerA.currentTeam == 0 || playerA.currentTeam != playerB.currentTeam) return false;
return true;
}
}
}The plugin replaces the default radius scan so a sentry only treats turrets owned by the same player or team as interference. OnNearbyTurretsScan receives the scanning turret and the empty pooled list. It reads the owner via OwnerID, walks the server entity list with BaseNetworkable.serverEntities, and adds any AutoTurret inside the configured radius whose owner matches (same player id or same team id when both are on a team). Because the plugin returns true, Oxide skips the game's Vis.Entities call and the game iterates only the entries the plugin added. Radius is configurable in oxide/config/TurretOwnerScan.json.
Common use cases
Group turret interference by team
Fill the list only with turrets belonging to the same team as the scanning sentry, so allied bases do not power each other down while raiders nearby still cause interference.
Extend interference range for high-pop bases
Replace the default radius scan with your own distance check to a larger custom radius, producing a harsher or gentler interference rule than Facepunch's defaults.
Ignore specific turrets
Whitelist certain turrets (for example admin-placed or NPC turrets) by excluding them from the list so they never count as interference for anyone.
Pitfalls
Returning a value skips the default scan
A non-null return means the game never runs
Vis.Entities. If you return a value but leave the list empty, the sentry sees no neighbours at all and its interference behaviour changes silently.The list is pooled
Oxide and the game hand you a pooled
List<AutoTurret>. Add entries withAddand do not store the list reference in plugin state; it can be reused elsewhere after the call.Runs for every sentry refresh
AddNearbyTurretsis called whenever a sentry rebuilds its neighbour cache, which can be frequent on large servers. Keep the callback cheap and never callPutsorPrintWarninginside it.
Build a plugin with OnNearbyTurretsScan
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 OnNearbyTurretsScan
Generate