Diseaseable
Based on game build 714014 | Last updated: 2026-03-03
Overview
Diseaseable implements a state machine for entity disease, handling the transition from healthy → warning → diseased → spreading. It integrates with game tunings (e.g., TUNING.DISEASE_*) to control timing, spread radius, and chance. The component automatically manages tasks (delays, warnings, FX, spread), persists state via OnSave/OnLoad, and adds/removes tags (diseaseable, diseased) to reflect current condition.
Usage example
local inst = CreateEntity()
inst:AddComponent("diseaseable")
-- Optionally set a custom callback when disease is contracted
inst.components.diseaseable:SetDiseasedFn(function(entity)
print(entity.prefab .. " is now diseased!")
end)
-- Force immediate disease (bypasses delay/warning)
inst.components.diseaseable:Disease()
Dependencies & tags
Components used: None identified.
Tags: Adds diseaseable on construction; adds/removes diseased based on state.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
diseased | boolean | false | Whether the entity is currently diseased. |
_delaytask | Task | nil | Pending delay task before warning/disease check. |
_warningtask | Task | nil | Pending warning countdown before disease onset. |
_spreadtask | Task | nil | Pending task to attempt disease spread. |
_fxtask | Task | nil | Pending task to spawn disease FX (flies). |
onDiseasedFn | function | nil | Optional callback fired when Disease() is called. |
Main functions
Disease()
- Description: Immediately transitions the entity to the diseased state, cancels pending tasks, schedules spread attempts, and spawns FX. No-op if already diseased.
- Parameters: None.
- Returns: Nothing.
- Error states: Returns early with no effect if
self.diseasedistrue.
Spread()
- Description: Attempts to infect one nearby
diseaseableentity withinTUNING.DISEASE_SPREAD_RADIUS. If successful, reschedules itself for future spread attempts. - Parameters: None.
- Returns: Nothing.
- Error states: No-op if not diseased. If no target found, no further spread occurs until manually restarted.
SetDiseasedFn(fn)
- Description: Registers a callback function that fires once when the entity transitions to
diseasedstate. - Parameters:
fn(function) – Called withinstas sole argument at disease onset. - Returns: Nothing.
IsDiseased()
- Description: Returns whether the entity is currently diseased.
- Parameters: None.
- Returns: boolean –
trueif diseased, elsefalse.
IsBecomingDiseased()
- Description: Returns whether the entity is in the warning phase (warning timer active, but not yet diseased).
- Parameters: None.
- Returns: boolean –
trueif warning is pending, elsefalse.
RestartNearbySpread()
- Description: Cancels and restarts spread timers for all diseased entities within
TUNING.DISEASE_SPREAD_RADIUS. Used to accelerate spread when disease becomes more aggressive (e.g., after Certain events). - Parameters: None.
- Returns: Nothing.
OnSave()
- Description: Serializes current state and pending timers for save/load compatibility.
- Parameters: None.
- Returns: table or
nil– Contains keysspreadtime,delaytime, orwarningtimewith remaining seconds (or-1for cancelled). Returnsnilif no active timers or disease state.
OnLoad(data)
- Description: Restores state and pending tasks from serialized data.
- Parameters:
data(table) – Result fromOnSave(). - Returns: Nothing.
GetDebugString()
- Description: Returns a human-readable debug string for console/log inspection.
- Parameters: None.
- Returns: string – Formatted as
"diseased: <bool>, spreadtime: <sec>, delaytime: <sec>, warningtime: <sec>".
Events & listeners
- Listens to: None identified.
- Pushes: None identified. (Note:
ondiseasedis a hook for the class’s_OnAddTagsystem, not an event pushed viainst:PushEvent.)