Skip to content
RustPluginGenerator

OnQuarryGather

OnQuarryGather is called each time a MiningQuarry produces a resource item during MiningQuarry.ProcessResources, right after the item is created and before it is placed into the hopper storage container.

Signature
object OnQuarryGather(MiningQuarry miningQuarry, Item item)

Parameters

Hook parameters
ParameterTypeDescription
miningQuarryMiningQuarryThe MiningQuarry instance that just produced the resource item. Use it to read the quarry's position, owner, hopper storage or connected fuel container when deciding what to do with the item.
itemItemThe freshly created resource Item (for example sulfur.ore or stones) before it is moved into the quarry's hopper. Read info.shortname and amount, or remove it to cancel the deposit.

Return value

Returning a non-null value (any object) makes the game discard the produced item by calling item.Remove() instead of moving it into the hopper, so no resource is deposited. Returning null keeps normal behavior and the item is moved into the hopper storage container.

How it works

The hook fires inside MiningQuarry.ProcessResources, which the quarry runs on its production cycle while it is powered and has resources to process. At the injection point the game has already rolled the resource type and amount (including any softcore gather multiplier) and created the Item, but it has not yet moved it into the hopper's StorageContainer.inventory. That makes this the correct place to inspect or block a single produced unit of ore.

miningQuarry lets you identify the source: you can check its position, owner, or cached prefab when you want different behavior per quarry. item gives you info.shortname, info.itemid, amount and skin, so you can reward bonus output, filter unwanted resources, or log production. Because the parameter types are concrete (MiningQuarry, Item), Oxide only calls your method when the arguments match those types.

The hook fires frequently on active quarries, so keep the body cheap: no chat spam or disk writes per call. Combine production changes with OnQuarryToggle or OnQuarryToggled if you also need to react to power state.

Example plugin: Bonus ore from quarries with a permission multiplier

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

namespace Oxide.Plugins
{
    [Info("Quarry Bonus Ore", "RustPluginGenerator", "1.0.0")]
    [Description("Gives quarry owners with permission a configurable chance for extra ore output")]
    public class QuarryBonusOre : RustPlugin
    {
        private const string PermBonus = "quarrybonusore.bonus";

        private PluginConfig config;

        private class PluginConfig
        {
            [JsonProperty("Bonus chance (0-1)")]
            public float BonusChance = 0.25f;

            [JsonProperty("Bonus multiplier of produced amount")]
            public float BonusMultiplier = 1.0f;

            [JsonProperty("Maximum bonus items per gather")]
            public int MaxBonusPerGather = 50;

            [JsonProperty("Drop at quarry if owner is far away")]
            public bool DropWhenOwnerAway = 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);

        private void Init()
        {
            permission.RegisterPermission(PermBonus, this);
        }

        protected override void LoadDefaultMessages()
        {
            lang.RegisterMessages(new Dictionary<string, string>
            {
                ["Bonus"] = "Your quarry produced a bonus of {0} x {1}."
            }, this);
        }

        private string Msg(string key, string userId = null, params object[] args) =>
            string.Format(lang.GetMessage(key, this, userId), args);

        private object OnQuarryGather(MiningQuarry miningQuarry, Item item)
        {
            if (miningQuarry == null || item == null || item.info == null) return null;
            if (config.BonusChance <= 0f || config.BonusMultiplier <= 0f) return null;

            ulong ownerId = miningQuarry.OwnerID;
            if (ownerId == 0UL) return null;
            if (!permission.UserHasPermission(ownerId.ToString(), PermBonus)) return null;
            if (UnityEngine.Random.Range(0f, 1f) > config.BonusChance) return null;

            int bonus = Mathf.Clamp(Mathf.RoundToInt(item.amount * config.BonusMultiplier), 1, config.MaxBonusPerGather);
            Item extra = ItemManager.CreateByName(item.info.shortname, bonus, item.skin);
            if (extra == null) return null;

            BasePlayer owner = BasePlayer.FindByID(ownerId);
            if (owner != null && owner.IsConnected && !owner.IsDead() &&
                Vector3.Distance(owner.transform.position, miningQuarry.transform.position) <= 50f)
            {
                if (!owner.inventory.GiveItem(extra))
                {
                    extra.Drop(miningQuarry.transform.position + Vector3.up, Vector3.zero);
                }
                owner.ChatMessage(Msg("Bonus", owner.UserIDString, bonus, item.info.displayName.english));
            }
            else if (config.DropWhenOwnerAway)
            {
                extra.Drop(miningQuarry.transform.position + Vector3.up * 1.5f, Vector3.zero);
            }
            else
            {
                extra.Remove();
            }

            return null;
        }
    }
}

The plugin keeps a MiningQuarry hook that returns null in every path so the original item always deposits normally. When a quarry produces an ore stack, it checks the quarry owner's permission for a bonus multiplier and, if the configured chance succeeds, creates extra items of the same shortname with ItemManager.CreateByName and gives them to the owner if they are nearby, otherwise it drops them at the quarry hopper. Extra amounts are capped and the chance is read from config, so active quarries never generate unbounded output. The OnQuarryToggle hook is used only to log nothing; all player-facing feedback is optional through lang messages sent to the owner when they are online.

Common use cases

  • Boost output for VIP quarry owners

    Read miningQuarry.OwnerID, check a permission on that user and spawn additional items of the same shortname into the hopper or the owner's inventory.

  • Block specific resources from quarries

    Return a non-null value when item.info.shortname matches a blacklisted resource, so the item is removed and nothing reaches the hopper.

  • Track server production economy

    Accumulate counts of shortname and amount per quarry owner in memory and flush the totals to a data file on a timer or on server save.

Pitfalls

  • Any non-null return cancels the deposit

    The hook only distinguishes null from non-null, so returning true, false or a string all remove the item. Always return null when production should continue.

  • Do not remove the item yourself and then return null

    The game calls item.MoveToContainer afterwards, and an already removed item cannot be moved. Cancel through the return value instead of calling item.Remove().

  • The hook is hot on busy servers

    A powered quarry fires this on every production tick. Avoid printing to console, writing data files, or iterating all players inside the hook; batch that work on a timer.

Plugin recipes that use OnQuarryGather

Build a plugin with OnQuarryGather

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

Prompt: Boost output for VIP quarry owners using the OnQuarryGather 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 OnQuarryGather

Generate