OnWireClear
OnWireClear is called when a player uses the Wire Tool to remove an existing electrical wire connection between two IOEntities, before the connection is actually broken.
object OnWireClear(BasePlayer ply, IOEntity iOEntity, int clearIndex, IOEntity iOEntity2, bool isInput)Parameters
| Parameter | Type | Description |
|---|---|---|
ply | BasePlayer | The player using the Wire Tool who is clearing the wire; may be null for non-player callers, so null-check it. |
iOEntity | IOEntity | The output IOEntity the wire is being cleared from (the source side of the connection). |
clearIndex | int | The slot index on the entity being cleared, matching the input or output slot depending on isInput. |
iOEntity2 | IOEntity | The IOEntity at the other end of the wire (the connected target). |
isInput | bool | True when the player is clearing the input side of the connection, false when clearing the output side. |
Return value
Returning null lets the wire clear proceed normally. Returning a bool overrides the result of WireTool.AttemptClearSlot: true allows the wire to be cleared (and stops the original code path), false blocks the removal and keeps the connection intact.
How it works
This hook fires inside WireTool.AttemptClearSlot, when a player right-clicks with the Wire Tool to detach a wire from a slot. The game resolves the currently connected entity first; if there is a live connection, Oxide calls OnWireClear with both endpoints. ply is the acting player, iOEntity is the entity whose slot is being cleared, clearIndex is that slot index, iOEntity2 is the entity on the other end, and isInput tells you which side of the pair you are touching.
Use it to enforce wire ownership, count how many wires a player has removed, or block clearing connections that belong to another player's base. Because both entities are passed, you can inspect OwnerID or building privilege on either end. Declaring ply as BasePlayer is already specific; the entity parameters are IOEntity, so narrowing them further (e.g. to a subtype) would make Oxide skip calls where the entity is a different type. Keep the body cheap, as it runs on every wire removal, and do not call Puts/PrintWarning here.
Example plugin: Block clearing wires on authorized bases
using System.Collections.Generic;
using System;
using Newtonsoft.Json;
using Oxide.Core;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Wire Clear Guard", "RustPluginGenerator", "1.0.0")]
[Description("Blocks players from clearing electrical wires on bases they are not authorized on")]
public class WireClearGuard : RustPlugin
{
private const string PermBypass = "wireclearguard.bypass";
private PluginConfig config;
private class PluginConfig
{
[JsonProperty("Protect authorized bases only")]
public bool ProtectAuthorizedBases = 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>
{
["NotAuthorized"] = "You are not authorized to clear wires on this structure."
}, this);
}
private string Msg(string key, string userId = null, params object[] args)
{
return string.Format(lang.GetMessage(key, this, userId), args);
}
private void Init()
{
permission.RegisterPermission(PermBypass, this);
}
private object OnWireClear(BasePlayer player, IOEntity sourceEntity, int clearIndex, IOEntity targetEntity, bool isInput)
{
if (!config.ProtectAuthorizedBases) return null;
if (player == null) return null;
var privilege = targetEntity != null ? targetEntity.GetBuildingPrivilege() : null;
if (privilege == null && sourceEntity != null)
privilege = sourceEntity.GetBuildingPrivilege();
if (privilege == null) return null;
if (privilege.IsAuthed(player)) return null;
if (permission.UserHasPermission(player.UserIDString, PermBypass)) return null;
player.ChatMessage(Msg("NotAuthorized", player.UserIDString));
return false;
}
}
}The plugin guards wire removal on built structures. When OnWireClear fires, it checks the config flag and whether the acting player is null. It then looks up building privilege on the target entity via GetBuildingPrivilege(); if the privilege exists and the player is not authorized on it, the hook returns false, which keeps the wire connected and sends a chat warning through localized messages. Unauthorized removals are also counted. Players with the bypass permission are exempt, so admins can still rewire. Everything runs from a single hook with no timers or stored state beyond the config.
Common use cases
Protect base wiring
Block players who are not authorized on a structure's cupboard from detaching wires, so raiders cannot quietly rewire doors, turrets or traps.
Audit wire changes
Count or record removals per player to spot suspicious activity such as mass wire clearing before a raid.
Minimum wire age
Track when connections were made with OnWireConnect and refuse clearing (return false) until a configurable delay has passed, reducing accidental disconnects.
Pitfalls
Return value controls the clear
Returning a non-null bool replaces the game's result entirely. Returning
trueclears the wire,falseblocks it; returning null (or anything else) falls through to the default behavior.Entity can be null after resolution
The hook is called before the code checks whether
iOEntityis null, so always null-check the entity parameters and any nested members you access.Fires often on active servers
Wire tool edits happen constantly on electrical builds. Keep the body lightweight and never call Puts or PrintWarning inside the hook.
Build a plugin with OnWireClear
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 OnWireClear
Generate