Dev » Lua API » statedef
← Back to all classes

statedef

Definitions & Systems 3 Properties 1 Methods 4 Hooks

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

# id PROPERTY
statedef.id
State string identifier.
Parameters
None
Returns
string

State string ID.

Description

Unique identifier such as "poison", "burning", "wet", "exhausted".

# index PROPERTY
statedef.index
Internal index of the state definition.
Parameters
None
Returns
number

Internal integer index.

Description

Fast integer lookup index.

# isValid PROPERTY
statedef.isValid
Checks if state definition is valid.
Parameters
None
Returns
boolean

True if definition is registered.

Description

Returns true if the definition exists in registry.

# new METHOD
statedef.new(id)
Looks up a state definition by ID.
Parameters
ParameterTypeDefaultDescription
idstring

State definition ID.

Returns
statedef

State definition descriptor.

Description

Returns the statedef descriptor matching id.

local poisonDef = statedef.new("poison")
# onApply HOOK
stateDef:onApply(targetId, value, duration, stateValue, stateRemainingDuration)
Triggered when the state is applied to an entity.
Parameters
ParameterTypeDefaultDescription
targetIdnumber

Target entity ID.

valuenumber

Applied value.

durationnumber

Applied duration.

stateValuenumber

Resulting state value.

stateRemainingDurationnumber

Resulting duration.

Returns
None (void)
Description

Hook called immediately when the state becomes active.

# onRemove HOOK
stateDef:onRemove(targetId, stateValue, stateRemainingDuration, isExpire)
Triggered when the state is removed or expires.
Parameters
ParameterTypeDefaultDescription
targetIdnumber

Target entity ID.

stateValuenumber

Current value.

stateRemainingDurationnumber

Remaining duration.

isExpireboolean

True if expired naturally.

Returns
boolean

Return true to prevent removal.

Description

Called when the state ends or is cured.

# onTick HOOK
stateDef:onTick(targetId, stateValue, stateDuration, stateRemainingDuration)
Periodic tick hook for status effect logic.
Parameters
ParameterTypeDefaultDescription
targetIdnumber

Target entity ID.

stateValuenumber

Current state value.

stateDurationnumber

Total duration.

stateRemainingDurationnumber

Remaining duration in seconds.

Returns
None (void)
Description

Invoked every state tick interval to apply damage or effects over time.

# onTryApply HOOK
stateDef:onTryApply(targetId, value, duration)
State definition validation hook called before application.
Parameters
ParameterTypeDefaultDescription
targetIdnumber

Target entity ID.

valuenumber

Proposed intensity value.

durationnumber

Proposed duration in seconds.

Returns
boolean

Return true to block the state from being applied.

Description

Hook defined in state definitions to validate or block application to targetId.