CanUseFuel
CanUseFuel is called from EntityFuelSystem.TryUseFuel whenever a fuel-driven entity attempts to consume fuel for an update tick. Return an int to override the amount of fuel taken.
object CanUseFuel(EntityFuelSystem entityFuelSystem, StorageContainer fuelContainer, float seconds, float fuelUsedPerSecond)Parameters
| Parameter | Type | Description |
|---|---|---|
entityFuelSystem | EntityFuelSystem | The EntityFuelSystem instance that is trying to consume fuel, typically owned by a vehicle, generator, furnace or other fuel-driven entity. Use its owner to identify what is burning fuel. |
fuelContainer | StorageContainer | The StorageContainer holding the fuel items, returned by the system's GetFuelContainer. It can be null when the entity has no fuel container assigned. |
seconds | float | How many seconds of burn time the system wants to consume in this update call. |
fuelUsedPerSecond | float | The fuel units consumed per second for this system, as configured by the entity. Divide total fuel by this to estimate remaining burn time. |
Return value
Returning null lets the normal fuel consumption proceed. Returning an int replaces the value the game would otherwise produce for this call, letting you control how much fuel is consumed.
How it works
The hook fires inside EntityFuelSystem.TryUseFuel, which is the method entities call to burn fuel over time. Every tick a powered entity (furnace, generator, vehicle, turret and similar) needs fuel, the game asks this hook before touching the fuel container. The arguments give you the system, its StorageContainer, the requested seconds of burn time and the fuelUsedPerSecond rate.
This is a per-tick hot path — it runs repeatedly for each active fuel entity — so keep the method cheap and never log inside it.
Because the object value can replace the game's return, the practical use is adjusting fuel consumption: return the effective number of fuel units the system should be treated as having consumed. That lets you make machines more efficient or burn fuel faster, or make a system refuse fuel by returning 0. Returning null leaves the vanilla consumption untouched. You cannot narrow this hook by parameter type; declare the exact signature.
Example plugin: Discount furnace and generator fuel use
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Fuel Efficiency", "RustPluginGenerator", "1.0.0")]
[Description("Applies a configurable fuel efficiency multiplier to appliances using the CanUseFuel hook.")]
public class FuelEfficiency : RustPlugin
{
private const string PermManage = "fuelefficiency.manage";
private PluginConfig config;
private class PluginConfig
{
[JsonProperty("Fuel efficiency multiplier (lower uses less fuel)")]
public float Efficiency { get; set; } = 0.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();
}
ClampEfficiency();
SaveConfig();
}
protected override void SaveConfig() => Config.WriteObject(config);
protected override void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>
{
["Usage"] = "Usage: /fuel [multiplier]",
["Set"] = "Fuel efficiency set to {0}.",
["Denied"] = "You do not have permission to change fuel efficiency."
}, 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(PermManage, this);
}
private object CanUseFuel(EntityFuelSystem entityFuelSystem, StorageContainer fuelContainer, float seconds, float fuelUsedPerSecond)
{
if (entityFuelSystem == null || fuelContainer == null) return null;
if (config.Efficiency >= 1f) return null;
int requested = Mathf.CeilToInt(seconds * fuelUsedPerSecond);
if (requested <= 0) return null;
int reduced = Mathf.CeilToInt(requested * config.Efficiency);
if (reduced < 0) reduced = 0;
return reduced;
}
[ChatCommand("fuel")]
private void CmdFuel(BasePlayer player, string command, string[] args)
{
if (player == null) return;
if (!permission.UserHasPermission(player.UserIDString, PermManage))
{
player.ChatMessage(Msg("Denied", player.UserIDString));
return;
}
if (args.Length != 1)
{
player.ChatMessage(Msg("Usage", player.UserIDString));
return;
}
if (!float.TryParse(args[0], out float value))
{
player.ChatMessage(Msg("Usage", player.UserIDString));
return;
}
config.Efficiency = Mathf.Clamp(value, 0.05f, 5f);
SaveConfig();
player.ChatMessage(Msg("Set", player.UserIDString, config.Efficiency));
}
private void ClampEfficiency()
{
config.Efficiency = Mathf.Clamp(config.Efficiency, 0.05f, 5f);
}
}
}The plugin reads a configurable efficiency multiplier and applies it inside CanUseFuel. It null-checks the fuel container and system, then returns the reduced integer fuel amount so appliances burn less fuel per tick for the same run time. A chat command guarded by a permission lets admins change the multiplier at runtime, and the value is saved through config. Logging is avoided inside the hook since it fires every tick; only rare config warnings are printed.
Common use cases
Fuel efficiency multiplier
Reduce the fuel an appliance consumes each tick so servers can run furnaces and generators with longer burn times without editing entity prefabs.
Fast-burn event mode
Return a larger number than requested to drain fuel faster during an event, forcing players to keep toping up their machines.
Disable fuel entirely for selected entities
Return 0 for specific systems identified by their owner so certain appliances never consume fuel while remaining visually on.
Pitfalls
Null fuel container
GetFuelContainercan return null when the system has no container assigned. Always checkfuelContainerbefore reading items or the hook will throw on those ticks.Hot path, no logging
This fires on every consumed-fuel update for every appliance. Avoid
Puts, string formatting or allocations here; they cause lag on busy servers.Returning large values
Returning much more than
fuelUsedPerSecond * secondscan empty a container in one tick and skip expected effects. Test with realistic rates before shipping.
Build a plugin with CanUseFuel
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 CanUseFuel
Generate