Klaus
Based on game build 714014 | Last updated: 2026-03-05
Overview
klaus.lua defines the prefab and core behavior of Klaus, a boss entity in Don't Starve Together. It coordinates multiple components (health, combat, commander, grouptargeter, sleeper, sanityaura, etc.) to implement a multi-phase boss with phase transitions (based on health thresholds), helper summoning (red and blue deer), music control, chain-breaking mechanics (Unchained state), and rage state activation. The prefab is initialized using a factory function fn() and supports client-server network synchronization via net_bool variables.
Usage example
Klaus is not intended to be manually instantiated by mods. It is instantiated by the game via its prefab definition. However, modders can interact with its public methods on the master server:
-- Example of triggering an action in the game logic (e.g., after an event)
local klaus = TheWorld:FindPrefab("klaus")
if klaus and not klaus.components.health:IsDead() then
klaus:PushEvent("transition") -- Forces phase transition manually
klaus:SpawnDeer() -- Manually spawn deer helpers
end
Dependencies & tags
Components used: spawnfader, inspectable, lootdropper, sleeper, locomotor, health, healthtrigger, combat, explosiveresist, grouptargeter, commander, timer, sanityaura, epicscare, knownlocations, drownable, burnable, freezable, talker (via Say call).
Tags added: epic, noepicmusic, monster, hostile, scarytoprey, largecreature, deergemresistance.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
engaged | boolean or nil | nil | Indicates whether Klaus is currently engaged in combat (affects health regen and command cooldown). |
nohelpers | boolean or nil | nil | Prevents helper summoning until reset (e.g., on entering Phase 2 or rage). |
enraged | boolean | false | true when Klaus has entered the enraged state (increased size, scaled stats, no helpers). |
recentattackers | table | {} | Maps attacker entities to timer handles (for resetting attacker tracking after 30 seconds). |
recentlycharged | table | {} | Maps damaged workable entities to true (to prevent repeated charging damage within 3 seconds). |
_unchained | net_bool | false | Networked state indicating whether Klaus's chains have been broken (affects sanity, music, burnable state). |
_pausemusic | net_bool | false | Networked state for music pausing (e.g., during boss death or state transitions). |
_playingmusic | boolean | false | Local flag to prevent redundant music triggers. |
deer_dist | number | 3.5 | Distance offset for deer positioning relative to Klaus. |
hit_recovery | number | TUNING.KLAUS_HIT_RECOVERY | Hit recovery duration (scaled). |
attack_range, hit_range | number | TUNING.KLAUS_ATTACK_RANGE, TUNING.KLAUS_HIT_RANGE | Combat ranges (scaled). |
chomp_range, chomp_min_range, chomp_hit_range | number | Tuning constants (scaled) | Chomp attack range parameters (scaled). |
scrapbook_maxhealth, scrapbook_damage | tables | Arrays of base and enraged values | Exposed for scrapbook display. |
Main functions
SetPhysicalScale(inst, scale)
- Description: Adjusts visual scale, shadow size, physics mass, and capsule dimensions for Klaus. Typically used during rage or phase changes.
- Parameters:
scale(number) - Multiplicative scale factor. - Returns: Nothing.
- Error states: No explicit error handling; assumes
scale > 0.
SetStatScale(inst, scale)
- Description: Scales Klaus's health, damage, attack period, and ranges using a volume-scaled factor (
scale^3). Updates thecombatandhealthcomponents accordingly. - Parameters:
scale(number) - Multiplicative scale factor for stats. - Returns: Nothing.
- Error states: None.
UpdatePlayerTargets(inst)
- Description: Periodically updates Klaus's target list in
grouptargeterby checking which players are withinKLAUS_DEAGGRO_DISTof the spawn point location. Adds/withdraws targets dynamically. - Parameters:
inst(entity) - Klaus entity. - Returns: Nothing.
RetargetFn(inst)
- Description: Called periodically by the
combatcomponent to find a new target. Prioritizes players ingrouptargeter(especially near spawn) and falls back to random nearby players. Returns a new target and atrueflag to continue retargeting. - Parameters:
inst(entity) - Klaus entity. - Returns:
target(entity ornil) andtrue(to indicate readiness to retarget). - Error states: May return
nilif no valid targets are found.
KeepTargetFn(inst, target)
- Description: Determines if Klaus should continue targeting a player. Returns
trueonly if the target is valid and withinKLAUS_DEAGGRO_DISTof the spawn point. - Parameters:
inst(entity) - Klaus entity.target(entity) - Target player.
- Returns:
trueorfalse.
SummonHelpers(inst, warning)
- Description: Spawns up to 2 red and 2 blue deer helpers near Klaus based on proximity to recent attackers or current combat target. Sets
nohelperstotrueto prevent repeat calls. Pushesms_forcenaughtinessevents for penalty calculation. - Parameters:
inst(entity) - Klaus entity.warning(boolean) - Whether to warn nearby players via talker component.
- Returns:
trueif helpers were spawned;falseotherwise.
EnterPhase2Trigger(inst)
- Description: Called when Klaus's health drops to 50% of max. Pushes a
"transition"event to trigger animation/state changes for Phase 2 (chain break, enraged). - Parameters:
inst(entity) - Klaus entity. - Returns: Nothing.
SetEngaged(inst, engaged)
- Description: Manages combat state transition. When
engaged=true: stops health regen, sets command cooldown timer, disablesnewcombattargetcallback. Whenengaged=false: starts regen, resets cooldown, re-enables callback. Resetsnohelperson recovery. - Parameters:
inst(entity) - Klaus entity.engaged(boolean) - Combat engagement state.
- Returns: Nothing.
SpawnDeer(inst)
- Description: Instantiates a red deer and a blue deer, positions them in a spread arc around Klaus, and registers them as soldiers under the
commandercomponent. - Parameters:
inst(entity) - Klaus entity. - Returns: Nothing.
Unchain(inst, warning)
- Description: Breaks Klaus's chains. Unhides chain visuals, enables chain-breaking effects, sets large sanity aura, allows burning (via
nocharring=false), disables foley sounds, and setsurchained=true. - Parameters:
inst(entity) - Klaus entity.warning(boolean) - Whether to warn nearby players.
- Returns: Nothing.
Enrage(inst, warning)
- Description: Activates Klaus's rage state: stops physics, teleports to position, scales up size and stats, disables helper spawning, sets large sanity aura, resets combat FX override.
- Parameters:
inst(entity) - Klaus entity.warning(boolean) - Whether to warn nearby players.
- Returns: Nothing.
PushMusic(inst, level)
- Description: Triggers the
triggeredeventevent for the player if within range, to control music volume levels (1=normal, 2=pause, 3=unchained/rage). - Parameters:
inst(entity) - Klaus entity.level(number) - Music level indicator.
- Returns: Nothing.
OnMusicDirty(inst)
- Description: Recalculates music level based on
urchainedandpausemusicflags and starts/stops a periodic task to update music state. - Parameters:
inst(entity) - Klaus entity. - Returns: Nothing.
PauseMusic(inst, paused)
- Description: Toggles music pausing by updating
_pausemusicnet_bool and callingOnMusicDirty. - Parameters:
inst(entity) - Klaus entity.paused(boolean) -trueto pause,falseto resume.
- Returns: Nothing.
IsUnchained(inst)
- Description: Returns the current
urchainedstate. - Parameters:
inst(entity) - Klaus entity. - Returns:
trueif unchained;falseotherwise.
FindChompTarget(inst)
- Description: Finds a valid chomp target from
AllPlayers: prefers distant targets first, then nearby targets, and falls back to current combat target. - Parameters:
inst(entity) - Klaus entity. - Returns:
target(entity ornil).
OnSave(inst, data)
- Description: Saves
nohelpers,unchained, andenragedstate intodatafor world persistence. - Parameters:
inst(entity) - Klaus entity.data(table) - Save data table.
- Returns: Nothing.
OnPreLoad(inst, data)
- Description: Restores saved state (
nohelpers,unchained,enraged) after loading from a save file. - Parameters:
inst(entity) - Klaus entity.data(table ornil) - Loaded save data.
- Returns: Nothing.
OnEntitySleep(inst)
- Description: Starts a 10-second delayed removal task for Klaus (and his deer) when world enters sleep mode, unless Klaus is unchained and dead.
- Parameters:
inst(entity) - Klaus entity. - Returns: Nothing.
OnEntityWake(inst)
- Description: Cancels the sleep removal task if Klaus wakes up.
- Parameters:
inst(entity) - Klaus entity. - Returns: Nothing.
OnAttacked(inst, data)
- Description: Handles damage event: adds attacker to
recentattackers, updates combat target if needed, and shares attacker to all soldiers. - Parameters:
inst(entity) - Klaus entity.data(table) - Attack event data.
- Returns: Nothing.
OnCollide(inst, other)
- Description: On physics collision with a
workableentity, schedulesOnDestroyOther(with 2-FRAME delay) to destroy the workable and prevent rapid recharging. - Parameters:
inst(entity) - Klaus entity.other(entity) - Collided entity.
- Returns: Nothing.
OnDestroyOther(inst, other)
- Description: Destroys a
workableentity (except dig/net) by triggering its destroy action. Prevents repeated charging withrecentlychargedcooldown. - Parameters:
inst(entity) - Klaus entity.other(entity) - Workable entity to destroy.
- Returns: Nothing.
Events & listeners
- Listens to:
attacked- CallsOnAttacked.musicdirty(client) - CallsOnMusicDirty.newcombattarget- CallsOnNewTarget(only when not engaged).
- Pushes:
"transition"- On health dropping to 50%."soldierschanged"(viacommander) - Soldier list changes."ms_forcenaughtiness"(viaTheWorld:PushEvent) - For Naughty player scoring."triggeredevent"(viaThePlayer:PushEvent) - For music control.