Skip to content
RustPluginGenerator

OnMlrsFire

OnMlrsFire is called in MLRS.Fire right before the MLRS is set into its firing state, letting a plugin cancel the launch. Returning a non-null value stops the fire sequence.

Signature
object OnMlrsFire(MLRS mLRS, BasePlayer owner)

Parameters

Hook parameters
ParameterTypeDescription
mLRSMLRSThe MLRS vehicle entity whose Fire method is running. Use it to read the mounted player, position, owner ID or flags.
ownerBasePlayerThe BasePlayer the game treats as the operator of the MLRS at the moment of firing. It can be null in edge cases, so null-check it before using the player.

Return value

Returning null (or nothing) lets MLRS.Fire continue and the MLRS enters its firing state. Returning any non-null value stops the remaining code in Fire, so the reserved flag is never set and the launch does not start.

How it works

The hook fires inside MLRS.Fire, after the game has already checked that firing is possible (CanFire), that a player is mounted, and that the raid window is not blocked. It runs immediately before the vehicle sets the internal flag that starts the launch sequence, so it is the last point where the launch can still be prevented. The mLRS parameter is the vehicle entity itself, useful for its position, its mounted player, or its owner ID. The owner parameter is the player passed into Fire as the operator. Because the dispatch only checks types, declaring owner as a more specific type would never match, since the game passes a BasePlayer; keep the declared types as they are. The return value is what makes the hook useful: a non-null return (for example true or a string) aborts the rest of Fire, so no flag is set and no rocket launch begins. This is a good place to enforce per-player cooldowns, limit MLRS use to authorised groups, or apply a server event rule where MLRS launches are disallowed.

Example plugin: Restrict MLRS launches to a permission and add a per-player cooldown

MlrsFireGate.cs
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;

namespace Oxide.Plugins
{
    [Info("Mlrs Fire Gate", "RustPluginGenerator", "1.0.0")]
    [Description("Restricts MLRS launches by permission and a per-player cooldown")]
    public class MlrsFireGate : RustPlugin
    {
        private const string PermUse = "mlrsfiregate.use";

        private PluginConfig config;
        private Dictionary<string, double> lastLaunch = new Dictionary<string, double>();

        private class PluginConfig
        {
            [JsonProperty("Cooldown seconds (0 disables)")]
            public int CooldownSeconds = 300;

            [JsonProperty("Require permission to fire")]
            public bool RequirePermission = 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>
            {
                ["NoPermission"] = "You are not allowed to fire the MLRS.",
                ["Cooldown"] = "MLRS cooldown active, try again in {0} seconds."
            }, 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(PermUse, this);
            lastLaunch = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<string, double>>(Name) ?? new Dictionary<string, double>();
        }

        private void Unload()
        {
            Interface.Oxide.DataFileSystem.WriteObject(Name, lastLaunch);
        }

        private object OnMlrsFire(MLRS mLRS, BasePlayer owner)
        {
            if (mLRS == null || owner == null)
                return true;

            string userId = owner.UserIDString;

            if (config.RequirePermission && !permission.UserHasPermission(userId, PermUse))
            {
                owner.ChatMessage(Msg("NoPermission", userId));
                return true;
            }

            if (config.CooldownSeconds > 0)
            {
                double last;
                double now = DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
                if (lastLaunch.TryGetValue(userId, out last))
                {
                    double remaining = config.CooldownSeconds - (now - last);
                    if (remaining > 0)
                    {
                        owner.ChatMessage(Msg("Cooldown", userId, (int)Math.Ceiling(remaining)));
                        return true;
                    }
                }
                lastLaunch[userId] = now;
            }

            return null;
        }

        [ConsoleCommand("mlrsfiregate.purge")]
        private void CmdPurge(ConsoleSystem.Arg arg)
        {
            lastLaunch.Clear();
            Interface.Oxide.DataFileSystem.WriteObject(Name, lastLaunch);
            arg.ReplyWith("Cooldown data cleared.");
        }
    }
}

The plugin registers a permission and a configurable cooldown in seconds. In OnMlrsFire it checks that an owner is present, that the owner has mlrsfiregate.use, and that the stored cooldown timestamp for that player is in the past. If any check fails, it sends a language message to the player and returns true, which cancels the launch. On a successful pass it records the current unix time, saves the data file, and returns null so the MLRS fires normally. Cooldown timestamps live in a small data file keyed by user ID, written only when an actual launch is allowed, so the hook does not touch disk on every call. A purge console command clears stale entries.

Common use cases

  • Permission-gated MLRS

    Allow only members of a specific group or permission to launch MLRS rockets, returning a non-null value with a chat warning for everyone else.

  • Launch cooldowns

    Track the last launch time per user ID and block repeated firing within a configurable window to limit spam during raids.

  • Event or wipe-phase rules

    Disable MLRS entirely during a custom event or a grace period after wipe by returning a non-null value from the hook.

Pitfalls

  • Owner can be null

    The player argument is not guaranteed to be present in every path, so null-check owner before calling permission or chat methods on it; return a non-null value if you cannot verify the player.

  • Not the same as OnMlrsFired

    OnMlrsFire runs before the launch and can cancel it, while OnMlrsFired is a notification that the launch happened. Use the former for gating, the latter for logging or rewards.

  • Raid window already checked

    The game blocks firing when the raid window is closed before this hook runs, so your hook does not need to repeat that check; focus on your own rules.

Build a plugin with OnMlrsFire

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

Prompt: Permission-gated MLRS using the OnMlrsFire 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 OnMlrsFire

Generate