Skip to content
RustPluginGenerator

OnStructureRepair

OnStructureRepair is called when a player repairs a damageable structure with a hammer, before the repair is applied. Returning a non-null value cancels the repair entirely.

Signature
object OnStructureRepair(BaseCombatEntity entity, BasePlayer player)

Parameters

Hook parameters
ParameterTypeDescription
entityBaseCombatEntityThe BaseCombatEntity being repaired (typically a BuildingBlock or another damageable deployable). Declare a narrower type such as BuildingBlock if you only care about building pieces.
playerBasePlayerThe BasePlayer performing the repair with a hammer. Can be null in edge cases, so always null-check it.

Return value

Return null to let the repair proceed normally. Returning any non-null value (a true boolean is the usual choice) stops the original code path, so no health is restored and no resources are consumed.

How it works

The hook fires inside BaseCombatEntity.DoRepair, which runs when a player uses a repair tool (hammer) on a damaged building block or other repair-enabled entity. It runs before the game checks repair cooldowns, creative-mode free repair, and resource consumption, so cancelling it here prevents the repair from happening at all.

Use entity to inspect what is being repaired: its type, current health, owner, grade, or attached cupboard. Use player to check permissions, team membership, building authorization or to send feedback. Because DoRepair exists on BaseCombatEntity, the hook can fire for entities beyond building blocks; declare BaseCombatEntity to catch everything or narrow to BuildingBlock to skip non-structure repairs.

Oxide dispatches the call only when the argument matches your declared parameter types, so a BuildingBlock parameter means repairs of other entity types are ignored. Keep the method cheap: it can fire multiple times per second during a long repair session.

Example plugin: Permission-gated building repair with cooldown

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

namespace Oxide.Plugins
{
    [Info("Repair Permission Gate", "RustPluginGenerator", "1.0.0")]
    [Description("Requires a permission before players can repair building blocks with a hammer")]
    public class RepairPermissionGate : RustPlugin
    {
        private const string PermUse = "repairpermissiongate.use";

        private PluginConfig config;

        private class PluginConfig
        {
            [JsonProperty("Require permission to repair")]
            public bool RequirePermission { get; set; } = 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>
            {
                ["NoPermission"] = "You do not have permission to repair structures.",
                ["Disabled"] = "Structure repair is currently disabled."
            }, this);
        }

        private string Msg(string key, string userId = null) => lang.GetMessage(key, this, userId);

        private void Init()
        {
            permission.RegisterPermission(PermUse, this);
        }

        private object OnStructureRepair(BaseCombatEntity entity, BasePlayer player)
        {
            if (!config.RequirePermission) return null;
            if (entity == null || player == null) return null;
            if (entity is BuildingBlock == false) return null;
            if (player.IsAdmin) return null;
            if (permission.UserHasPermission(player.UserIDString, PermUse)) return null;

            player.ChatMessage(Msg("NoPermission", player.UserIDString));
            return true;
        }
    }
}

The plugin requires the repairpermissiongate.use permission before a player can repair a building block. When a player without the permission starts repairing, OnStructureRepair sends a localized warning and returns true, which blocks the repair at the earliest point in DoRepair. Players with the permission (or admins) are let through with a null return. Config holds the permission toggle so admins can enable open repair without editing code. The method narrows entity to BuildingBlock, so repairs of other base entities are untouched, and every parameter is null-checked before use.

Common use cases

  • Restrict repairs to base owners

    Check the entity's owner or building privilege and cancel repair for players who are not authorized on the base.

  • Raiding balance

    Block or delay structure repair during an active raid window by returning a non-null value and notifying the player.

  • Discord or log auditing

    Track who repairs which structures and how often by recording the event in data files before returning null.

Pitfalls

  • Return value cancels the whole repair

    Any non-null return stops DoRepair before health is restored, so returning false by mistake still blocks the repair. Return null to allow it.

  • Fires on non-building entities

    The hook is injected into BaseCombatEntity.DoRepair, so repair-enabled deployables can trigger it too. Narrow the parameter type or check as BuildingBlock if you only want walls and foundations.

  • High call frequency

    A player hammering a wall can trigger this repeatedly. Avoid logging or chat spam inside the hook and cache permission results where reasonable.

Build a plugin with OnStructureRepair

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

Prompt: Restrict repairs to base owners using the OnStructureRepair 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 OnStructureRepair

Generate