statedef
statedef
The statedef class represents status effect definitions registered in def.state.*. It defines how buffs and debuffs behave on application, periodic tick, and expiration.
Overview
Properties (3)
| Property | Type | Summary |
|---|---|---|
id
|
string
|
State string identifier. |
index
|
number
|
Internal index of the state definition. |
isValid
|
boolean
|
Checks if state definition is valid. |
Methods (1)
| Method Signature | Returns | Summary |
|---|---|---|
statedef.new(id)
|
statedef
|
Looks up a state definition by ID. |
Hooks & Events (4)
| Hook Signature | Returns | Summary |
|---|---|---|
stateDef:onApply(targetId, value, duration, stateValue, stateRemainingDuration)
|
void
|
Triggered when the state is applied to an entity. |
stateDef:onRemove(targetId, stateValue, stateRemainingDuration, isExpire)
|
boolean
|
Triggered when the state is removed or expires. |
stateDef:onTick(targetId, stateValue, stateDuration, stateRemainingDuration)
|
void
|
Periodic tick hook for status effect logic. |
stateDef:onTryApply(targetId, value, duration)
|
boolean
|
State definition validation hook called before application. |
Detailed Reference
statedef.idstringState string ID.
Unique identifier such as "poison", "burning", "wet", "exhausted".
statedef.indexnumberInternal integer index.
Fast integer lookup index.
statedef.isValidbooleanTrue if definition is registered.
Returns true if the definition exists in registry.
statedef.new(id)| Parameter | Type | Default | Description |
|---|---|---|---|
id | string | State definition ID. |
statedefState definition descriptor.
Returns the statedef descriptor matching id.
local poisonDef = statedef.new("poison")stateDef:onApply(targetId, value, duration, stateValue, stateRemainingDuration)| Parameter | Type | Default | Description |
|---|---|---|---|
targetId | number | Target entity ID. | |
value | number | Applied value. | |
duration | number | Applied duration. | |
stateValue | number | Resulting state value. | |
stateRemainingDuration | number | Resulting duration. |
Hook called immediately when the state becomes active.
stateDef:onRemove(targetId, stateValue, stateRemainingDuration, isExpire)| Parameter | Type | Default | Description |
|---|---|---|---|
targetId | number | Target entity ID. | |
stateValue | number | Current value. | |
stateRemainingDuration | number | Remaining duration. | |
isExpire | boolean | True if expired naturally. |
booleanReturn true to prevent removal.
Called when the state ends or is cured.
stateDef:onTick(targetId, stateValue, stateDuration, stateRemainingDuration)| Parameter | Type | Default | Description |
|---|---|---|---|
targetId | number | Target entity ID. | |
stateValue | number | Current state value. | |
stateDuration | number | Total duration. | |
stateRemainingDuration | number | Remaining duration in seconds. |
Invoked every state tick interval to apply damage or effects over time.
stateDef:onTryApply(targetId, value, duration)| Parameter | Type | Default | Description |
|---|---|---|---|
targetId | number | Target entity ID. | |
value | number | Proposed intensity value. | |
duration | number | Proposed duration in seconds. |
booleanReturn true to block the state from being applied.
Hook defined in state definitions to validate or block application to targetId.