Skip to main content

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

PropertyTypeDescription
currenthealthNumberCurrent health value of the entity
maxhealthNumberMaximum possible health value
minhealthNumberMinimum health value (usually 0)
invincibleBooleanWhether the entity can take damage
vulnerabletoheatdamageBooleanWhether entity takes damage from overheating
vulnerabletocoldBooleanWhether entity takes damage from freezing
fire_damage_scaleNumberMultiplier for fire damage
absorbNumberAmount of damage absorption (0-1 range)
playerabsorbNumberDamage absorption specifically from player attacks
penaltyNumberHealth 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:

  1. Combat Component initiates damage via DoAttack() or similar functions
  2. Armor Component (if present) absorbs a percentage of damage via absorb_percent
  3. Health Component applies remaining damage via DoDelta()
  4. 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

Several components interact with health properties:

ComponentKey Health Interactions
HealthCore health management (DoDelta, SetMax, etc.)
CombatDamage dealing, attack handling
ArmorDamage absorption via absorb_percent
EdibleHealth restoration via healthvalue
HealerDirect healing functionality
SpawnerRespawn mechanics after death
ResurrectionReturn 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 dies
  • healthdelta - When health changes
  • attacked - When the entity receives damage
  • startfiredamage / stopfiredamage - For fire damage states

See also