OnQuarryToggled
OnQuarryToggled is called after a player starts or stops a MiningQuarry engine through its engine switch, once the engine state has already changed.
void OnQuarryToggled(MiningQuarry miningQuarry, BasePlayer player)Parameters
| Parameter | Type | Description |
|---|---|---|
miningQuarry | MiningQuarry | The MiningQuarry (or its child engine switch parent) whose engine was just started or stopped. Use it to read position, OwnerID, fuel state or to send a network update. |
player | BasePlayer | The BasePlayer who used the engine switch. May be null in edge cases, so null-check before reading UserIDString or sending chat. |
Return value
The return value is ignored at both injection sites, so returning null or any other value changes nothing. The engine switch has already happened before the hook fires; to block a toggle you must use OnQuarryToggle, which runs first and can cancel it.
How it works
The hook fires from EngineSwitch.StartEngine and EngineSwitch.StopEngine. When a player presses a quarry's engine switch, the game resolves the parent entity as a MiningQuarry, calls the earlier OnQuarryToggle hook, and โ if that hook returned null โ flips the engine state with miningQuarry.EngineSwitch(isOn). Immediately after that state change, OnQuarryToggled is called with the quarry and the interacting player.
Use it to react to the new state: read whether the engine is now on, bill the player, log usage, notify a team, or start a monitoring timer. Because the engine has already been switched when the hook runs, the quarry's current state reflects the new value โ there is no separate boolean parameter, so inspect the quarry (fuel, IsOn() on related components, or a flag you track in OnQuarryToggle) if you need to tell start from stop.
Both parameters are typed by the game: MiningQuarry and BasePlayer. Declaring miningQuarry as a broader type such as BaseEntity still matches, but a narrower or unrelated type makes Oxide skip the call. The return value is ignored here.
Example plugin: Notify owners and log quarry engine toggles
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("QuarryToggleNotifier", "RustPluginGenerator", "1.0.0")]
[Description("Notifies players and quarry owners when a mining quarry engine is toggled.")]
public class QuarryToggleNotifier : RustPlugin
{
private const string PermNotify = "quarrytogglenotifier.notify";
private PluginConfig config;
private readonly Dictionary<ulong, float> lastToggle = new Dictionary<ulong, float>();
private class PluginConfig
{
[JsonProperty("Notify owner")]
public bool NotifyOwner { get; set; } = true;
[JsonProperty("Cooldown seconds per quarry")]
public float CooldownSeconds { get; set; } = 5f;
}
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>
{
["Toggled"] = "You toggled the engine of the quarry at {0}.",
["OwnerAlert"] = "{0} toggled your quarry engine at {1}."
}, 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(PermNotify, this);
}
private void OnQuarryToggled(MiningQuarry miningQuarry, BasePlayer player)
{
if (miningQuarry == null || player == null || player.IsNpc) return;
ulong quarryId = miningQuarry.net != null ? miningQuarry.net.ID.Value : 0UL;
float now = UnityEngine.Time.realtimeSinceStartup;
float last;
if (quarryId != 0UL && lastToggle.TryGetValue(quarryId, out last) &&
now - last < config.CooldownSeconds) return;
if (quarryId != 0UL) lastToggle[quarryId] = now;
Vector3 pos = miningQuarry.transform.position;
string location = $"({Mathf.RoundToInt(pos.x)}, {Mathf.RoundToInt(pos.z)})";
player.ChatMessage(Msg("Toggled", player.UserIDString, location));
ulong ownerId = miningQuarry.OwnerID;
if (!config.NotifyOwner || ownerId == 0UL || ownerId == player.userID.Get()) return;
BasePlayer owner = BasePlayer.FindByID(ownerId);
if (owner == null || !owner.IsConnected) return;
if (!permission.UserHasPermission(owner.UserIDString, PermNotify)) return;
owner.ChatMessage(Msg("OwnerAlert", owner.UserIDString, player.displayName, location));
}
private void Unload()
{
lastToggle.Clear();
}
}
}The plugin listens to OnQuarryToggled and, when the engine state changes, sends a chat message to the interacting player confirming the action. It also reports the event to the quarry owner if that player is online and different from the user, and records a short line to the server console. A nested config lets an admin turn owner notifications on or off and set the cooldown so a player spamming the switch does not flood chat. Cooldowns are tracked in a dictionary keyed by quarry network ID and pruned during Unload. All player-facing text goes through the language file so it can be localized.
Common use cases
Charge a fee to start a quarry
In
OnQuarryToggle, pre-check the player's balance via an economy plugin and return a non-null value to cancel the start when they cannot pay, then deduct inOnQuarryToggledonce the engine is running.Alert the quarry owner
When a stranger flips the switch, message the owner (if connected) with who toggled their quarry and where it is, so they can respond.
Track engine runtime
Record start and stop events in oxide/data timestamped per quarry to build uptime statistics or to detect quarries left running overnight.
Pitfalls
The state has already changed
By the time
OnQuarryToggledruns,EngineSwitch(isOn)has executed. If you need to inspect the previous state or veto the change, useOnQuarryToggleinstead, which fires before the switch.No explicit on/off argument
The hook signature does not tell you whether the engine started or stopped. Read the quarry's current state or cache the value you saw in
OnQuarryToggleif your feature depends on direction.Player can be null
Always null-check the
playerparameter before readingUserIDStringor callingChatMessage; a missing reference otherwise throws and breaks the toggle path.
Build a plugin with OnQuarryToggled
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 OnQuarryToggled
Generate