Chest Terrarium Pigs
Based on game build 714014 | Last updated: 2026-03-08
Overview
chest_terrarium_pigs is a scenario-specific trap handler used in the Terrarium event chest mechanics. When attached to a chest via OnLoad, it registers a trap function that—upon chest opening—identifies nearby pigs within a 16-unit radius and transforms them into werepigs. Transformed pigs are set to target the player who opened the chest, if valid. This behavior leverages the werebeast and combat components to enforce state changes and aggression.
The script depends on chestfunctions for trap initialization and cleanup, and on chest_terrarium for shared OnCreate behavior.
Usage example
-- Typically used internally by chest prefabs in the Terrarium event.
-- The component is attached automatically via scenario configuration:
-- inst:AddComponent("chest_terrarium_pigs")
-- followed by calling OnLoad during chest setup:
chest_terrarium_pigs.OnLoad(inst, scenariorunner)
Dependencies & tags
Components used: werebeast, health, combat
Tags: Checks pig and werepig tags via FindEntities; no tags are added/removed directly by this script.
Properties
No public properties.
Main functions
transform(ent, player)
- Description: Transforms a pig entity into a werepig and sets its combat target to the player.
- Parameters:
ent(Entity) — The pig entity to transform.player(Entity ornil) — The player to target; may benil.
- Returns: Nothing.
- Error states: Transformation and targeting occur only if
enthas awerebeastcomponent, is not already in were-pig state, has ahealthcomponent, and is not dead.
triggertrap(inst, scenariorunner, data)
- Description: Scans for nearby pigs (excluding those already werepigs) within 16 units and schedules their transformation with a staggered delay.
- Parameters:
inst(Entity) — The chest entity where the trap is triggered.scenariorunner(ScenarioRunner) — Scenario runner instance.data(table ornil) — Optional trigger data containingdata.player(the triggering player).
- Returns: Nothing.
- Error states: Uses staggered timers (
0.25 * (i-1) + 0.25 * math.random()) to prevent simultaneous transformation; does not act on pigs withoutwerebeastor already in were-pig state.
OnLoad(inst, scenariorunner)
- Description: Initializes the chest as a trap by registering the
triggertrapcallback withchestfunctions. - Parameters:
inst(Entity) — The chest entity.scenariorunner(ScenarioRunner) — Scenario runner instance.
- Returns: Nothing.
Events & listeners
- Listens to: None.
- Pushes: None.