OnHelicopterAttack
OnHelicopterAttack is called when a CH47 Chinook is attacked and before the game applies the damage reaction in CH47HelicopterAIController.OnAttacked. Returning a non-null value cancels that reaction.
object OnHelicopterAttack(CH47HelicopterAIController helicopter, HitInfo info)Parameters
| Parameter | Type | Description |
|---|---|---|
helicopter | CH47HelicopterAIController | The CH47 Chinook AI controller that was hit. Use it for its position, health (Health()/MaxHealth()), and to read or change its state. |
info | HitInfo | The HitInfo describing the attack: damage amount, damage types (ScaleAll/Scale), initiating player (InitiatorPlayer), weapon and hit position. |
Return value
Returning null lets the game continue: base attack handling runs, InitiateAnger() fires, and the Chinook reacts to the attacker. Returning any non-null value (e.g. true) makes the patched call return early, so the Chinook neither processes the hit nor becomes angry. The original method returns void, so the returned value itself is discarded.
How it works
The hook fires from CH47HelicopterAIController.OnAttacked, which the game invokes whenever the Chinook receives a hit. That covers bullets, melee, explosions and any other damage source routed through HitInfo. The hook runs before the controller's base attack handling and before InitiateAnger() marks the target as a threat.
Use info to inspect the source of damage: info.InitiatorPlayer gives the attacker (null for NPC or environmental damage), info.damageTypes.Total() gives the incoming amount, and info.damageTypes.GetMajorityDamageType() tells you whether it was bullets, explosions or something else. Use the helicopter parameter to read or alter its health, position or state.
The first parameter is typed CH47HelicopterAIController, so declare it exactly that way. If you declare BaseCombatEntity or BaseEntity, Oxide's dispatch still matches the call, but you lose access to controller-specific members.
Because the hook also gates anger, returning a value makes the Chinook ignore the hit entirely for retaliation purposes. Common uses are damage scaling, PvE protection, custom announcements, and rewarding the attacker.
Example plugin: Scale and announce player damage to the Chinook
using System.Linq;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Helicopter Attack Guard", "RustPluginGenerator", "1.0.0")]
[Description("Scales or blocks player damage on the CH47 Chinook and announces hits.")]
public class HelicopterAttackGuard : RustPlugin
{
private const string PermAdmin = "helicopterattackguard.admin";
private PluginConfig config;
private readonly Dictionary<ulong, float> lastNotice = new Dictionary<ulong, float>();
private class PluginConfig
{
[JsonProperty("Damage multiplier for player hits")]
public float DamageMultiplier = 1.5f;
[JsonProperty("Block player damage entirely")]
public bool BlockPlayerDamage = false;
[JsonProperty("Notify attacker in chat")]
public bool NotifyAttacker = true;
[JsonProperty("Minimum seconds between notices per player")]
public float NoticeCooldown = 15f;
}
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>
{
["Hit"] = "You hit a Chinook for {0} damage.",
["Blocked"] = "The Chinook is protected from player damage."
}, this);
}
private string Msg(string key, string userId = null, params object[] args) => string.Format(lang.GetMessage(key, this, userId), args);
private void Init()
{
permission.RegisterPermission(PermAdmin, this);
}
private object OnHelicopterAttack(CH47HelicopterAIController helicopter, HitInfo info)
{
if (helicopter == null || info == null || info.damageTypes == null) return null;
BasePlayer attacker = info.InitiatorPlayer;
if (attacker == null || attacker.IsNpc) return null;
if (permission.UserHasPermission(attacker.UserIDString, PermAdmin)) return null;
if (config.BlockPlayerDamage)
{
if (config.NotifyAttacker) SendNotice(attacker, "Blocked");
return true;
}
info.damageTypes.ScaleAll(Mathf.Max(0f, config.DamageMultiplier));
if (config.NotifyAttacker)
{
SendNotice(attacker, "Hit", info.damageTypes.Total().ToString("0"));
}
return null;
}
private void SendNotice(BasePlayer player, string key, params object[] args)
{
float now = Time.realtimeSinceStartup;
float last;
if (lastNotice.TryGetValue(player.userID, out last) && now - last < config.NoticeCooldown) return;
lastNotice[player.userID] = now;
player.ChatMessage(Msg(key, player.UserIDString, args));
}
}
}The plugin multiplies damage from player attackers so admins can tune how punishing it is to shoot the CH47. In OnHelicopterAttack it reads info.InitiatorPlayer and skips the work when the attacker is not a player, so NPC or environmental hits pass through unchanged. With the BlockPlayerDamage option enabled it returns true to stop both the damage and the anger reaction. Otherwise it scales all damage types down or up, records the attacker's Steam ID for a short cooldown, and sends a chat notice through the language file. The config exposes the multiplier, the toggle, and the announcement text, and messages live in LoadDefaultMessages.
Common use cases
Make the Chinook immune to player fire
Return true from the hook when the attacker is a player to cancel both the hit reaction and the anger response, leaving the Chinook passive.
Damage multiplier for events
Use
info.damageTypes.ScaleAll(multiplier)to tune how quickly event Chinooks die without editing server config or the prefab.Alert the team that hit the Chinook
Read
info.InitiatorPlayer.currentTeamand message team members that a helicopter was engaged, useful for PvE servers tracking air encounters.
Pitfalls
Returning true stops anger too
The early return skips
InitiateAnger(), so a Chinook that you block from reacting will not target or fight back. Only return a value if you intend that.InitiatorPlayer is often null
Explosions from barrels, fall damage and NPC shots may not carry a player initiator. Always null-check
info.InitiatorPlayerbefore reading team or user ID.Hook only covers the Chinook
Patrol Helicopter hits are handled by a different code path. Do not expect this hook to fire for attack helicopters or Bradley.
Build a plugin with OnHelicopterAttack
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 OnHelicopterAttack
Generate