CanUseHBHFSensor
CanUseHBHFSensor is called when a player tries to use an HBHFSensor, before the sensor's own CanBuild check runs. Returning a boolean overrides whether the use is allowed.
object CanUseHBHFSensor(BasePlayer player, HBHFSensor hBHFSensor)Parameters
| Parameter | Type | Description |
|---|---|---|
player | BasePlayer | The BasePlayer attempting to interact with the HBHFSensor. Always the player who triggered the use, never null when the hook is called from normal interaction. |
hBHFSensor | HBHFSensor | The HBHFSensor entity being used. Use it to check owner, position, flags or attached building privilege when deciding whether to allow the use. |
Return value
Return true to allow the use even if player.CanBuild() would fail, or false to block the use outright. Return null (or any non-bool value) to let the game fall back to the default player.CanBuild() check.
How it works
This hook fires inside HBHFSensor.CanUse, which the game calls when a player attempts to interact with an HBHFSensor (the detector from the hbhf_sensor deployable). It runs before the default player.CanBuild() result is returned, so you can allow or block the use regardless of build privilege. The player argument is the user performing the action; hBHFSensor is the sensor entity itself, useful for checking OwnerID, position, or the building privilege covering it. Because the original method returns bool, only a bool return value is used — if you return anything else, Oxide ignores it and the game falls back to player.CanBuild(). Declaring the entity parameter as a more specific type is not helpful here since the hook already passes HBHFSensor; declaring player as BasePlayer is the natural choice. Keep the handler fast — it runs per interaction attempt, so avoid allocations or expensive scans inside it.
Example plugin: Restrict HBHF sensor use to the owner or their team
using System.Linq;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Hbhf Sensor Owner Only", "RustPluginGenerator", "1.0.0")]
[Description("Restricts HBHF sensor use to the owner (and optionally their team).")]
public class HbhfSensorOwnerOnly : RustPlugin
{
private const string PermBypass = "hbhfsensorowneronly.bypass";
private PluginConfig config;
private class PluginConfig
{
[JsonProperty("Share with owner's team")]
public bool ShareWithTeam { get; set; } = true;
[JsonProperty("Allow admins to bypass")]
public bool AdminBypass { 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>
{
["NotOwner"] = "This sensor belongs to someone else."
}, this);
}
private string Msg(string key, string userId = null) => lang.GetMessage(key, this, userId);
private void Init()
{
permission.RegisterPermission(PermBypass, this);
}
private object CanUseHBHFSensor(BasePlayer player, HBHFSensor sensor)
{
if (player == null || sensor == null) return null;
if (config.AdminBypass && player.IsAdmin) return null;
if (permission.UserHasPermission(player.UserIDString, PermBypass)) return null;
if (sensor.OwnerID == player.userID.Get()) return null;
if (config.ShareWithTeam)
{
ulong ownerId = sensor.OwnerID;
BasePlayer owner = BasePlayer.FindByID(ownerId);
if (owner != null && owner.currentTeam != 0 && owner.currentTeam == player.currentTeam)
return null;
var team = RelationshipManager.ServerInstance.FindTeam(player.currentTeam);
if (team != null && team.members.Contains(ownerId))
return null;
}
player.ChatMessage(Msg("NotOwner", player.UserIDString));
return false;
}
}
}This plugin blocks anyone except the sensor's owner (and, optionally, members of the owner's team) from using an HBHFSensor, while still letting authorized players pass the default build check. The config exposes a toggle for team sharing. On each call, the handler confirms the player matches the sensor owner, or — when team sharing is on — looks up the owner's team through RelationshipManager.ServerInstance.FindTeam and checks if the player is a member. If allowed, it returns null so the normal player.CanBuild() check still applies; otherwise it returns false and the interaction is rejected. Build eligibility is not bypassed, so a stranger who happens to be building-authorised still needs to be on the team.
Common use cases
Owner-only sensor access
Turn HBHFSensors into private detectors by rejecting use attempts from anyone who does not own the sensor, independent of build privilege.
Team-shared sensors
Allow teammates of the owner to use the sensor, but block other players who might otherwise be authed on a nearby base.
Raid gating
Block use of the sensor while a raid or event is active by returning false until the plugin clears the flag, then fall back to the default check.
Pitfalls
Only bool returns take effect
The game compares the returned object against
bool. Returning any other type, including integers, strings or null, is ignored and the originalplayer.CanBuild()check runs.Return null to keep build checks
If you return
trueto allow use, you skip the defaultCanBuildgate entirely, which means players can use sensors placed in areas they normally could not. Returnnullwhen you want the original check to still apply.Team lookup can return null
FindTeamreturns null when the id is zero or the team no longer exists. Null-check the team and fall back to denying (or granting) instead of assuming the members list is available.
Build a plugin with CanUseHBHFSensor
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 CanUseHBHFSensor
Generate