Skip to content
RustPluginGenerator

CanHelicopterStrafe

CanHelicopterStrafe is called when a patrol helicopter's AI checks whether it is allowed to begin a strafing run. Returning a bool overrides the game's own cooldown and random delay check.

Signature
object CanHelicopterStrafe(PatrolHelicopterAI patrolHelicopterAI)

Parameters

Hook parameters
ParameterTypeDescription
patrolHelicopterAIPatrolHelicopterAIThe PatrolHelicopterAI brain component of the patrol helicopter that is asking whether it may start a strafing run. Use its heli entity, position and target to decide.

Return value

Return null to let the game run its normal cooldown and random-delay check. Return true or false to force the strafing decision and bypass that native check completely for this call.

How it works

Oxide fires this hook inside PatrolHelicopterAI.CanStrafe, the routine the helicopter calls before it decides to strafe its current target. The method is evaluated repeatedly while the helicopter is hunting, so this hook can fire often during an active engagement.

If your hook returns a bool, the game uses that value as the answer and skips its native check entirely. That native check compares the time since lastStrafeTime against a random interval between 15 and 25 seconds, with other conditions layered on top. Returning true lets the helicopter strafe immediately, returning false blocks it. Returning null (or anything that is not a bool) lets the vanilla timing decide.

The single parameter is the PatrolHelicopterAI instance. Reach the entity behind it through patrolHelicopterAI.heli, which gives you position, health and owner. You can also read its current target field to gate strafes by target type.

Declaring the parameter as PatrolHelicopterAI is required here; there is no narrower type that makes sense. Keep the body cheap because the method is queried during combat, and do not print to console from it.

Example plugin: Limit helicopter strafes to every N seconds

HeliStrafePacing.cs
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("Heli Strafe Pacing", "RustPluginGenerator", "1.0.0")]
    [Description("Replaces the patrol helicopter's random strafe interval with a configurable cooldown.")]
    public class HeliStrafePacing : RustPlugin
    {
        private PluginConfig config;
        private readonly Dictionary<ulong, float> lastStrafe = new Dictionary<ulong, float>();

        private class PluginConfig
        {
            [JsonProperty("Minimum seconds between strafes")]
            public float Cooldown = 30f;
        }

        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 CanHelicopterStrafe(PatrolHelicopterAI patrolHelicopterAI)
        {
            if (patrolHelicopterAI == null)
                return null;

            BaseEntity heli = patrolHelicopterAI.helicopterBase;
            if (heli == null || heli.IsDestroyed)
                return null;

            ulong heliId = heli.net.ID.Value;
            float now = Time.realtimeSinceStartup;

            float last;
            if (lastStrafe.TryGetValue(heliId, out last) && now - last < config.Cooldown)
                return false;

            lastStrafe[heliId] = now;
            return true;
        }

        private void Unload()
        {
            lastStrafe.Clear();
        }
    }
}

The plugin keeps a per-helicopter timestamp of the last strafe it allowed, keyed by the helicopter's network ID. Inside CanHelicopterStrafe it looks up the ID on patrolHelicopterAI.helicopterBase, compares the current time against a configurable cooldown, and returns false while the cooldown is still running. When the cooldown has passed it records the new time and returns true, so the helicopter strafes on a predictable schedule. If the helicopter argument or its base entity is null or destroyed, the hook returns null and no cooldown is recorded. The timestamps are cleared entirely in Unload.

Common use cases

  • Fixed strafe cadence

    Replace the vanilla random 15 to 25 second interval with a server-wide constant so players can predict and plan around strafing runs.

  • Disable strafing for new players

    Return false while the helicopter's target is a player below a playtime threshold, keeping early-game raids survivable.

  • Event-controlled helicopter aggression

    Toggle a flag from an admin command so the helicopter can strafe aggressively during a custom event and behaves normally afterwards.

Pitfalls

  • Returning true ignores all native checks

    The hook replaces the entire CanStrafe result, so a hard true also skips conditions the game may add later. Return null unless you specifically want to override.

  • No target available during idle flight

    The helicopter calls this while patrolling too. Check patrolHelicopterAI._targetList or heli health before gating on a player, or you may block strafes with no visible effect.

  • Called frequently in combat

    Do not run expensive queries or spawn effects here. Store decisions in a dictionary keyed by patrolHelicopterAI.heli.net.ID.Value and read from it.

Build a plugin with CanHelicopterStrafe

Describe what should happen and get a compiled plugin that uses this hook.

Prompt: Fixed strafe cadence using the CanHelicopterStrafe hook, with a config file and a permission
Generate this plugin

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 CanHelicopterStrafe

Generate