CanHelicopterStrafeTarget
CanHelicopterStrafeTarget is called when a patrol helicopter checks whether a player is a valid target for its rocket/strafe attack, before the built-in validation runs.
object CanHelicopterStrafeTarget(PatrolHelicopterAI patrolHelicopterAI, BasePlayer ply)Parameters
| Parameter | Type | Description |
|---|---|---|
patrolHelicopterAI | PatrolHelicopterAI | The PatrolHelicopterAI instance deciding whether to strafe at the player. Use it to read the helicopter entity, its position, or its current target state. |
ply | BasePlayer | The BasePlayer being evaluated as a strafe/rocket target. Can be null in the unpatched method, so check it before reading player state. |
Return value
Return a bool to replace the game's own result for ValidRocketTarget: true marks the player as a valid strafe/rocket target and lets the attack proceed, false rejects the player. Return null (or anything that is not a bool) to let the original validation logic decide.
How it works
The hook fires inside PatrolHelicopterAI.ValidRocketTarget, which the helicopter calls while it decides whether a given player may be attacked. Every time the AI evaluates a candidate player for a strafe or rocket target, your hook runs first with the AI instance and the candidate player.
Use patrolHelicopterAI to inspect the helicopter entity (its net.ID, position, or GetParentEntity() via the AI's base entity reference) and ply to read the player's status: health, team, mounted state, building privileges, or position relative to the helicopter. Returning a bool overrides the game's own decision for that call.
Because the injection makes the game use a returned bool as the method result, you must return a real bool to change the outcome; returning null lets the original validation continue. A ply can be null, so guard it. There is no separate overload for rocket versus strafe calls here; both go through this single check. Keep the method cheap since it can run repeatedly for each nearby player as the AI scans targets.
Example plugin: Make helicopters ignore players in safe zones and building-blocked areas
using System.Collections.Generic;
using System;
using Newtonsoft.Json;
using Oxide.Core;
namespace Oxide.Plugins
{
[Info("Helicopter Safe Zone Target", "RustPluginGenerator", "1.0.0")]
[Description("Stops patrol helicopters from strafing players in protected states")]
public class HelicopterSafeZoneTarget : RustPlugin
{
private const string PermAdmin = "helicoptersafezonetarget.admin";
private PluginConfig config;
private class PluginConfig
{
[JsonProperty("Protect building blocked players")]
public bool ProtectBuildingBlocked = true;
[JsonProperty("Protect mounted players")]
public bool ProtectMounted = true;
[JsonProperty("Protect players at full health")]
public bool ProtectFullHealth = false;
}
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>
{
["ToggleOn"] = "Helicopter protection is now enabled for you.",
["ToggleOff"] = "Helicopter protection is now disabled for you."
}, this);
}
private void Init()
{
permission.RegisterPermission(PermAdmin, this);
}
// Runs before the game decides whether the helicopter may strafe/rocket this player.
private object CanHelicopterStrafeTarget(PatrolHelicopterAI patrolHelicopterAI, BasePlayer ply)
{
if (ply == null || ply.IsNpc || !ply.IsAlive() || ply.IsWounded())
return null;
if (config.ProtectBuildingBlocked && ply.IsBuildingBlocked())
return false;
if (config.ProtectMounted && ply.GetMounted() != null)
return false;
if (config.ProtectFullHealth && ply.health >= ply.MaxHealth())
return false;
return null;
}
[ChatCommand("heli.protect")]
private void CmdHeliProtect(BasePlayer player, string command, string[] args)
{
if (player == null) return;
if (!permission.UserHasPermission(player.UserIDString, PermAdmin))
{
player.ChatMessage("You do not have permission to use this command.");
return;
}
config.ProtectBuildingBlocked = !config.ProtectBuildingBlocked;
SaveConfig();
player.ChatMessage(Msg(config.ProtectBuildingBlocked ? "ToggleOn" : "ToggleOff", player.UserIDString));
}
private string Msg(string key, string userId = null, params object[] args) =>
string.Format(lang.GetMessage(key, this, userId), args);
}
}The plugin blocks the patrol helicopter from strafing players who are inside a safe zone, mounted on a vehicle, or standing where building is blocked (for example inside a defended compound). In CanHelicopterStrafeTarget it null-checks the player, then returns false when any protection condition applies so ValidRocketTarget rejects that player. Otherwise it returns null, which lets the built-in AI validation run unchanged. A short config lists the toggle flags, and the helper uses ply.IsBuildingBlocked() and ply.GetMounted() to detect protected states. Admins can toggle the protection with a chat command that writes the config.
Common use cases
Protect safe-zone players
Return false when the candidate player is inside a safe zone so the helicopter never targets traders or players standing next to the bandit camp.
Ignore mounted players
Reject players who are driving a car or boat, so helicopters do not waste rockets on targets that are hard to hit or that would crash on impact.
VIP prioritization
Return null for normal players but force the choice for specific players by reading permission state and returning true to make the helicopter focus on them.
Pitfalls
Returning true without checking
Returning true for every player bypasses the game's normal target rules and can make helicopters fire at dead, wounded, or otherwise invalid players. Only force true when you have a real reason.
Null player argument
The original method handles a null player after the hook call. If you read
ply.userIDorply.transformwithout a null check your plugin throws and the hook effectively fails.Non-bool returns do nothing
Only a bool result replaces the game's answer. Returning an int, string, or object is ignored and the default validation runs, so use true, false, or null deliberately.
Build a plugin with CanHelicopterStrafeTarget
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 CanHelicopterStrafeTarget
Generate