Smashables
Based on game build 714014 | Last updated: 2026-03-07
Overview
smashables.lua defines a system for creating and managing smashable ruins-related prefabs—specifically relics (intact structures) and rubble (damaged or broken states). These prefabs support dynamic transitions between states based on health damage and repair progress. It uses core components (combat, health, lootdropper, repairable, sittable, inspectable) and interacts with the ruinsshadelingspawner component. This file is not a component itself, but rather a prefab factory that produces multiple unique prefabs using a shared makefn constructor function.
Usage example
-- Example of adding a smashable relic to a map (internal usage, not typical modder API):
local relic = Prefab("ruins_vase", ...) -- Created internally via `makefn`
relic:AddTag("smashable")
relic:AddComponent("health")
relic.components.health:SetMaxHealth(100)
-- Direct modder usage is typically via prefabs defined here (e.g., "ruins_vase", "ruins_rubble_table")
Dependencies & tags
Components used:
combat, health, lootdropper, repairable, sittable, inspectable, ruinsshadelingspawner (via world component), sanity (via doer component), network (net_bool), miniMapEntity, animstate, soundemitter, transform
Tags added/checked:
Adds cavedweller, smashable, object, stone or clay, noauradamage, electricdamageimmune, structure, limited_chair, uncomfortable_chair (conditionally on chair state).
Checks repairable_stone in displaynamefn, and "ruinsrelic_"..inst._recipename in SCANNABLE_RECIPENAME.
Properties
No public properties are defined as instance fields in the constructor—state is encapsulated in component properties and local flags (e.g., inst.rubble, inst._isrubble, inst._recipename). inst.rubble is used as a legacy boolean flag for compatibility.
Main functions
OnHit(inst)
- Description: Plays a hit animation on the entity if it is animated; triggers "repair" animation for rubble and transitions back to "broken", or "hit" for intact objects followed by "idle".
- Parameters:
inst(entity instance) — the smashable object. - Returns: Nothing.
- Error states: Only intended for animated objects (
if inst.animated). No explicit error handling.
OnDeath(inst)
- Description: Handles entity destruction—spawns a "collapse_small" FX, drops loot via
lootdropper, and removes the entity. - Parameters:
inst(entity instance). - Returns: Nothing.
OnHealthDelta(inst, oldpct, newpct)
- Description: Monitors health percentage; if the entity drops below 50% health and is not yet rubble, it triggers a transition to the rubble state via
SetIsRubbleandMakeRubble. - Parameters:
inst(entity instance),oldpct(number),newpct(number) — previous and current health percentages. - Returns: Nothing.
MakeRelic(inst)
- Description: Converts a rubble entity back into a relic (e.g., during repair): removes
repairable, setsinspectable.nameoverrideto"relic", plays idle animation, and conditionally adds chair-related components/tags ifinst.chairis true. - Parameters:
inst(entity instance). - Returns: Nothing.
MakeRubble(inst)
- Description: Converts an intact relic into rubble: adds
repairablecomponent withrepairmaterial = MATERIALS.STONEand setsonrepaired = OnRepaired, sets nameoverride to"ruins_rubble", plays "broken" animation, and removes chair components/tags. - Parameters:
inst(entity instance). - Returns: Nothing.
OnRepaired(inst, doer)
- Description: Triggered after repair; grants tiny sanity restore if fully repaired, updates sound and animation, and transitions back to relic state if currently rubble.
- Parameters:
inst(entity instance),doer(entity performing repair). - Returns: Nothing.
Chair_TrySpawnShadeling(inst)
- Description: Requests the world's
ruinsshadelingspawnercomponent to spawn a shadeling on this chair if conditions are met. - Parameters:
inst(entity instance, typically a chair). - Returns: Nothing.
Chair_OnEntityWake(inst) / Chair_OnEntitySleep(inst)
- Description: Manages a one-shot task to spawn shadelings when the chair wakes/sleeps to ensure proper persistence across world chunks.
- Parameters:
inst(entity instance). - Returns: Nothing.
SetIsRubble(inst, isrubble)
- Description: Updates the
rubblestate andinst._isrubblenetworked boolean, and updatesSCANNABLE_RECIPENAMEbased on state. - Parameters:
inst(entity instance),isrubble(boolean). - Returns: Nothing.
OnSave(inst, data) / OnPreLoad(inst, data)
- Description: Save/load hooks to persist
rubblestate andmaxhealthacross saves/load. - Parameters:
inst(entity instance),data(table for save or loaded data). - Returns: Nothing.
MakeRubble / MakeRelic / OnIsRubbleDirty / KeepTargetFn
- Description: See above individual functions.
Events & listeners
- Listens to:
"death"— triggersOnDeath."isrubbledirty"— triggersOnIsRubbleDirty(client-side only)."onremove"(viaChair_OnEntitySleep) — cancels shadeling tasks.
- Pushes:
"entity_droploot"— vialootdropper:DropLoot()."sanitydelta"— indirectly viasanity:DoDelta.