OnPlanterBoxFertilize
OnPlanterBoxFertilize is called when a PlanterBox is about to be fertilized, before it consumes fertilizer items and boosts the growth of the plants inside. Returning a non-null value cancels the fertilization entirely.
object OnPlanterBoxFertilize(PlanterBox planterBox)Parameters
| Parameter | Type | Description |
|---|---|---|
planterBox | PlanterBox | The PlanterBox entity whose fertilize routine is about to run (the box a player used fertilizer on). Use it to inspect position, owner, its growable slots or its inventory. |
Return value
Returning null lets FertilizeGrowables continue, so fertilizer is counted, consumed and growables advance. Returning any non-null value short-circuits the method immediately, so no fertilizer is spent and no growth change happens; the value itself is discarded because the original method returns void.
How it works
The hook fires at the top of PlanterBox.FertilizeGrowables, which is the server-side method that runs when a player applies fertilizer to a planter box. Because the injection is the first statement of that method, it runs before the game counts fertilizer in the box, before any fertilizer item is consumed and before growth stages of the contained growables are pushed forward. The single argument is the PlanterBox entity itself, so you can read its transform.position, its OwnerID, its inventory and the growable entities parented to it.
Declaring the parameter as PlanterBox is required for the hook to be dispatched; a broader type such as BaseEntity or StorageContainer still matches, but there is no reason to use one. Return null to let the vanilla fertilize routine continue, or return any non-null object to abort it, which leaves fertilizer untouched and growth unchanged. Since the method returns void, the returned value is only used as a cancel signal and is never passed back to the caller.
The hook fires once per fertilize action, not per growable, and only when the game actually reaches FertilizeGrowables (an empty fertilizer slot still triggers the call). It is safe to run checks here, but avoid expensive work on busy servers with many planter boxes.
Example plugin: Limit fertilizer use to authorized players
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Planter Fertilize Gate", "RustPluginGenerator", "1.0.0")]
[Description("Restricts fertilizing planter boxes to their owner, admins or a permission holder.")]
public class PlanterFertilizeGate : RustPlugin
{
private const string PermUse = "planterfertilizegate.use";
private PluginConfig config;
private class PluginConfig
{
[JsonProperty("Message cooldown (seconds)")]
public float MessageCooldown = 3f;
}
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>
{
["Denied"] = "You can only fertilize your own planter box, or ask an admin for access.",
["DeniedEmpty"] = "This planter box has no fertilizer in it."
}, 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);
}
private object OnPlanterBoxFertilize(PlanterBox planterBox)
{
if (planterBox == null) return null;
ulong ownerId = planterBox.OwnerID;
if (ownerId == 0) return null; // public box, nobody to gate
BasePlayer owner = BasePlayer.FindByID(ownerId);
if (owner != null && (owner.IsAdmin || permission.UserHasPermission(owner.UserIDString, PermUse)))
return null;
if (owner != null && owner.IsConnected && !owner.IsDead())
owner.ChatMessage(Msg("Denied", owner.UserIDString));
return false; // cancel fertilization
}
}
}The plugin registers a permission (planterfertilizegate.use) and blocks fertilization of planter boxes the caller does not own unless they hold it. In OnPlanterBoxFertilize it reads the box's OwnerID and compares it to the calling player's userID. Players without the permission who do not own the box get a localized chat warning and the hook returns a non-null value, which cancels fertilizer consumption. Admins are always allowed. Because the hook only knows the box, ownership is the cheapest reliable check; the permission allows server staff or trusted players to work on public farms.
Common use cases
Restrict fertilizer to the box owner
Compare
planterBox.OwnerIDwith the acting player's ID and cancel the hook to stop strangers from draining fertilizer on shared farms.Charge a plugin currency per fertilize
Call into an economy plugin on the hook and return non-null when the player cannot afford the fee, so growth only happens after payment.
Pause growth during server events
Set a plugin flag while a raid or event is active and cancel fertilization during that window to keep crops from maturing at the wrong time.
Pitfalls
Finding the acting player
The hook only gives you the planter box. Look up the caller via the box's
OwnerIDor track it withOnPlayerInput/ use hooks, because no player is passed in.Cancelling blocks all fertilizer
Because the injection is the first line of
FertilizeGrowables, returning a value prevents the game from consuming any fertilizer, not just some of it.Hook fires even with none in the box
The check runs before
GetFertilizerCount, so your logic executes when a player tries to fertilize an empty box too; guard accordingly.
Build a plugin with OnPlanterBoxFertilize
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 OnPlanterBoxFertilize
Generate