OnSensorDetect
OnSensorDetect is called by HBHFSensor.CountDetectedPlayers for every entity inside the sensor's trigger that is a player, before that player is counted as a detection.
object OnSensorDetect(HBHFSensor sensor, BasePlayer player)Parameters
| Parameter | Type | Description |
|---|---|---|
sensor | HBHFSensor | The HBHFSensor entity running the detection pass. Use it to read the sensor's position, owner, IO connections and the detection radius it is currently evaluating. |
player | BasePlayer | The player entity found inside the sensor's trigger volume during this pass. It may already be null in the game's loop, so always null-check before touching it. |
Return value
Return null to let the player count as a detection as normal. Returning any non-null value (for example true) makes CountDetectedPlayers skip that player entirely, so they are not counted and the sensor's output does not react to them. The value itself is not read, only whether it is null.
How it works
The hook fires inside HBHFSensor.CountDetectedPlayers, the method the HBHF sensor uses to work out how many players are currently in its detection range. The game walks myTrigger.entityContents, filters for BasePlayer, and calls OnSensorDetect for each candidate before checking dead, sleeping and server-only conditions. Returning a non-null value makes the loop skip that player, so the sensor does not count them and does not fire its outputs for them.
This gives you a per-player veto over detection. The player argument is the candidate, and the sensor argument is the exact sensor doing the check, which matters on bases with many sensors. You cannot narrow the arguments to a more specific player type because the game already passes the concrete BasePlayer; declaring object or BaseEntity would make Oxide pass different values, so keep the declared types as given.
The hook runs on every detection pass, which the sensor repeats on a short interval while powered, so keep the body cheap. Do not print to console inside it. Cache any permission or team lookups you need rather than recalculating heavy data for every player on every tick.
Example plugin: Ignore authorised players and teammates on HBHF sensors
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Sensor Team Ignore", "RustPluginGenerator", "1.0.0")]
[Description("Lets HBHF sensors ignore authorised players and the owner's team")]
public class SensorTeamIgnore : RustPlugin
{
private const string PermUse = "sensorteamignore.use";
private PluginConfig config;
private class PluginConfig
{
[JsonProperty("Ignore players authorised on the building")]
public bool IgnoreAuthorised { get; set; } = true;
[JsonProperty("Ignore players on the owner's team")]
public bool IgnoreTeam { get; set; } = true;
[JsonProperty("Only apply on sensors owned by users with the permission")]
public bool RequirePermission { 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);
private void Init()
{
permission.RegisterPermission(PermUse, this);
}
private void OnServerInitialized()
{
Puts($"Active rules: authorised={config.IgnoreAuthorised}, team={config.IgnoreTeam}, permission={config.RequirePermission}");
}
private object OnSensorDetect(HBHFSensor sensor, BasePlayer player)
{
if (sensor == null || player == null || player.IsNpc || !player.IsConnected) return null;
if (config.RequirePermission && !permission.UserHasPermission(sensor.OwnerID.ToString(), PermUse)) return null;
if (config.IgnoreAuthorised && IsAuthorised(sensor, player)) return true;
if (config.IgnoreTeam && IsSameTeam(sensor.OwnerID, player)) return true;
return null;
}
private bool IsAuthorised(HBHFSensor sensor, BasePlayer player)
{
BuildingPrivlidge privilege = sensor.GetBuildingPrivilege();
return privilege != null && privilege.IsAuthed(player);
}
private bool IsSameTeam(ulong ownerId, BasePlayer player)
{
BasePlayer owner = BasePlayer.FindByID(ownerId);
if (owner == null || owner.currentTeam == 0) return false;
return owner.currentTeam == player.currentTeam;
}
}
}The plugin lets server owners mark HBHF sensors as ignoring the base's authorised players and the sensor owner's own team. In OnSensorDetect it reads the sensor's building privilege and checks whether the candidate is authorised, then compares currentTeam values against the sensor owner's team. If either rule matches and that rule is enabled in config, it returns true so CountDetectedPlayers skips the player. The config also allows a permission gate, so only players with sensorteamignore.use get the filtering on sensors they own, and a startup message confirms which rules are active.
Common use cases
Ignore base members
Skip counting players who are authorised on the sensor's building privilege, so a team's own raid alarm does not trigger when they walk past their own sensor.
Ignore the owner's team
Compare
currentTeamvalues so anyone sharing a team with the sensor owner is never detected, useful on shared compounds.Restrict to raiders only
Combine the privilege and team checks with a permission gate so sensors only respond to genuinely hostile players, reducing false alarms on busy servers.
Pitfalls
The player argument can be null
The game's condition checks
basePlayer == nullafter the hook call, so treat the incoming player as possibly null and return early before reading any member.Runs on a repeating pass
A powered sensor reruns detection frequently. Avoid
Puts, disk access or heavy loops in this hook; cache permission results and short-circuit on cheap checks first.Returning false still skips
Only
nullkeeps default behaviour. Returningfalseis non-null and will exclude the player, so use an explicitreturn null;when you want normal counting.
Build a plugin with OnSensorDetect
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 OnSensorDetect
Generate