Chest Abandonedboat
Based on game build 714014 | Last updated: 2026-03-08
Overview
This scenario file configures an abandoned boat chest by defining its loot table and trap behavior. It integrates with chestfunctions.lua to populate the chest with randomized items and attach a trap that activates with 90% probability upon opening. The trap can spawn pirates, spawn a nearby ghost that targets the opener, or destroy the chest’s platform.
Usage example
-- This file is called by the game's scenario system; usage is implicit.
-- It is not meant to be directly instantiated.
-- When a chest prefab with this scenario runs:
chestfunctions.AddChestItems(inst, LOOT) -- adds loot
chestfunctions.InitializeChestTrap(inst, scenariorunner, TriggerTrap, 0.9) -- attaches trap
Dependencies & tags
Components used: walkableplatform, health, fueled, finiteuses, sanity, piratespawner
Tags: No tags added or checked directly; relies on tags in spawned entities (e.g., "skeleton", "ghost").
Properties
No public properties. All state is encapsulated in LOOT table and TRIGGER_TRAP_CHANCE.
Main functions
GetRandomAmount2to5()
- Description: Returns a random integer between 2 and 5 inclusive.
- Parameters: None.
- Returns:
number— random integer2 ≤ n ≤ 5.
GetRandomAmount1to3()
- Description: Returns a random integer between 1 and 3 inclusive.
- Parameters: None.
- Returns:
number— random integer1 ≤ n ≤ 3.
RandomFueledPercent(item)
- Description: Sets the
fueledcomponent ofitemto a random percent between43%and82%. - Parameters:
item(Entity) — an entity with afueledcomponent. - Returns: Nothing.
RandomFiniteusesPercent(item)
- Description: Sets the current uses of
itemto a random integer between40%and80%of its total uses, rounded up. - Parameters:
item(Entity) — an entity with afiniteusescomponent. - Returns: Nothing.
SetGhostTarget(inst, player)
- Description: Assigns a
followtargeton thebrainofinst(a ghost) to trackplayer. - Parameters:
inst(Entity) — ghost entity (may benil).player(Entity) — target player entity.
- Returns: Nothing.
- Error states: Returns early if
instisnilorinst.brainisnil.
FindNearbySkeleton(platform)
- Description: Searches for a
"skeleton"entity on the givenwalkableplatform. - Parameters:
platform(Entity) — platform entity withwalkableplatformcomponent (may benilor invalid). - Returns:
Entity?— the skeleton entity if found, otherwisenil.
TriggerTrap(inst, scenariorunner, data)
- Description: Triggers one of three effects on chest opening, based on a random roll and conditions:
≤ 33%: Spawns pirates for the player.≤ 66%and skeleton present: Spawns a ghost on the platform, sets it to target the player, and deals huge sanity loss to the player.- Otherwise: Destroys the platform (
health:Kill()).
- Parameters:
inst(Entity) — the chest entity.scenariorunner(Entity) — scenario runner instance.data(table) — must containplayer(Entity). May include platform context viaGetCurrentPlatform().
- Returns: Nothing.
OnCreate(inst, scenariorunner)
- Description: Populates the chest with loot using the
LOOTtable. - Parameters:
inst(Entity) — the chest entity.scenariorunner(Entity) — scenario runner instance.
- Returns: Nothing.
OnLoad(inst, scenariorunner)
- Description: Initializes the trap for the chest using
TRIGGER_TRAP_CHANCE = 0.9. - Parameters:
inst(Entity) — the chest entity.scenariorunner(Entity) — scenario runner instance.
- Returns: Nothing.
Events & listeners
- Listens to: None (no event listeners).
- Pushes: None directly; relies on functions like
health:Kill()and component events (sanitydelta, etc.) from other components.