Repairable
Based on game build 714014 | Last updated: 2026-03-03
Overview
The Repairable component enables an entity to be repaired by compatible repair items (via the repairer component). It tracks repair eligibility via boolean flags and adds/removes corresponding tags (healthrepairable, workrepairable, finiteusesrepairable, repairable_<material>). It also provides logic to detect if repairs are needed and execute repairs using compatible items.
Usage example
local inst = CreateEntity()
inst:AddComponent("repairable")
inst.components.repairable:SetHealthRepairable(true)
inst.components.repairable:SetWorkRepairable(false)
inst.components.repairable:SetFiniteUsesRepairable(true)
inst.components.repairable.repairmaterial = "metal"
Dependencies & tags
Components used: health, workable, perishable, finiteuses, repairer, stackable
Tags: Adds/removes dynamically:
healthrepairable,workrepairable,finiteusesrepairablerepairable_<material>(where<material>is the currentrepairmaterialvalue)
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
repairmaterial | string? | nil | Repair material type required (e.g., "metal"). Controls the repairable_<material> tag. |
healthrepairable | boolean? | nil | Whether the entity can be repaired by increasing health. Controls the healthrepairable tag. |
workrepairable | boolean? | nil | Whether the entity can be repaired by restoring work points (e.g., durability). Controls the workrepairable tag. |
finiteusesrepairable | boolean? | nil | Whether the entity can be repaired by restoring finite uses. Controls the finiteusesrepairable tag. |
noannounce | boolean? | nil | If set, suppresses repair announcements (not used in this file, but part of the data model). |
checkmaterialfn | function? | nil | Optional custom function (entity, repair_item) -> success, reason to validate repair compatibility. |
testvalidrepairfn | function? | nil | Optional early-rejection function (entity, repair_item) -> boolean. |
justrunonrepaired | boolean? | nil | If true, allows Repair() to succeed even if no actual repair was applied. |
Main functions
SetHealthRepairable(repairable)
- Description: Enables or disables health-based repairability and updates the
healthrepairabletag accordingly. - Parameters:
repairable(boolean) — whether the entity should be considered health-repairable. - Returns: Nothing.
SetWorkRepairable(repairable)
- Description: Enables or disables work-point-based repairability and updates the
workrepairabletag accordingly. - Parameters:
repairable(boolean) — whether the entity should be considered work-repairable. - Returns: Nothing.
SetFiniteUsesRepairable(repairable)
- Description: Enables or disables finite-uses-based repairability and updates the
finiteusesrepairabletag accordingly. - Parameters:
repairable(boolean) — whether the entity should be considered finite-uses-repairable. - Returns: Nothing.
NeedsRepairs()
- Description: Determines if the entity requires repairs by checking its current state against a threshold (95% full). Checks health first, then workable, then perishable, then finiteuses.
- Parameters: None.
- Returns:
trueif any repairable aspect is below the threshold;falseotherwise.
Repair(doer, repair_item)
- Description: Attempts to repair the entity using the given repair item. Validates material compatibility and repair function, then applies repairs incrementally across health, work, perish, and uses.
- Parameters:
doer(entity) — the entity performing the repair.repair_item(entity) — the item being used to repair (must haverepairercomponent).
- Returns:
trueif the repair succeeded (including whenjustrunonrepairedistrueand no actual change occurred).falseif the repair failed due to incompatibility or full state.false, reason(string) ifcheckmaterialfnfails and returns a reason.
- Error states:
- Returns
falseifrepair_itemlacks arepairercomponent. - Returns
falseifrepairmaterialmismatches. - Returns
falseiftestvalidrepairfn(if present) rejects the repair. - Returns
falseifcheckmaterialfn(if present) returnsfalse(optionally with a reason). - Returns
falseif the target is already at full capacity for the applicable property.
- Returns
OnRemoveFromEntity()
- Description: Cleans up all repair-related tags when the component is removed from an entity.
- Parameters: None.
- Returns: Nothing.
Events & listeners
- Listens to: None — the constructor (implicitly via
Classconstructor arguments) registers callbacks for property changes (repairmaterial,healthrepairable,workrepairable,finiteusesrepairable) to manage tags automatically on updates. - Pushes:
repairableitself does not push events, butRepair()callsonrepaired(self.inst, doer, repair_item)if defined as a local closure or assigned externally.