Damagetracker
Overview
This component's primary responsibility is to monitor its parent entity's health changes. It accumulates the absolute value of all health modifications (damage taken or healing received) occurring on the entity while the component is enabled. If this cumulative value reaches or exceeds a predefined threshold, it will execute a specified callback function, providing a mechanism to react to significant health-related activity on the entity.
Dependencies & Tags
None identified.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
damage_done | number | 0 | The cumulative absolute amount of health change (damage taken + healing received) tracked since the component was enabled or reset. |
damage_threshold | number | 2500 | The accumulated health change amount that, when reached or exceeded, will trigger the damage_threshold_fn callback. |
damage_threshold_fn | function or nil | nil | A callback function to be executed when damage_done reaches damage_threshold. It receives the component's inst as its only argument. |
enabled | boolean | false | Controls whether the component is actively tracking health changes. |
Main Functions
Start()
- Description: Enables the component to begin tracking health changes. When enabled, the
OnHealthDeltalistener will process subsequenthealthdeltaevents. - Parameters: None.
Stop()
- Description: Disables the component, pausing the tracking of health changes. While stopped, the
OnHealthDeltalistener will ignorehealthdeltaevents. - Parameters: None.
OnHealthDelta(data)
- Description: This is the event handler for the
healthdeltaevent. When triggered and the component is enabled, it adds the absolute value of the health change todamage_done. If the newdamage_donevalue meets or exceedsdamage_thresholdand it was previously below the threshold, it calls thedamage_threshold_fnif one is set. - Parameters:
data(table): A table containing information about the health change. It is expected to contain anamountfield, representing the raw change in health (negative for damage, positive for healing).
Events & Listeners
- Listens For:
healthdelta: Listened to on the component'sinst. This event triggers theOnHealthDeltamethod whenever the entity's health changes.