Skip to content
RustPluginGenerator

OnOvenToggle

OnOvenToggle is called when a player sends the switch RPC to a BaseOven (or its subclasses like furnaces, campfires, and refineries) to turn it on or off. Returning a non-null value cancels the switch before the game checks lock permissions.

Signature
object OnOvenToggle(BaseOven oven, BasePlayer player)

Parameters

Hook parameters
ParameterTypeDescription
ovenBaseOvenThe BaseOven entity being switched. Cast to a more specific type such as BaseOven or a custom oven subclass when you need its inventory or position.
playerBasePlayerThe BasePlayer who triggered the switch via the RPC. Can be null in edge cases, so null-check before using it.

Return value

Return null to let the normal toggle proceed (subject to flag == IsOn() and lock permissions). Return any non-null object to cancel the switch entirely, meaning the oven will not change state and the game will not run its lock permission check or fire the toggle effect.

How it works

The hook fires inside BaseOven.SVSwitch, which runs server-side when the client sends the toggle bit. The original code reads the desired state from the RPC, then bails out if your hook returns non-null or if the requested state already matches the current state. Only after that does the game check lock permissions and actually flip the oven on or off.

oven is the entity being toggled. You can declare it as BaseOven (the default) or, if you want to target only one kind, a subclass the game actually uses. The RPC handler is on BaseOven, so the argument will always be a BaseOven or subclass; declaring BaseOven is fine.

player is the player sending the RPC. It can be null if the RPC arrives without a valid connection, so null-check before reading UserIDString or sending chat.

The return value is a cancellation flag: any non-null object stops the switch. Because the check happens before the lock permission test, blocking here also blocks the game's own lock denial message and effect, which is useful when you want to enforce your own toggle rules (permissions, cooldowns, proximity).

Example plugin: Restrict furnace control to the entity owner and their building authers

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

namespace Oxide.Plugins
{
    [Info("Oven Owner Only", "RustPluginGenerator", "1.0.0")]
    [Description("Restricts who can toggle furnaces and campfires to the owner and building authers.")]
    public class OvenOwnerOnly : RustPlugin
    {
        private const string PermBypass = "ovenowneronly.bypass";

        private PluginConfig config;

        private class PluginConfig
        {
            [JsonProperty("Restrict toggles to owners and authers")]
            public bool RestrictToOwners = 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>
            {
                ["NotAllowed"] = "Only the owner or an authorized builder can switch this {0}."
            }, 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 OnOvenToggle(BaseOven oven, BasePlayer player)
        {
            if (oven == null) return null;
            if (!config.RestrictToOwners) return null;
            if (player == null || player.userID == 0u) return null;
            if (player.IsAdmin) return null;
            if (permission.UserHasPermission(player.UserIDString, PermBypass)) return null;

            if (oven.OwnerID == player.userID.Get()) return null;

            BuildingPrivlidge privilege = oven.GetBuildingPrivilege();
            if (privilege != null && privilege.IsAuthed(player)) return null;

            string name = oven.ShortPrefabName?.Replace(".deployed", "") ?? "oven";
            player.ChatMessage(Msg("NotAllowed", player.UserIDString, name));
            return true; // cancel the switch
        }
    }
}

The plugin stores a config toggle and registers a permission. OnOvenToggle runs every time any player toggles a furnace or campfire. If the feature is enabled and the player lacks the bypass permission, the plugin checks oven.OwnerID against the player's user id and against authers of the building privilege the oven is inside. If neither matches, it sends a localized message and returns true to cancel the toggle. Null checks guard against a missing player or a null GetBuildingPrivilege(). All player-facing text goes through the language file, and no logging happens inside the hook because it fires on every toggle.

Common use cases

  • Owner-only furnace control

    Block players who are not the entity owner or a building auther from turning furnaces on or off, stopping griefing on shared bases.

  • Toggle cooldowns

    Reject rapid on/off toggling to reduce RPC spam or prevent players from gaming a custom furnace plugin that reacts to every state change.

  • Permission-gated ovens

    Require a specific permission before a player can light a campfire or refinery, and send a clear message when they lack it.

Pitfalls

  • Runs before the lock check

    Because the hook returns before GetLock() is called, blocking here also suppresses the game's own lock permission message. If you need consistent feedback, send your own chat reply before returning.

  • Player can be null

    The RPC's player field can be null in malformed or internal cases. Always null-check player before reading UserIDString or calling ChatMessage.

  • Same hook for on and off

    OnOvenToggle fires for both directions. If you only want to restrict lighting, check oven.IsOn() to see whether it is currently burning before deciding to cancel.

Build a plugin with OnOvenToggle

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

Prompt: Owner-only furnace control using the OnOvenToggle 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 OnOvenToggle

Generate