Healer
Based on game build 714014 | Last updated: 2026-03-03
Overview
The Healer component enables an entity (typically a consumable item) to heal a target's health component. It supports configurable healing amount, conditional healing via callback functions, multiplier application via the efficientuser component, and automatic consumption of the healer item upon successful use.
Usage example
local inst = CreateEntity()
inst:AddComponent("healer")
inst.components.healer:SetHealthAmount(TUNING.HEALING_LARGE)
inst.components.healer:SetOnHealFn(function(inst, target, doer)
print(target_prefab .. " was healed by " .. doer_prefab)
end)
-- Later, during interaction:
inst.components.healer:Heal(target_entity, doer_entity)
Dependencies & tags
Components used: health, efficientuser, stackable
Tags: None identified.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
health | number | TUNING.HEALING_SMALL | The base amount of health restored per heal. |
canhealfn | function? | nil | Optional callback: (healer_inst, target_inst, doer_inst) -> valid: boolean, reason: string? |
onhealfn | function? | nil | Optional callback: (healer_inst, target_inst, doer_inst) -> void |
Main functions
SetHealthAmount(amount)
- Description: Sets the base healing amount applied per use.
- Parameters:
amount(number) – the healing value to assign. - Returns: Nothing.
SetOnHealFn(fn)
- Description: Assigns a callback function that executes after successful healing.
- Parameters:
fn(function) – signature(healer_inst, target_inst, doer_inst). - Returns: Nothing.
SetCanHealFn(fn)
- Description: Assigns a validation callback that determines if healing is allowed before execution.
- Parameters:
fn(function) – signature(healer_inst, target_inst, doer_inst) -> valid: boolean, reason: string?. - Returns: Nothing.
Heal(target, doer)
- Description: Attempts to heal the
targetentity. Returns success status, consumes the healer item on success. - Parameters:
target(Entity) – Entity to heal (must havehealthcomponent).doer(Entity) – Entity using the healer (used for multiplier checks and callbacks).
- Returns:
trueon successful heal,falseotherwise (optionally with areasonstring). - Error states:
- Returns
falseiftargetlacks thehealthcomponent. - Returns
false, reasonifcanhealfnreturnsfalse. - Does not apply healing if
target.components.health.canhealisfalse, but still does not consume the item.
- Returns
Events & listeners
- Listens to: None identified.
- Pushes: None identified.