Waxable
Overview
The Waxable component allows an entity to be waxed (or sprayed with wax), offering a customizable callback (waxfn) to define what happens when waxing occurs, and automatically manages the "waxable" and "needswaxspray" tags on the entity based on internal state and waxing conditions.
Dependencies & Tags
- Tags added/removed:
"waxable"(when waxable),"needswaxspray"(when wax spray is needed). - Component dependencies: Relies on components present on the waxing item (
wax,finiteuses,stackable), not directly added to the host entity.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | nil | Reference to the parent entity, assigned in the constructor. |
waxfn | function | nil | Callback function responsible for executing waxing logic (signature: fn(inst, doer, waxitem) → result: boolean, reason?: string). |
needs_spray | boolean | false | Indicates whether the entity currently requires wax spray. Controls the "needswaxspray" tag. |
Note: No explicit _ctor properties beyond inst and needs_spray are initialized — waxfn starts as nil and is set via SetWaxfn().
Main Functions
Waxable:SetWaxfn(fn)
- Description: Sets the waxing callback function that defines how waxing behaves for this entity.
- Parameters:
fn (function): A function with signaturefn(inst, doer, waxitem) → result: boolean, reason?: string.
Waxable:SetNeedsSpray(val)
- Description: Updates whether the entity needs wax spray, adding or removing the
"needswaxspray"tag accordingly. - Parameters:
val (any): Truthy value setsneeds_spray = true; otherwisefalse.
Waxable:NeedsSpray()
- Description: Returns whether the entity is currently in a state that requires wax spray (i.e.,
needs_sprayis true). - Parameters: None.
- Returns:
boolean.
Waxable:Wax(doer, waxitem)
- Description: Attempts to apply wax to the entity. Validates conditions (e.g., sprays only allowed if
needs_spray), invokes thewaxfncallback, and consumes the wax item upon success. - Parameters:
doer (Entity): The entity performing the waxing (e.g., a player).waxitem (Entity): The wax item used (must havewaxcomponent; if it's a spray,needs_sprayis enforced).
- Returns:
result (boolean), optionallyreason (string). - Side effects: Consumes
waxitemon success (viafiniteuses:Use(),stackable:Get():Remove(), orwaxitem:Remove()). Fails ifneeds_sprayis false but the item is a spray, or ifwaxfnreturns false.
Waxable:OnRemoveFromEntity()
- Description: Cleanup method called when this component is removed from the entity; ensures wax-related tags are removed.
- Parameters: None.
Events & Listeners
None.