Skip to content
RustPluginGenerator

OnHuntEventStart

OnHuntEventStart is called when the game is about to begin the Egg Hunt seasonal event, right before EggHuntEvent.StartEvent initializes collection counts and spawns eggs.

Signature
object OnHuntEventStart(EggHuntEvent eggHuntEvent)

Parameters

Hook parameters
ParameterTypeDescription
eggHuntEventEggHuntEventThe EggHuntEvent instance that is about to start. Use it to read the event's transform position, inspect flags, or schedule follow-up logic against the active event object.

Return value

Returning null (or having no return, which is the same for an object-returning hook) lets StartEvent continue and the egg hunt proceeds normally. Returning any non-null value stops the original method, so the event does not initialize and no eggs are placed for that run.

How it works

The hook fires at the top of EggHuntEvent.StartEvent, before the event counts active players (or bots), builds the combined player list, and proceeds with its normal startup work. It only triggers when the server actually starts an egg hunt - typically because the event spawner decided it is time, not on every player action, so it is a rare hook.

The single parameter is the live EggHuntEvent object. Read it rather than modifying it: useful members are its position via transform.position, net.ID, and the entity itself if you need to track it. Declaring the parameter as EggHuntEvent is required to receive the call; there is no alternative signature.

Because the injection uses a non-null return check, returning a value from your hook stops StartEvent from running its normal body. That makes the hook a clean gate for admins who want to suppress egg hunts during specific periods, or for plugins that want to run their own replacement event logic. Keep the hook body short - it is called once per event start, but any work here delays event initialization.

Example plugin: Announce egg hunts and block them for opted-out admins

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

namespace Oxide.Plugins
{
    [Info("Hunt Event Announcer", "RustPluginGenerator", "1.0.0")]
    [Description("Announces egg hunt starts and lets admins block the event via command.")]
    public class HuntEventAnnouncer : RustPlugin
    {
        private const string PermBlock = "hunteventannouncer.admin";

        private PluginConfig config;

        private class PluginConfig
        {
            [JsonProperty("Announce event start")]
            public bool Announce { get; set; } = true;

            [JsonProperty("Block egg hunts")]
            public bool Blocked { get; set; } = 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>
            {
                ["Announce"] = "An egg hunt has started near {0}. Good luck!",
                ["Blocked"] = "Egg hunts are currently disabled.",
                ["Toggled"] = "Egg hunts are now {0}.",
                ["NoPerm"] = "You do not have permission to toggle egg hunts."
            }, 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(PermBlock, this);
        }

        [ChatCommand("huntblock")]
        private void CmdHuntBlock(BasePlayer player, string command, string[] args)
        {
            if (player == null) return;
            if (!permission.UserHasPermission(player.UserIDString, PermBlock))
            {
                SendReply(player, Msg("NoPerm", player.UserIDString));
                return;
            }

            config.Blocked = !config.Blocked;
            SaveConfig();
            SendReply(player, Msg("Toggled", player.UserIDString, config.Blocked ? "blocked" : "enabled"));
        }

        private object OnHuntEventStart(EggHuntEvent eggHuntEvent)
        {
            if (eggHuntEvent == null) return null;

            if (config.Announce)
            {
                Vector3 pos = eggHuntEvent.transform.position;
                Server.Broadcast(Msg("Announce", null, FormatPosition(pos)));
            }

            if (config.Blocked)
            {
                Puts("Egg hunt suppressed by configuration.");
                return true;
            }

            return null;
        }

        private static string FormatPosition(Vector3 pos)
            => string.Format("{0:0}, {1:0}", pos.x, pos.z);
    }
}

The plugin tracks a blocked flag in its config. When OnHuntEventStart fires it broadcasts a chat announcement with the event's world position so players can find the hunt area, then returns true if blocking is enabled. Because a non-null return stops EggHuntEvent.StartEvent, an admin toggle via /huntblock lets the server suppress the event during off-season without disabling the game's spawner. The hunt.announce permission is checked for the chat command, and the config value is persisted between restarts so a blocked state survives wipes or restarts.

Common use cases

  • Seasonal scheduling gate

    Return a non-null value outside the configured event window so egg hunts do not leak into unrelated parts of the server's calendar.

  • Broadcast event location

    Read eggHuntEvent.transform.position and broadcast coordinates so players know where the hunt spawned without relying on the in-game map marker.

  • Custom reward integration

    Use the announcement as a trigger to grant an Economics or server-rewards bonus to all connected players before the hunt begins.

Pitfalls

  • Returning a value silently skips the event

    Any non-null return stops StartEvent entirely. If your hook returns the result of a helper, make sure that helper returns null when you intend the event to proceed.

  • Event object may be destroyed shortly after

    Do not cache the EggHuntEvent reference for long; it can be killed at any time. Re-check with IsDestroyed or refetch via BaseNetworkable.serverEntities before using it later.

  • Hook does not fire for manually started events

    Only the game's own StartEvent path triggers this hook. If your plugin starts a hunt through a different code path, no callback is delivered, so wrap custom starts yourself.

Build a plugin with OnHuntEventStart

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

Prompt: Seasonal scheduling gate using the OnHuntEventStart 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 OnHuntEventStart

Generate