Last Update: 2023-07-06
Health Properties
API Version: 619045
Health properties are a set of shared attributes and mechanics that govern how entities manage their health state in Don't Starve Together. These properties span across multiple components but follow consistent patterns for damage, healing, and death mechanics.
Core Health Properties
Property | Type | Description |
---|---|---|
currenthealth | Number | Current health value of the entity |
maxhealth | Number | Maximum possible health value |
minhealth | Number | Minimum health value (usually 0) |
invincible | Boolean | Whether the entity can take damage |
vulnerabletoheatdamage | Boolean | Whether entity takes damage from overheating |
vulnerabletocold | Boolean | Whether entity takes damage from freezing |
fire_damage_scale | Number | Multiplier for fire damage |
absorb | Number | Amount of damage absorption (0-1 range) |
playerabsorb | Number | Damage absorption specifically from player attacks |
penalty | Number | Health penalty (reduces maximum health) |
Health Interactions
Health properties interact across multiple components to create a cohesive damage and healing system:
Damage Flow
When an entity takes damage, the process typically follows this flow:
- Combat Component initiates damage via
DoAttack()
or similar functions - Armor Component (if present) absorbs a percentage of damage via
absorb_percent
- Health Component applies remaining damage via
DoDelta()
- If health reaches zero, death events are triggered
-- Example damage flow
function ApplyDamage(target, damage, attacker, weapon)
-- Combat component initiates attack
if target.components.combat then
target.components.combat:GetAttacked(attacker, damage, weapon)
else
-- Direct health modification if no combat component
if target.components.health then
target.components.health:DoDelta(-damage)
end
end
end
Protection Mechanics
Protection against damage is handled through several properties:
- Damage Absorption: Reduces damage by a percentage (0-1)
- Invincibility: Completely prevents damage when true
- Immunity Tags: Specific damage types that can be negated
- Weakness Tags: Damage types that bypass protection
-- Example damage reduction calculation
function CalculateReducedDamage(damage, absorb_percent, weakness_mult)
local reduced_damage = damage * (1 - absorb_percent)
if weakness_mult then
reduced_damage = reduced_damage * weakness_mult
end
return math.max(0, reduced_damage)
end
Healing Mechanics
Healing can come from multiple sources and is processed through health properties:
- Direct Healing: Via
Health:DoDelta(positive_amount)
- Food Healing: Via
Edible.healthvalue
- Regeneration: Automatic healing over time via
StartRegen()
- Sleep Healing: Healing while sleeping
Health-Related Components
Several components interact with health properties:
Component | Key Health Interactions |
---|---|
Health | Core health management (DoDelta , SetMax , etc.) |
Combat | Damage dealing, attack handling |
Armor | Damage absorption via absorb_percent |
Edible | Health restoration via healthvalue |
Healer | Direct healing functionality |
Spawner | Respawn mechanics after death |
Resurrection | Return from death with health restoration |
Health States
Entities can be in various health states:
- Healthy: Health above any critical thresholds
- Critical: Health below critical threshold (often triggers special behaviors)
- Dead: Health at or below zero
- Invincible: Cannot take damage regardless of health value
- Sleeping: Often has modified health regeneration
Special Health Mechanics
The Don't Starve Together API implements several special health-related mechanics:
Health Penalties
Health penalties reduce maximum health while maintaining the same percentage of current health:
function ApplyHealthPenalty(inst, percent)
if inst.components.health then
inst.components.health:SetPenalty(percent)
end
end
Resurrection and Death Prevention
Some mechanics allow preventing or reversing death:
function PreventDeath(inst)
if inst.components.health then
inst.components.health.preventdeath = true
end
end
function AllowResurrection(inst)
if inst.components.health then
inst.components.health:SetCanMurder(false)
end
end
Health Visualization
Health properties are often visualized through:
- Health Badges: UI elements showing current/max health
- Health Bars: Visual indicators above entities
- Visual Effects: Blood splatter, healing effects, etc.
Common Health Events
Health properties trigger several standard events:
death
- When an entity dieshealthdelta
- When health changesattacked
- When the entity receives damagestartfiredamage
/stopfiredamage
- For fire damage states
See also
- Health Component - Core component for health management
- Combat Component - For attack and damage handling
- Armor Component - For health protection mechanics
- Edible Component - For health restoration through food
- Hunger Component - For another vital stat affecting health