UODiamondCodex

Treasure Chests System

Randomly spawns lockable "guardian" treasure chests on grasslands; opening one summons a wave of monsters and, after a delay, yields a loot-filled chest. Source: UOD - System Treasure Chests.scp.

How it works

Spawneri_chest_treasure_system keeps the world topped up to a target population (MORE=150 chests):

  • Each tick (@timer), if i_treasurechest.instances already exceeds the target, it waits 60s.
  • Otherwise it picks a random map coordinate, and only places a chest if the tile is t_grass. It spawns a scratch c_rat named fixchest to test placement, then rejects the spot if it is in a housing region (r_housing), a guarded region, or near a tree/wall (isneartype t_tree/t_wall). Valid spots get an i_treasurechest; the test rat is removed.
  • say lines ("Was grass" / "Wasn't Grass") report placement attempts for tuning/debug.

The chesti_treasurechest (brass chest, random flip, colour 0800) uses a TAG.opened state machine:

tag.opened Meaning / on double-click
0 (fresh) First open: plays lightning, spawns 3 waves of a random monster (titans, ophidians, elementals, dragon, cyclops king, etc.), sets them to attack and home on the chest, arms a 3-minute decay ("Hurry! The chest will decay in 3 minutes!"), and sets state to 1.
1 (guarded) "You can't open the chest yet!" — must clear the guardians / wait.
2 (ready) Opens: spawns i_treasurechest_opened (the loot container) in place, 180s decay, and removes itself.

On @timer, a fresh (opened==0) chest simply decays; a guarded chest advances to opened=2 (ready to loot).

Loot — the i_treasurechest_opened TEMPLATE contains gold {400 800}, poor/meager magic goodies and loot, reagents, potions, magic wands, and random loot rolls.

Commands / player-facing usage

No player commands — chests spawn automatically and are used by double-clicking. GM helper: FIXTCHEST removes all i_treasurechest instances (cleanup).

Key definitions

DEFNAME Role
i_chest_treasure_system Global spawner; MORE = target chest population (150)
i_treasurechest The spawned chest with the open/guard/ready state machine
i_treasurechest_opened TEMPLATE loot container spawned when looted
i_tempsummon Item placed on summoned guardians (ties them to the chest)
FIXTCHEST GM cleanup: removes every treasure chest

Note: This is separate from the map-based Treasures system (dig-for-treasure via treasure maps). Chests here spawn directly on the landscape.