Ghost
Based on game build 722832 | Last updated: 2026-04-28
Overview
ghost.lua registers two spawnable ghost entity prefabs. The primary ghost prefab represents the standard player ghost form with hostility toward non-allies and sanity drain aura. The graveguard_ghost prefab is Wendy's decorated grave guard variant with modified targeting logic that respects ghost-friendly tags and PvP settings. Both prefabs attach combat, health, aura, sanityaura, locomotor, and trader components, and are linked to their respective brain files for AI behavior.
Usage example
-- Spawn standard ghost at position:
local ghost_inst = SpawnPrefab("ghost")
ghost_inst.Transform:SetPosition(10, 0, 10)
-- Spawn grave guard ghost:
local guard_inst = SpawnPrefab("graveguard_ghost")
-- Link grave guard to a gravestone (master only):
if TheWorld.ismastersim then
guard_inst.LinkToHome(guard_inst, gravestone_inst)
end
Dependencies & tags
External dependencies:
brains/ghostbrain-- AI behavior tree for standard ghostbrains/graveguard_ghostbrain-- AI behavior tree for grave guard ghostMakeGhostPhysics-- applies ghost-specific physics configurationTUNING-- global constants table for balance values
Components used:
locomotor-- movement speed configuration (walkspeed, runspeed, directdrive)sanityaura-- drains sanity of nearby players (-TUNING.SANITYAURA_MED)health-- sets max health to TUNING.GHOST_HEALTHcombat-- damage output and target tracking with custom keep target functionaura-- periodic damage aura with custom test functiontrader-- accepts heart items for flavor text (always rejects via AbleToAcceptTest)inspectable-- allows players to examine the ghostknownlocations-- (graveguard only) remembers gravestone home positiontimer-- (graveguard only) tracks "played_recently" timer
Tags:
ghost-- added to both variants for ghost-specific interactionsflying-- added to both variants for movement classificationnoauradamage-- added to both variants to prevent receiving aura damagetrader-- added to both variants for trader component optimizationmonster-- added to standard ghost for combat targetinghostile-- added to standard ghost for aggression classificationgraveghost-- added to graveguard variant only
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
assets | table | --- | Array of Asset entries for animation and sound files loaded with both prefabs. |
GRAVEGUARD_SCRAPBOOK_OVERRIDEDARA | constant (local) | {{ "ghost_eyes", "ghost_build", "ghost_eyes_happy" }} | (graveguard) File-scope constant defining symbol override data for scrapbook rendering. |
GUARD_AURA_SAFE_TAGS | constant (local) | {"abigail", "ghostlyfriend"} | (graveguard) Tags that exempt targets from graveguard aura aggression. |
GUARD_AURA_UNSAFE_TAGS | constant (local) | {"hostile", "monster"} | (graveguard) Tags that mark targets for graveguard aura aggression. |
Main functions
fn()
- Description: Client-side constructor for the standard ghost prefab. Creates entity, applies ghost physics, configures light and animation, adds tags, and plays ambient howl sound. On master sim, attaches brain, stategraph, and all gameplay components (locomotor, sanityaura, health, combat, aura, trader, inspectable). Returns
instfor engine processing. - Parameters: None
- Returns: entity instance
- Error states: None — runs on every host with master-only branching for gameplay components.
graveguard_fn()
- Description: Client-side constructor for Wendy's grave guard ghost variant. Similar to
fn()but with modified eye symbol override (happy eyes), different multicolour tint, and additional components (knownlocations, timer). On master sim, attaches graveguard-specific brain, custom aura test function, and gravestone linking functionality. Setspersists = falseto prevent world save. - Parameters: None
- Returns: entity instance
- Error states: None — runs on every host with master-only branching for gameplay components.
AbleToAcceptTest(inst, item) (local)
- Description: Trader component test function that determines if the ghost can accept a trade item. Always returns
falsewith reason string"GHOSTHEART"if item has "reviver" tag, otherwise returnsfalsewithnilreason. Used to trigger flavor text when players attempt to give hearts. - Parameters:
inst-- ghost entity instanceitem-- item entity being offered for trade
- Returns:
false, reason_stringorfalse, nil - Error states: Errors if
itemis nil and trader component does not guard before calling test function (no nil guard beforeitem:HasTag()call in this function).
OnDeath(inst) (local)
- Description: Event callback fired when ghost dies. Disables the aura component to stop periodic damage ticks. Called via
inst:ListenForEvent("death", OnDeath). - Parameters:
inst-- ghost entity instance - Returns: None
- Error states: Errors if
inst.components.aurais nil (component not attached).
AuraTest(inst, target) (local)
- Description: Aura component test function for standard ghost. Returns
trueif target should receive aura damage. Targets are damaged if they are the ghost's combat target, if the ghost is their combat target, or if they lack "abigail", "ghostlyfriend", or "ghost_ally" tags. - Parameters:
inst-- ghost entity instancetarget-- potential aura damage recipient entity
- Returns:
trueto apply damage,falseto skip - Error states: Errors if
inst.components.combatortarget.components.combatis nil.
OnAttacked(inst, data) (local)
- Description: Event callback fired when ghost is attacked. Sets combat target to the attacker unless attacker has "noauradamage" tag. Clears target if attacker is nil. Called via
inst:ListenForEvent("attacked", OnAttacked). - Parameters:
inst-- ghost entity instancedata-- event data table withattackerfield
- Returns: None
- Error states: Errors if
inst.components.combatis nil (no guard present) or ifdata.attackeris non-nil but lacksHasTagmethod.
KeepTargetFn(inst, target) (local)
- Description: Combat component keep target function for standard ghost. Returns
trueto maintain target if within TUNING.GHOST_FOLLOW_DSQ distance squared. Clearsinst.brain.followtargetand returnsfalseif target is too far. - Parameters:
inst-- ghost entity instancetarget-- current combat target entity
- Returns:
trueto keep target,falseto drop - Error states: Errors if
inst:GetDistanceSqToInst()fails on invalid target.
target_test(inst, target, pvp_enabled) (local)
- Description: Internal targeting test for graveguard variant. Determines if target should be aggressively targeted based on PvP settings, ghost-friendly tags, and combat target relationships. Returns
falsefor players with PvP off or targets with safe tags. Returnstruefor targets attacking the ghost or their leader. - Parameters:
inst-- graveguard entity instancetarget-- potential target entitypvp_enabled-- boolean or nil (queries TheNet if nil)
- Returns:
trueto target,falseto ignore - Error states: Errors if
target.components.combatis nil when expected, or if TheNet methods fail.
GuardAuraTest(inst, target) (local)
- Description: Aura component test function for graveguard variant. Combines tag checks ("character", "hostile", "monster", "smallcreature") with
target_test()logic. Only applies aura damage to valid hostile targets. - Parameters:
inst-- graveguard entity instancetarget-- potential aura damage recipient entity
- Returns:
trueto apply damage,falseto skip - Error states: Errors if
target:HasAnyTag()fails ortarget_test()encounters nil components.
GuardKeepTargetFn(inst, target) (local)
- Description: Combat component keep target function for graveguard variant. Identical logic to
KeepTargetFn()— maintains target within TUNING.GHOST_FOLLOW_DSQ distance, clears brain follow target otherwise. - Parameters:
inst-- graveguard entity instancetarget-- current combat target entity
- Returns:
trueto keep target,falseto drop - Error states: Errors if
inst:GetDistanceSqToInst()fails on invalid target.
OnGhostPlayWithMe(inst) (local)
- Description: Event callback for graveguard variant fired when player interacts via "ghostplaywithme" event. Starts or resets "played_recently" timer to TUNING.SEG_TIME duration. Used to track recent player interaction for behavior decisions.
- Parameters:
inst-- graveguard entity instance - Returns: None
- Error states: Errors if
inst.components.timeris nil.
link_to_gravestone(inst, gravestone) (local)
- Description: Links graveguard ghost to a gravestone home position. Stores unlink callback on
inst.UnlinkFromGravestone, registers gravestone "onremove" event listener, and remembers gravestone position via knownlocations component as "home" location. - Parameters:
inst-- graveguard entity instancegravestone-- gravestone entity to link to
- Returns: None
- Error states: Errors if
gravestone:IsValid()fails,gravestone:ListenForEvent()fails, orinst.components.knownlocationsis nil.
Events & listeners
Listens to:
death-- triggers OnDeath; disables aura component on both variantsattacked-- triggers OnAttacked; sets combat target to attacker on both variantsghostplaywithme-- triggers OnGhostPlayWithMe; resets played_recently timer (graveguard only)
Pushes:
- None identified
World state watchers:
- None identified