Repairable
Overview
The Repairable component manages whether and how an entity can be repaired by external repair items. It tracks repair constraints (e.g., material type, health/work/perish/finite-uses state), dynamically manages entity tags to reflect repairability conditions, and executes repair actions when valid repair items are used.
Dependencies & Tags
Dependencies:
inst.components.health(used if present for health-based repair logic)inst.components.workable(used if present for work-based repair logic)inst.components.perishable(used if present for perish-time-based repair logic)inst.components.finiteuses(used if present for finite-uses-based repair logic)
Tags added/removed dynamically:
"repairable_<material>", where<material>is the value ofself.repairmaterial"healthrepairable"whenself.healthrepairableis true"workrepairable"whenself.workrepairableis true"finiteusesrepairable"whenself.finiteusesrepairableis true
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
repairmaterial | string? | nil | Required material type for repairs; used to tag the entity as compatible with specific repair items. |
healthrepairable | boolean? | nil | Indicates whether the entity is eligible for health-based repairs (based on current health deficit). |
workrepairable | boolean? | nil | Indicates whether the entity is eligible for work-based repairs (based on remaining work left). |
finiteusesrepairable | boolean? | nil | Indicates whether the entity is eligible for finite-uses-based repairs (based on remaining uses). |
noannounce | boolean? | nil | Reserved; unused in provided code. |
checkmaterialfn | function? | nil | Optional callback to validate repair materials beyond basic equality. |
testvalidrepairfn | function? | nil | Optional callback to validate whether a repair attempt is allowed before material checks. |
Main Functions
Repairable:SetHealthRepairable(repairable)
- Description: Sets the
healthrepairableflag and updates the"healthrepairable"tag accordingly. - Parameters:
repairable(boolean): Whether the entity is currently repairable via health restoration.
Repairable:SetWorkRepairable(repairable)
- Description: Sets the
workrepairableflag and updates the"workrepairable"tag accordingly. - Parameters:
repairable(boolean): Whether the entity is currently repairable via work restoration.
Repairable:SetFiniteUsesRepairable(repairable)
- Description: Sets the
finiteusesrepairableflag and updates the"finiteusesrepairable"tag accordingly. - Parameters:
repairable(boolean): Whether the entity is currently repairable via finite-uses restoration.
Repairable:OnRemoveFromEntity()
- Description: Cleans up all repair-related tags when the component is removed from its entity.
- Parameters: None.
Repairable:NeedsRepairs()
- Description: Determines whether the entity is below a repair threshold (95% health/work/perish/uses) and thus needs repairs. Prioritizes health > work > perish > finiteuses.
- Parameters: None.
- Returns:
boolean—trueif repairs are needed,falseotherwise.
Repairable:Repair(doer, repair_item)
- Description: Executes a repair action on the entity using a given repair item. Validates material compatibility, runs custom checks, applies repair amounts, consumes the repair item, and triggers callbacks.
- Parameters:
doer(Entity): The entity performing the repair (typically a player).repair_item(Entity): The item used to perform repairs (e.g., rope, glue, patch).
- Returns:
boolean—trueif repair succeeded;falseotherwise.
Events & Listeners
- Listens to changes in
repairmaterialvia theonrepairmateriallistener (added inClass()constructor) → updates"repairable_<material>"tag. - Listens to changes in
healthrepairablevia theonhealthrepairablelistener → updates"healthrepairable"tag. - Listens to changes in
workrepairablevia theonworkrepairablelistener → updates"workrepairable"tag. - Listens to changes in
finiteusesrepairablevia theonfiniteusesrepairablelistener → updates"finiteusesrepairable"tag.