Living Tool
Browse the docs
Docs/Reference

Event opcodes

Story events run on a small bytecode VM inside each NPC pack. Retail has 74 one-byte opcodes of fixed length, with operands relative to the pack's D-block; a HackerGC base adds a 75th.

v0.1.27 · updated 16 Oct 2026 · 6 min read

How scripts run

Every NPC pack carries two kinds of event logic. Tier-1 triggers are proximity records: doors, flag setters and scene starts. Tier-2 is a bytecode VM that runs a script when you talk to an actor or a scene begins.

Retail counts: 3,770 actor scripts, 1,930 doors, 488 scene starts and 512 event flags.
Retail counts: 3,770 actor scripts, 1,930 doors, 488 scene starts and 512 event flags.
  • Each opcode is one byte with a fixed length, so a script can be decoded without running it.
  • Operands are u16 offsets from the pack's D-block, which also holds the text, names and objectives they point at.
  • In a Tier-1 trigger group, only the first trigger whose flag is set is active.
  • A script ends at END (0x00) outside every block. A retail new game starts on chunk/326.
The Structured view of npc/7's wake-up scene: each instruction with its D-offset, operands and what it does.
The Structured view of npc/7's wake-up scene: each instruction with its D-offset, operands and what it does.

Blocks without offsets

Conditions don't store jump distances. When a test fails, the VM steps forward one instruction at a time, counting nested blocks, until it reaches the matching ELSE. You can insert code anywhere without fixing up a single offset. In the DSL you write if … { } else { }, and the assembler writes the markers.

IF := condition 0D then 0E else 0F
0B 04 00    IF_FLAG 0x004       ; flag clear? jump to ELSE
0D          BEGIN
  01 4C 0D    SAY D+0x0D4C
0E          ELSE
  23 0B 00    CUTSCENE 11
0F          ENDIF
00          END

Opcode reference

Lengths include the opcode byte and come from the table at OVR02 0x801FC454. Mnemonics are the Structured view's names. The DSL writes them in lower case, with if_item_alt for 0x1D and block_begin, block_else and block_end for markers that don't pair up.

OpLenMnemonicEffect
Flow and conditions
001ENDScript finished
0A1IF_YESYes/No prompt; "No" runs the else branch
0B3IF_FLAGFlag clear → else
0C5IF_RUBIESFewer rubies than n → else
0D 0E 0F1BEGIN ELSE ENDIFBlock markers
1D 1E3IF_ITEMItem not in inventory → else (identical handlers)
2F3GOTOJump to D+offset
3A3CHOICEMenu of options; the second → else
Dialogue
01 02 033SAY SAY2 SAY3Show the line at D+offset; SAY2 keeps the window, SAY3 keeps the line shown
1F3SPEAKERSet the speaker name
201NO_SPEAKERClear the speaker name
443OBJECTIVESet the quest-log line, up to 103 bytes (139 sites)
Flags, items and rubies
043SETSet a flag; 0xFD clears scratch flags 0–63 (wipe_scratch)
053CLEARClear a flag
163GIVEGive an item silently
285CHESTOpen a chest: flag, item (283 of 291 use no-op flag 0xF8)
335ADD_RUBIESAdd rubies (i32)
World and game modes
068INNRest, heal, offer a save, then warp
073SHOPOpen shop 0–22
083BATTLEStart a battle from a zone or story id 0x100–0x13F
1911WARPWarp: facing, chunk, x, z, flags
223BGMLoad a music track
233CUTSCENERun canned cutscene task 0–15
Actors and camera
103ANIMSet this actor's animation
111FACE_KNIGHTActor turns to face the Knight
1C3WALKWalk the Knight along the walk data at D+offset
272WAITWait n frames
147CAM_EASEEase the camera to three angles (blocking)
262CAM_ACTORPoint the camera at an actor
HackerGC base only
4A6EXText sub a b; sub 0 runs new overlay new/a with argument b

The other 40 retail opcodes cover fades, camera variants, helper actors, party healing and a few no-ops. Select an instruction in the Structured view to see its encoding and how many retail sites use it. Right-click a row and choose Insert after → Other instruction… for the opcodes the guided form can write.

Operand types

All multi-byte operands are little-endian. References into the pack are D-relative, so moving text means repointing every operand that names it. Living Tool does that each time it lays a pack out again.

KindEncodingUsed by
Text refu16 offset from the D-block01–03 1F 3A 3B 44
Code refu16 D-offset on an instruction boundary2E 2F
Walk refu16 D-offset of walk data1C 34
Flagu16, 0–511 on retail; up to 0x29F on a HackerGC base04 05 0B 2D 28
Itemu16: below 500 an item, 1000+ a Living Toy, 3000 nothing16 1D 1E 28
Chunku16 0–523, or a new area the project has (1328–2499)06 13 19 45
Actoru8 slot, below 8724 25 26 36 37 48

Worked example

The wake-up scene on chunk/326 is actor 3 in npc/7: 30 instructions, 84 bytes. If you've already been woken, it plays a short line. Otherwise it runs the morning cutscene, sets the first objective and warps you outside. Here it is as the DSL prints it.

npc/7 · actor 3 · D+0x2024
if flag(0x004) {
  say @0x0D4C  // "I guess it was just / an illusion..."
  set 0x081
  if flag(0x002) {
    wipe_scratch  // flags 0–63 cleared
    set 0x002
  } else {
    wipe_scratch  // flags 0–63 cleared
  }
  clear 0x0FC
} else {
  cutscene 11  // Knight walks waypoints
  say @0x1BCC  // "Good morning! / Wake up, wake up!"
  cutscene 12  // commit the typed name
  say2 @0x0D74  // "$A, wake up! / Wake up you sleepy / head!"
  anim 1
  anim 2
  say2 @0x0DA0  // "Come on $A, / it's almost noon! / Rise and shine!"
  say @0x0DD0  // "I've never seen / anyone get up / so slowly! …"
  anim 3
  anim 0
  set 0x00E
  clear 0x0FF
  clear 0x0FC
  objective @0x1CC0  // "The Mayor was looking / for you. We better …"
  warp facing:0 chunk/78 x:-32 z:-880 flags:0x0201
}
The DSL view with give 5 added before the warp: Assemble appends the program, 87 bytes, at the end of the D-span.
The DSL view with give 5 added before the warp: Assemble appends the program, 87 bytes, at the end of the D-span.