CanExplosiveStick
CanExplosiveStick is called when a TimedExplosive checks whether it may attach to a target entity. Returning a bool overrides the game's normal stick decision for that explosive.
object CanExplosiveStick(TimedExplosive timedExplosive, BaseEntity entity)Parameters
| Parameter | Type | Description |
|---|---|---|
timedExplosive | TimedExplosive | The TimedExplosive entity that is deciding whether it can attach to a surface (C4, satchel charge, rocket entity and similar). Null-check it before reading any member. |
entity | BaseEntity | The BaseEntity the explosive is trying to stick to. May be a building block, a deployable, a vehicle or another entity; it is passed straight from CanStickTo and can be null when the game checks with no target. |
Return value
Return a bool to replace the game's result: true forces the explosive to stick to the target, false forbids sticking. Return null (or nothing) to let the vanilla logic continue, which checks things like DecorDeployable components and other built-in rules.
How it works
The hook fires inside TimedExplosive.CanStickTo(BaseEntity entity), which the game runs for each candidate surface when a thrown or placed timed explosive is deciding whether to attach. That covers C4 and satchel-style explosives that are thrown at a wall, roof or vehicle. The first parameter is the explosive itself, so you can read its prefab name or short prefab name to tell charge types apart; the second is the entity being tested as a sticking surface.
Because the injected call runs before the vanilla checks, the hook is a clean place to apply server rules: forbid sticking to certain building grades, block vehicle attachment, or allow sticking in places the game would otherwise reject. Oxide only calls your method if every argument matches your declared parameter types, so declaring a narrower second parameter (for example BuildingBlock) makes Oxide skip the call for entities that are not building blocks.
Keep the method cheap: it can run several times per thrown explosive as it collides with different colliders.
Example plugin: Prevent explosives from sticking to twig and wood builds
using System.Collections.Generic;
using System;
using Newtonsoft.Json;
using Oxide.Core;
namespace Oxide.Plugins
{
[Info("No Stick On Weak Buildings", "RustPluginGenerator", "1.0.0")]
[Description("Prevents timed explosives such as C4 from sticking to twig and wood building blocks")]
public class NoStickOnWeakBuildings : RustPlugin
{
private const string PermUse = "nostickonweakbuildings.enabled";
private PluginConfig config;
private class PluginConfig
{
[JsonProperty("Prevent sticking to twig")]
public bool BlockTwigs { get; set; } = true;
[JsonProperty("Prevent sticking to wood")]
public bool BlockWood { get; set; } = true;
[JsonProperty("Prevent sticking to stone")]
public bool BlockStone { get; set; } = 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>
{
["Toggled.On"] = "Explosive sticking restrictions are now enabled.",
["Toggled.Off"] = "Explosive sticking restrictions are now disabled.",
["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);
}
private object CanExplosiveStick(TimedExplosive timedExplosive, BaseEntity entity)
{
if (timedExplosive == null || entity == null) return null;
var block = entity as BuildingBlock;
if (block == null) return null;
switch (block.grade)
{
case BuildingGrade.Enum.Twigs:
return config.BlockTwigs ? (object)false : null;
case BuildingGrade.Enum.Wood:
return config.BlockWood ? (object)false : null;
case BuildingGrade.Enum.Stone:
return config.BlockStone ? (object)false : null;
default:
return null;
}
}
[ChatCommand("nostick")]
private void CmdNoStick(BasePlayer player, string command, string[] args)
{
if (player == null) return;
if (!player.IsAdmin && !permission.UserHasPermission(player.UserIDString, PermUse))
{
player.ChatMessage(Msg("NoPermission", player.UserIDString));
return;
}
bool nowBlocked = !config.BlockTwigs;
config.BlockTwigs = nowBlocked;
config.BlockWood = nowBlocked;
SaveConfig();
player.ChatMessage(Msg(nowBlocked ? "Toggled.On" : "Toggled.Off", player.UserIDString));
}
}
}The plugin registers nostickonweakbuildings.enabled and lets admins toggle it with /nostick. CanExplosiveStick checks the config flag first, then looks at whether the target entity is a BuildingBlock whose grade is Twigs or Wood. If it is, the hook returns false, so the timed explosive cannot attach and instead falls and detonates normally. Returning null for every other entity keeps vanilla behavior, including sticking to stone, metal, vehicles and deployables. The toggle command replies to the player through the language file.
Common use cases
Protect starter bases
Block C4 and satchels from sticking to twig or wood building blocks so raids on early-game bases require more effort or different tools.
Vehicle raid rules
Return
falsewhen the target is a ModularCar, MiniCopter or other vehicle type, forcing players to disable or destroy the vehicle rather than planting charges directly on it.Event-only sticking zones
Combine with a position or zone check on the explosive's transform to allow sticking only inside a designated raid zone while refusing it everywhere else.
Pitfalls
Only affects timed explosives
The hook is injected into
TimedExplosive.CanStickTo, so rockets and other projectiles that do not use that method are unaffected. Do not promise rocket-stick control from this hook.Narrow types skip calls
Declaring
BuildingBlockas the second parameter means Oxide never invokes your method for vehicles, deployables or other entity types. DeclareBaseEntityand type-check inside if you need all targets.Fires repeatedly per throw
The method can be evaluated against multiple colliders as the explosive moves, so avoid heavy work or
PrintWarningcalls in the hook body.
Build a plugin with CanExplosiveStick
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 CanExplosiveStick
Generate