Nightmarecreature
Based on game build 714014 | Last updated: 2026-03-06
Overview
This script defines a reusable factory function MakeShadowCreature that generates prefabs for nightmare creature variants (crawlingnightmare, nightmarebeak, and ruinsnightmare). It configures core combat, movement, and sanity mechanics, and applies contextual logic—such as planar transformation when shadow rifts are active for ruinsnightmare. The factory handles initialization of components (health, combat, locomotor, sanityaura, lootdropper, shadowsubmissive, knownlocations, planardamage, planarentity) and registers event listeners for attacks, death, and world state changes (e.g., isnightmaredawn, ms_riftaddedtopool).
Usage example
-- Typical usage is internal to DST; prefabs are returned and registered via the Prefab system.
-- Example external instantiation (for modding reference):
local prefabs = require("prefabs/nightmarecreature")
local creature = prefabs[1]() -- Creates a crawlingnightmare instance
Dependencies & tags
Components used: locomotor, health, combat, sanityaura, lootdropper, shadowsubmissive, knownlocations, planardamage, planarentity.
Tags added: nightmarecreature, gestaltnoloot, monster, hostile, shadow, notraptrigger, shadow_aligned, shadowsubmissive.
Tags checked: playerghost, crazy, shadowdominance, inherentshadowdominance.
Properties
No public properties. Configuration is performed via the data table passed to MakeShadowCreature, and all internal state is managed via components.
Main functions
MakeShadowCreature(data)
- Description: Creates and returns a prefab definition for a nightmare creature variant. It sets up all required components, event listeners, sound settings, animations, and tags.
- Parameters:
data(table) - a table containing keys:name(string),build(string),bank(string),num(number),speed(number),health(number),damage(number),attackperiod(number), optionallyphysics_rad(number),stategraph(string),master_postinit(function), andprefabs(table of strings). - Returns: A prefab object (result of
Prefab(...)). - Error states: None documented; assumes valid
datakeys and tunings.
retargetfn(inst)
- Description: Custom retarget function used by the
combatcomponent to select the best target among players, prioritizing those with shadow dominance within a reduced range. - Parameters:
inst(Entity) - the nightmare creature instance. - Returns:
target(Entity ornil) — the selected target, ornilif no valid targets; additionally returns a boolean indicating if the target should be forced when the current target lacks dominance. - Error states: Returns
nilif no valid players are within range or none are valid targets percombat:CanTarget.
OnAttacked(inst, data)
- Description: Event handler that sets the attacker as the creature’s target and attempts to recruit one nearby
nightmarecreatureto assist. - Parameters:
inst(Entity),data(table withattackerfield). - Returns: Nothing.
OnDeath(inst, data)
- Description: If killed by a "crazy" afflicter (e.g., NPC with
crazytag) and no loot table is set, grants onenightmarefuelas loot. - Parameters:
inst(Entity),data(table with optionalafflicterfield). - Returns: Nothing.
ScheduleCleanup(inst)
- Description: Schedules a delayed task to clear loot, reset loot table, and kill the creature—used to handle cleanup on nightmare dawn.
- Parameters:
inst(Entity). - Returns: Nothing.
OnNightmareDawn(inst, dawn)
- Description: Listener for
isnightmaredawnworld state; triggersScheduleCleanupifdawnistrue. - Parameters:
inst(Entity),dawn(boolean). - Returns: Nothing.
RuinsNightmare_OnNewState(inst, data)
- Description: Manages movement sound playback for
ruinsnightmaredepending on state (e.g.,movingstate tag). - Parameters:
inst(Entity),data(table withstatenamefield, optional). - Returns: Nothing.
RuinsNightmare_CheckRift(inst)
- Description: For
ruinsnightmare, dynamically adds/removes planar entity and damage components based on whether a shadow rift is active in the world. - Parameters:
inst(Entity). - Returns: Nothing.
Events & listeners
- Listens to:
attacked— triggersOnAttackedto re-target and share aggro.death— triggersOnDeathto adjust loot if killed by a crazy entity.newstate— triggersRuinsNightmare_OnNewStateforruinsnightmareto manage movement sounds.ms_riftaddedtopool,ms_riftremovedfrompool— triggersRuinsNightmare_CheckRiftto toggle planar state.
- Pushes: None.
- World state watched:
isnightmaredawn— triggersOnNightmareDawnon dawn transition.