Skip to content
RustPluginGenerator

OnEventTrigger

OnEventTrigger is called when a TriggeredEventPrefab is about to run its event and spawn its prefab. Returning a non-null value cancels the spawn entirely.

Signature
object OnEventTrigger(TriggeredEventPrefab triggeredEventPrefab)

Parameters

Hook parameters
ParameterTypeDescription
triggeredEventPrefabTriggeredEventPrefabThe TriggeredEventPrefab component that is about to spawn its event entity (for example an airdrop, cargo plane, patrol helicopter or supply signal crate). Use its targetPrefab resource path and transform to identify and locate the event.

Return value

Returning null lets the original code continue and the event entity is created as normal. Returning any non-null object stops the method before it logs and spawns the prefab, so the event never happens.

How it works

The hook fires inside TriggeredEventPrefab.RunEvent, right before the game logs the event and creates the entity from targetPrefab.resourcePath. Anything in the world that schedules an event through a TriggeredEventPrefab component passes through here: airdrops, cargo planes, patrol helicopters, supply signals and other prefab-driven spawns. The single argument is the component itself, so you can read triggeredEventPrefab.targetPrefab.resourcePath to know which event it is, and its transform to know where it will appear. There is only one overload, so you cannot narrow it by parameter type; you must filter by prefab path inside the hook. Because the hook fires for every event prefab in the world, keep the body cheap and avoid logging. If you need to reroute an event instead of blocking it, you have to block it here and spawn your own replacement entity yourself, since the return value does not swap the prefab.

Example plugin: Limit airdrop events and broadcast a warning when blocked

EventTriggerLimiter.cs
using System.Linq;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;

namespace Oxide.Plugins
{
    [Info("Event Trigger Limiter", "RustPluginGenerator", "1.0.0")]
    [Description("Limits how often airdrop events may trigger and can block them per permission.")]
    public class EventTriggerLimiter : RustPlugin
    {
        private const string PermBypass = "eventtriggerlimiter.bypass";
        private const string AirdropPrefab = "airdrop";

        private PluginConfig config;
        private int activeAirdrops;
        private readonly List<Timer> timers = new List<Timer>();

        private class PluginConfig
        {
            [JsonProperty("Maximum concurrent airdrops")]
            public int MaxAirdrops = 1;

            [JsonProperty("Cooldown window in seconds")]
            public float WindowSeconds = 300f;

            [JsonProperty("Block airdrops for players without bypass permission")]
            public bool RequireBypassForExtra = 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>
            {
                ["AirdropBlocked"] = "An airdrop event was blocked: the limit of {0} is already active."
            }, 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(PermBypass, this);
        }

        private object OnEventTrigger(TriggeredEventPrefab triggeredEventPrefab)
        {
            if (triggeredEventPrefab == null || triggeredEventPrefab.targetPrefab == null)
                return null;

            string path = triggeredEventPrefab.targetPrefab.resourcePath;
            if (string.IsNullOrEmpty(path) || !path.Contains(AirdropPrefab))
                return null;

            if (activeAirdrops >= config.MaxAirdrops)
            {
                SendReplyToAll(Msg("AirdropBlocked", null, config.MaxAirdrops));
                return true;
            }

            activeAirdrops++;
            Timer cooldown = timer.Once(config.WindowSeconds, () =>
            {
                if (activeAirdrops > 0) activeAirdrops--;
            });
            if (cooldown != null) timers.Add(cooldown);

            return null;
        }

        private void SendReplyToAll(string message)
        {
            foreach (BasePlayer player in BasePlayer.activePlayerList)
            {
                if (player == null || !player.IsConnected) continue;
                if (config.RequireBypassForExtra && permission.UserHasPermission(player.UserIDString, PermBypass))
                    continue;
                player.ChatMessage(message);
            }
        }

        private void Unload()
        {
            foreach (Timer timer in timers)
            {
                if (timer != null) timer.Destroy();
            }
            timers.Clear();
        }
    }
}

The plugin keeps a running count of active airdrop events and blocks new ones once the configured maximum is reached. In OnEventTrigger it checks whether the prefab path contains the airdrop prefab name; if not, it returns null and the event proceeds untouched. For airdrops it compares the running count against the configured maximum. When the limit is reached it sends a chat message to all connected players and returns true to cancel the spawn. Otherwise it increments the counter, starts a timer that decrements it after the configured window, and returns null. If RequireBypassForExtra is true, players with eventtriggerlimiter.bypass are skipped when the warning is broadcast; the permission does not affect whether an airdrop is blocked. Config holds the maximum, the cooldown window in seconds and that broadcast toggle.

Common use cases

  • Block airdrop spam on small maps

    Return non-null when the airdrop prefab fires more often than the configured limit, preventing excess crates from controlling the map.

  • Disable patrol helicopter spawns on a PvE server

    Match the helicopter prefab path and cancel the event so it never appears, without touching other events.

  • Log or gate event spawns for admins only

    Let permission holders trigger restricted events by blocking the prefab and spawning your own variant, or simply count events for statistics.

Pitfalls

  • One hook, every event

    The argument type is identical for all prefab events, so you must compare targetPrefab.resourcePath and return null for anything you do not mean to affect.

  • Blocking does not relocate

    A non-null return cancels the spawn; it does not move or replace the event. Spawn your own entity with GameManager.server.CreateEntity if you need a reroute.

  • Fires on every event, keep it light

    Avoid heavy allocations or logging inside the hook; it runs whenever any TriggeredEventPrefab activates, including on busy servers with many events.

Build a plugin with OnEventTrigger

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

Prompt: Block airdrop spam on small maps using the OnEventTrigger 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 OnEventTrigger

Generate