Skip to content
RustPluginGenerator

OnOvenCook

OnOvenCook is called from BaseOven.Cook just before the oven decides whether to consume fuel and continue its cooking tick, letting a plugin cancel that tick by returning a non-null value.

Signature
object OnOvenCook(BaseOven oven, Item item)

Parameters

Hook parameters
ParameterTypeDescription
ovenBaseOvenThe BaseOven instance that is about to process a cook tick. This is the entity whose inventory is being checked and whose state flags apply.
itemItemThe Item returned by the oven's internal FindBurnable() call, i.e. the fuel/burnable item it is about to consume, or null when no burnable is present.

Return value

Returning null (or anything non-void that the plugin chooses to ignore by returning null) lets BaseOven.Cook proceed normally and consume fuel. Returning any non-null value aborts the rest of Cook, so the fuel item is not burned and no cooking progress happens this tick.

How it works

The hook fires inside BaseOven.Cook, which runs on the oven's internal cook timer. The game first bails out early if the oven has Flags.Reserved8 set, then looks up a burnable item with FindBurnable() and calls OnOvenCook(this, item). If the hook returns anything other than null, Cook returns immediately, so the burnable is not consumed and the cook step is skipped for this tick. The oven parameter is the oven entity itself (BaseOven subclasses such as BBQ, Furnace, Campfire and StoneOven all inherit from it), and item is the fuel item that would be burned, or null if the oven has no burnable contents. Declaring oven as a more specific type like BaseOven itself is already as general as it gets; narrowing to something like ElevatedOven would make Oxide skip calls for other oven types. Because this hook fires on every cook tick, keep the handler cheap: no chat output, no warnings, no data writes on the common path. Return null to let the game continue normally.

Example plugin: Pause ovens while the server plugin flag is on

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

namespace Oxide.Plugins
{
    [Info("Oven Cook Pause", "RustPluginGenerator", "1.0.0")]
    [Description("Allows admins to pause or resume cooking on all ovens via a chat command.")]
    public class OvenCookPause : RustPlugin
    {
        private const string PermUse = "ovencookpause.use";

        private PluginConfig config;
        private static bool paused;
        private int blockedTicks;

        private class PluginConfig
        {
            [JsonProperty("Blocked return value")]
            public bool BlockedReturnValue = true;

            [JsonProperty("Pause on plugin load")]
            public bool PauseOnLoad = 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>
            {
                ["Usage"] = "Usage: /ovenpause [on|off|status]",
                ["Paused"] = "Oven cooking is now paused.",
                ["Resumed"] = "Oven cooking has resumed.",
                ["PausedStatus"] = "Oven cooking is currently paused ({0} ticks blocked).",
                ["RunningStatus"] = "Oven cooking is currently running normally.",
                ["NoPermission"] = "You do not have permission to use this command."
            }, 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);
            paused = config.PauseOnLoad;
        }

        [ChatCommand("ovenpause")]
        private void CmdOvenPause(BasePlayer player, string command, string[] args)
        {
            if (player == null) return;
            if (!player.IsAdmin && !permission.UserHasPermission(player.UserIDString, PermUse))
            {
                SendReply(player, Msg("NoPermission", player.UserIDString));
                return;
            }

            string action = args.Length > 0 ? args[0].ToLowerInvariant() : "toggle";
            switch (action)
            {
                case "on":
                    paused = true;
                    break;
                case "off":
                    paused = false;
                    break;
                case "status":
                    SendReply(player, paused
                        ? Msg("PausedStatus", player.UserIDString, blockedTicks)
                        : Msg("RunningStatus", player.UserIDString));
                    return;
                case "toggle":
                    paused = !paused;
                    break;
                default:
                    SendReply(player, Msg("Usage", player.UserIDString));
                    return;
            }

            SendReply(player, paused ? Msg("Paused", player.UserIDString) : Msg("Resumed", player.UserIDString));
        }

        private object OnOvenCook(BaseOven oven, Item item)
        {
            if (!paused) return null;
            if (oven == null) return null;

            blockedTicks++;
            return config.BlockedReturnValue ? (object)true : null;
        }

        private void Unload()
        {
            paused = false;
        }
    }
}

OvenCookPause registers a chat command /ovenpause (admin only) that toggles a boolean flag stored in a static field. OnOvenCook checks the flag and, when paused, returns a non-null sentinel so BaseOven.Cook exits without consuming the burnable item, effectively freezing all cooking. When unpaused the handler returns null and cooking resumes. The example also tracks the number of ticks that were blocked, exposes it through /ovenstatus, and uses the language file for all chat output so the messages can be translated.

Common use cases

  • Server-wide cooking freeze

    Toggle a flag that makes every oven skip its tick, for example during scheduled maintenance or a wipe transition when admins want to stop resource consumption.

  • Selective fuel control per oven type

    Narrow the oven parameter to a specific BaseOven subtype (BBQ, Furnace) and return non-null for that type only, so only certain appliances are affected.

  • Regulated economy ovens

    When a player has no permission for a premium oven tier, return non-null so the oven will not burn fuel, and inform the player via a low-frequency check elsewhere.

Pitfalls

  • Runs every tick

    Cook is scheduled repeatedly for every lit oven. Do not log, send chat or write data files from this hook; just do a cheap boolean check and return.

  • Item may be null

    FindBurnable() returns null when the oven has no burnable item. Check item == null before reading item.info and similar members.

  • Non-null blocks the whole tick

    Any non-null return value aborts Cook entirely; it is not a way to swap in a different item. Fuel is not consumed and the oven does not progress while you keep returning non-null.

Plugin recipes that use OnOvenCook

Build a plugin with OnOvenCook

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

Prompt: Server-wide cooking freeze using the OnOvenCook 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 OnOvenCook

Generate