Scripting

Notation

Opcode fields:

char[]

Embedded C-style (NUL-terminated) string.

cond

One or more opcodes specifying a condition.

i16

16-bit signed value (little-endian) used for opcode arguments.

int_or_string

Any of char[], i8, u8, i16. This is used in conditions, where the type is determined by the type of the value that is being compared.

pc16

16-bit signed offset (little-endian) used as a jump destination, absolute.

pcrel16

16-bit signed offset (little-endian) used as a jump destination, relative to the current opcode.

u8

8-bit unsigned value used for opcode arguments.

u16

16-bit unsigned value (little-endian) used for opcode arguments.

u32

32-bit unsigned value (little-endian) used for opcode arguments.

Life scripts

Life scripts are broken down into "behaviours" ("comportement" in the source). Each time an actor's life script is executed, it executes the same behaviour as when it last exited (or the first behaviour if it is the first time running). This way, each behaviour acts as a mini AI loop for the actor, with each tailored to a particular situation (e.g. idling, with Twinsen nearby, in combat, interacting with an object, etc).

Life script operations

In the following table, you can see that there are a number of opcodes that have the same behaviour but different names. This is useful when compiling or decompiling the scripts as there is a 1:1 correspondence between the written script and the compiled bytecode.

Opcode (hex)Name/syntaxDescription
0x00ENDMarks the end of this script.
0x01NOPDoes nothing.
0x02SNIF cond pcrel16Jumps always, then replaced with SWIF opcode if condition was true.
0x03OFFSET pcrel16Jumps always.
0x04NEVERIF pcrel16Jumps always. Used as a replacement for a ONEIF opcode.
0x0APALETTE u8:paletteSwitches the game’s palette.
0x0BRETURNEnds the current behaviour.
0x0CIF cond pcrel16Jumps if the condition is false.
0x0DSWIF cond pcrel16Jumps if the condition is false and then replaced with SNIF.
0x0EONEIF cond pcrel16Jumps if the condition is false otherwise replaced with NEVERIF.
0x0FELSE pcrel16Jumps always.
0x10ENDIFDoes nothing.
0x11BODY u8:modelChanges the model of the actor.
0x12BODY_OBJ u8:actor u8:modelChanges the modem of another actor.
0x13ANIM u16:animationChanges the animation of the actor.
0x14ANIM_OBJ u8:actor u16:animChanges the animation of another actor.
0x15SET_CAMERA u8:zone u8:flagEnables or disables a camera zone.
0x16CAMERA_CENTRE u8:angle_adjustRecentres camera.
0x17SET_TRACK i16:trackChanges this actor’s move script track.
0x18SET_TRACK_OBJ u8:actor i16:trackChanges another actor’s move script track.
0x19MESSAGE i16:indexSays a line of dialogue.
0x1ACAN_FALL u8:fall_typeSets whether actor can fall.
0x1BSET_DIRMODE u8:modeSets this actor’s movement mode.
0x1CSET_DIRMODE_OBJ u8:actor u8:modeSets another actor’s movement mode.
0x1DCAMERA_FOLLOW u8:actorMake camera follow an actor.
0x1ESET_HERO_STANCE u8:modeSet Twinsen’s stance.
0x1FSET_VAR_SCENE u8:var u8:valueSets the value of a scene variable.
0x20BEHAVIOUR u8:idBegins a life script behaviour block.
0x21SET_BEHAVIOUR pc16:offsetJumps to a new behaviour block.
0x22SET_BEHAVIOR_OBJ u8:actor pc16:offChanges the active behaviour of another actor.
0x23END_BEHAVIOURMarks the end of a life script behaviour block.
0x24SET_VAR_GAME u8:var i16:valueSets the value of a game variable.
0x25KILL_OBJ u8:actorKills the given actor.
0x26SUICIDEKills this actor.
0x27USE_KEYSubtracts one key from the inventory.
0x28SUB_MONEY i16:quantityTakes money from Twinsen.
0x29END_LIFEEnds life script execution for this actor.
0x2ASAVE_CURRENT_TRACKSaves the move script track to a hidden variable.
0x2BRESTORE_LAST_TRACKRestores the move script track from the hidden variable.
0x2CMESSAGE_OBJ u8:actor i16:messageAnother actor says a line of dialogue.
0x2DINC_CHAPTERIncrement the chapter number game variable.
0x2EFOUND_OBJECT u8:objectDisplay the “found object” overlay.
0x2FSET_DOOR_LEFT i16:distanceSlides this door to the left.
0x30SET_DOOR_RIGHT i16:distanceSlides this door to the right.
0x31SET_DOOR_UP i16:distanceSlides this door upwards.
0x32SET_DOOR_DOWN i16:distanceSlides this door downwards.
0x33GIVE_BONUS u8:removeGives this actor’s bonus items.
0x34CHANGE_SCENE u8:sceneMove to a different scene.
0x35OBJ_COL u8:enabledEnables or disables object/actor collisions for this actor.
0x36BRICK_COL u8:collision_typeEnables or disables terrain collisions for this actor.
0x37OR_IF cond pcrel16Jumps if condition is true.
0x38INVISIBLE u8:invisibleMakes the actor invisible or visible again.
0x39SHADOW_OBJ u8:actor u8:enabledEnables or disables the shadow for another actor.
0x3APOS_POINT u8:pointMoves this actor to a point.
0x3BSET_MAGIC_LEVEL u8:levelSets Twinsen’s magic level.
0x3CSUB_MANA u8:quantityDrains some of Twinsen’s mana.
0x3DSET_HEALTH_OBJ u8:actor u8:valueSets the health of an actor.
0x3ESUB_HEALTH_OBJ u8:actor u8:pointsSubtracts health from another actor.
0x3FHIT u8:victim u8:damageDeals damage to another actor, caused by this actor.
0x40PLAY_VIDEO char[]:namePlays the named cutscene video.
0x41LIGHTNING u8:durationDisplay a lightning flash.
0x42INC_CLOVER_BOXGives Twinsen another clover box.
0x43SET_USED_INVENTORY u8:itemUse inventory item.
0x44ADD_CHOICE i16:messageAdds choice to the next ask.
0x45ASK_CHOICE i16:messageSays a line of dialogue and offers choices.
0x46INIT_BUGGY u8:flagSets up Twinsen’s car.
0x47MEMO_SLATE u8:pictureAdds a picture to the memo slate.
0x48SET_HOLO_POS u8:markerAdds a marker to the holomap.
0x49CLR_HOLO_POS u8:markerRemoves a marker from the holomap.
0x4AADD_FUEL u8:ignoredDoes nothing (LBA1 leftover).
0x4BSUB_FUEL u8:ignoredDoes nothing (LBA1 leftover).
0x4CSET_FRAGMENT u8:zone u8:enableEnables or disables a terrain chunk.
0x4DSET_TELEPORT_ZONE u8:zone u8:flagEnables or disables a teleport zone.
0x4EMESSAGE_ZOE i16:messageSays a line using Zoe’s voice.
0x4FFULL_POINTRestores Twinsen’s health, mana and healing horn.
0x50BETA i16:angleRotates actor.
0x51FADE_TO_PAL u8:paletteFades to the given palette.
0x52ACTIONTriggers Twinsen’s action (like pressing the Z key).
0x53SET_FRAME u8:frameChanges the frame number of this actor’s animation.
0x54SET_SPRITE u8:spriteChanges the sprite used for this actor.
0x55SET_FRAME_3DS u8:frameChanges the frame number of this actor’s animated sprite.
0x56IMPACT_OBJ u8:actor i16:anim i16:yoffsetPlays an impact animation above an actor.
0x57IMPACT_POINT u8:point i16:animPlays an impact animation at a point.
0x58ADD_MESSAGE i16:messageSame as MESSAGE.
0x59BALLOON u8:enableEnables or disables use of speech balloons.
0x5ANO_HIT u8:enableEnables or disables ignoring hits/damage to this actor.
0x5BASK_CHOICE u8:actor i16:messageAnother actor says a line of dialogue and offers choices.
0x5CCINEMA_MODE u8:enableEnables or disables cutscene mode.
0x5DSAVE_HEROSaves Twinsen’s stance to a hidden variable.
0x5ERESTORE_HERORestores Twinsen’s stance from a hidden variable.
0x5FANIM_SET u16:animSets this actor’s animation.
0x60RAIN u8:durationMakes it rain.
0x61GAME_OVERKills Twinsen and ends the game.
0x62THE_ENDEnds the game and shows the credits.
0x63SET_CONVEYOR_ZONE u8:zone u8:flagEnables or disables a conveyor zone.
0x64PLAY_MUSIC u8:trackPlays a music track.
0x65SAVE_TRACK_TO_GAME_VAR u8:varSaves this actor’s move script track to a game variable.
0x66SET_TRACK_FROM_GAME_VAR u8:varSets this actor’s move script track from a game variable.
0x67ANIM_TEXTURE u8:enableEnable or disable texture animation.
0x68ADD_MESSAGE_OBJ u8:actor i16:msgSame as MESSAGE_OBJ.
0x69BRUTAL_EXITEnds the game without displaying the credits.
0x6ACOMMENTDoes nothing.
0x6BSET_LADDER_ZONE u8:zone u8:enableEnables or disables a ladder zone.
0x6CSET_ARMOUR u8:armourSets this actor’s armour value.
0x6DSET_ARMOR_OBJ u8:actor u8:objSets the armour value of another actor.
0x6EADD_HEALTH_OBJ u8:actor u8:lifeAdds health to another actor.
0x6FSTATE_INVENTORY u8:item u8:stateChanges the state/variant of an inventory object.
0x70AND_IF cond pcrel16Jumps if condition is false.
0x71SWITCHBegins a switch statement.
0x72OR_CASE pcrel16 condJumps if condition fails.
0x73CASE pcrel16 condJumps if condition succeeds.
0x74DEFAULTDoes nothing.
0x75BREAK pcrel16Jumps to offset.
0x76END_SWITCHDoes nothing.
0x77SET_SPIKE_ZONE u8:zone u8:damageEnables or disables a spike/trap zone.
0x78SAVE_BEHAVIOURSaves this actor’s behaviour index to a hidden variable.
0x79RESTORE_BEHAVIOURRestores this actor’s behaviour from the hidden variable.
0x7ASAMPLE i16:samplePlays a sound sample coming from this actor.
0x7BSAMPLE_RND i16:sampleLike SAMPLE but randomly alters the sample’s frequency.
0x7CSAMPLE_ALWAYS i16:sampleLike SAMPLE but plays the sample continuously.
0x7DSAMPLE_STOP i16:sampleStops the given sample if it is playing from this actor.
0x7EREPEAT_SAMPLE i16:sample u8:countLike SAMPLE but plays the given number of repeats.
0x7FBACKGROUND u8:flagSets or clears the “background” (don’t redraw) flag for this actor.
0x80ADD_VAR_GAME u8:var i16:valueAdds a value to a game variable.
0x81SUB_VAR_GAME u8:var i16:valueSubtracts a value from a game variable.
0x82ADD_VAR_SCENE u8:var u8:valueAdds a value to a scene variable.
0x83SUB_VAR_SCENE u8:var u8:valueSubtracts a value from a scene variable.
0x84NOPDoes nothing.
0x85SET_RAIL_ZONE u8:zone u8:enableEnables or disables a rail zone.
0x86INVERSE_BETARotates the actor to face the opposite direction.
0x87NO_BODYHides the model for this actor.
0x88ADD_MONEY i16:quantityGives money to Twinsen.
0x89SAVE_CURRENT_TRACK_OBJ u8:actorSaves the move script track of another actor to a hidden variable.
0x8ARESTORE_LAST_TRACK_OBJ u8:actorRestores the move script track of another actor from the hidden variable.
0x8BSAVE_BEHAVIOUR_OBJ u8:actorSaves the life script behaviour of another actor to a hidden variable.
0x8CRESTORE_BEHAVIOUR_OBJ u8:actorRestores the life script behaviour of another actor from the hidden variable.
0x8DSPYDoes nothing.
0x8EDEBUGDoes nothing.
0x8FDEBUG_OBJDoes nothing.
0x90POPCORNDoes nothing.
0x91FLOW_POINT u8:point u8:flowDisplays a particle animation at a point.
0x92FLOW_OBJ u8:actor u8:flowDisplays a particle animation on an actor.
0x93SET_ANIM_DIAL u16:animSets the animation to use when talking.
0x94PCX u8:imageDisplays a still image.
0x95END_MESSAGEDoes nothing.
0x96END_MESSAGE_OBJ u8:ignoredDoes nothing.
0x97PARM_SAMPLE i16:freq u8:vol i16:fbaseConfigures audio sample parameters.
0x98NEW_SAMPLE i16:sample i16:f u8:v i16:fbPlays an audio sample on this actor with custom parameters.
0x99POS_OBJ_AROUND u8:move_actor u8:destPositions an actor on or near another actor.
0x9APCX_MESS_OBJ u8:img u8:fx u8:act i16:msgShow a message on a still image background.

Fall types (undocumented values are invalid):

0.  actor cannot fall
1.  actor can fall
2.  actor can fall; stops any fall in progress

Movement modes (undocumented values are invalid):

0.  no movement
1.  controlled by player
2.  follow actor (opcode has extra param: uint8: actor to follow)
3.  invalid
4.  invalid
5.  invalid
6.  same XZ position as other actor
7.  MecaPenguin movement
8.  rail cart movement
9.  circle a point (opcode has extra param: uint8: point index)
10. circle a point while facing it (opcode has extra param: uint8: point
    index)
11. same XZ position and angle as other actor
12. car movement
13. car movement under player control

Hero stances (undocumented values are invalid):

0.  normal
1.  athletic
2.  aggressive
3.  discreet
4.  protopack
5.  walking with Zoe
6.  healing horn
7.  spacesuit normal (interior)
8.  jetpack
9.  spacesuit athletic (interior)
10. spacesuit normal (exterior)
11. spacesuit athletic (exterior)
12. car
13. skeleton

Collision types (undocumented values are invalid):

0.  can move through terrain bricks
1.  blocked by terrain bricks
2.  blocked by terrain bricks but can crawl through narrow passages

Buggy init types (undocumented values are invalid):

0.  no init
1.  init if needed
2.  force init

Effects for PCX_MESS_OBJ (undocumented values are invalid):

0.  no effect
1.  venetian blinds effect

Life script conditions

Opcode (hex)Name/syntaxDescription
0x00COL -> i8Actor this actor collided with (or -1 if none).
0x01COL_OBJ u8:actor -> i8Actor another actor collided with (or -1 if none).
0x02DISTANCE u8:actor -> i162D distance to another actor.
0x03ZONE -> i8Index of sceneric zone this actor is within (or -1 if none).
0x04ZONE_OBJ u8:actor -> i8Index of sceneric zone another actor is within (or -1 if none).
0x05BODY -> i8Model used for this actor.
0x06BODY_OBJ u8:actor -> i8Model used by another actor.
0x07ANIM -> i16Animation used by this actor.
0x08ANIM_OBJ u8:actor -> i16Animation used by another actor.
0x09TRACK -> u8Life script track active on this actor.
0x0ATRACK_OBJ u8:actor -> u8Life script track active on another actor.
0x0BVAR_SCENE u8:var -> u8Value of a scene variable.
0x0CCONE_VIEW u8:actor -> i16Distance to another actor, if they are within a 90-degree view cone.
0x0DHIT_BY -> i8Actor that last hit this actor.
0x0EACTION -> i8Action key was pressed.
0x0FVAR_GAME u8:var -> i16Value of a game variable.
0x10LIFE_POINT -> i16Health of this actor.
0x11LIFE_POINT_OBJ u8:actor -> i16Health of another actor.
0x12KEYS -> i8Number of keys.
0x13MONEY -> i16Money.
0x14HERO_STANCE -> i8Twinsen’s stance.
0x15CHAPTER -> i8Game chapter.
0x16DISTANCE_3D u8:actor -> i163D distance to another actor.
0x17MAGIC_LEVEL -> i8Magic level.
0x18MANA -> i8Twinsen’s mana points.
0x19ITEM_USED u8:item -> i8Item being used.
0x1ACHOICE -> i16Choice made in last dialogue.
0x1BFUEL -> i16Returns junk value; do not used (lba1 leftover).
0x1CCARRY_BY -> i8Actor carrying this actor.
0x1DCDROM -> i8Whether this is the CDROM build or floppy build.
0x1ELADDER u8:zone -> i8Whether a ladder zone is enabled.
0x1FRND u8:max -> u8Random number.
0x20RAIL u8:zone -> i8Whether a rail zone is enabled.
0x21BETA -> i16Current angle of this actor.
0x22BETA_OBJ u8:actor -> i16Current angle of another actor.
0x23CARRY_OBJ_BY u8:actor -> i8Actor carrying another actor.
0x24ANGLE u8:actor -> i16Angle from this actor to another actor.
0x25DISTANCE_MESSAGE u8:actor -> i16Distance from another actor, if within an angle suitable for conversation.
0x26HIT_OBJ_BY u8:actor -> i8Actor that last hit another actor.
0x27REAL_ANGLE u8:actor -> i16Angle from this actor to another, clamped.
0x28DEMO -> i8Whether this is the demo build.
0x29COL_BRICK -> i8Whether this actor collides with scenery.
0x2ACOL_BRICK_OBJ u8:actor -> i8Whether another actor collides with scenery.
0x2BPROCESSOR -> i8Whether running on an old processor.
0x2COBJECT_DISPLAYED u8:actor -> i8Whether this actor was drawn to the screen.
0x2DANGLE_OBJ u8:actor -> i16Angle from another actor to this actor.
Opcode (hex)Name/syntaxDescription
0x00EQUAL int_or_stringWhether the value is equal to the constant.
0x01GREATER int_or_stringWhether the value is greater than the constant. Not valid for strings.
0x02LESS int_or_stringWhether the value is less than the constant. Not valid for strings.
0x03GREATER_OR_EQUAL int_or_stringWhether the value is not less than the constant. Not valid for strings.
0x04LESS_OR_EQUAL int_or_stringWhether the value is not greater than the constant. Not valid for strings.
0x05NOT_EQUAL int_or_stringWhether the value is not equal to the constant.

Move scripts

Opcode (hex)Name/syntaxDescription
0x00ENDEnds this move script.
0x01NOPDoes nothing.
0x02BODY u8:modelSets this actor’s model.
0x03ANIM u16:animSets this actor’s current animation.
0x04GOTO_POINT u8:pointActor rotates to face the given point and waits until its animation takes it there.
0x05WAIT_ANIMWaits for the current animation to end.
0x06LOOP u8:init u8:remaining pcrel16Decrements remaining, jumps if non-zero, sets remaining to init if zero.
0x07ANGLE i16:angleActor rotates to the given angle and waits until the rotation completes.
0x08POS_POINT u8:pointInstantly teleports the actor to a point.
0x09MOVE_TRACK u8:idBegins a track block within this move script.
0x0AGOTO pcrel16Jumps to another part of the move script.
0x0BSTOPStops executing this move script.
0x0CGOTO_POINT_BACKWARDS u8:pointActor rotates to face away from the given point and waits until its animation takes it there.
0x0DWAIT_NUM_ANIM u8:count u8:zeroWaits for the actor’s animation to have played a number of times.
0x0ESAMPLE i16:samplePlays a sound sample.
0x0FGOTO_POINT_3D u8:pointActor moves to the given point, if it’s a 3D sprite.
0x10SPEED i16:speedSets the rotation speed of the actor.
0x11BACKGROUND u8:enabledEnables or disables the “background” flag for this actor.
0x12WAIT_NUM_SECOND u8:count u32:zeroWait for the number of seconds.
0x13NO_BODYSets this actor to have no model.
0x14BETA i16:angleRotates this actor instantly.
0x15OPEN_LEFT i16:distanceDoor slides to the left.
0x16OPEN_RIGHT i16:distanceDoor slides to the right.
0x17OPEN_UP i16:distanceDoor slides upwards.
0x18OPEN_DOWN i16:distanceDoor slides downwards.
0x19CLOSERestore door’s original position.
0x1AWAIT_DOORWait until door finishes moving.
0x1BSAMPLE_RND i16:samplePlays a sound sample with a random frequency adjustment.
0x1CSAMPLE_ALWAYS i16:samplePlays a sound sample forever.
0x1DSAMPLE_STOP i16:sampleStops a particular sound sample.
0x1EPLAY_VIDEO char[]:namePlays a cutscene video.
0x1FREPEAT_SAMPLE i16:countSets the number of repeats for SIMPLE_SAMPLE.
0x20SIMPLE_SAMPLE i16:samplePlays a sample according to REPEAT_SAMPLE and resets the repeat count to 1.
0x21FACE_HERO i16:negative_oneActor rotates to face Twinsen and waits until the rotation completes.
0x22ANGLE_RND i16:angle i16:negative_oneActor rotates to a random angle and waits until the rotation completes.
0x23COMMENTDoes nothing.
0x24WAIT_NUM_DECISECONDS u8:count u32:zeroWaits for a number of deciseconds (tenths of a second).
0x25DODoes nothing.
0x26SPRITE i16:spriteSets this actor’s sprite.
0x27WAIT_NUM_SECOND_RND u8:max u32:zeroWaits for a random number of seconds, up to a maximum.
0x28AFF_TIMERDoes nothing.
0x29SET_FRAME u8:frameSets the actor’s animation frame.
0x2ASET_FRAME_3DS u8:frameSets the actor’s 3D sprite animation frame.
0x2BSET_START_3DS u8:frameSets the start frame of the actor’s 3D sprite animation.
0x2CSET_END_3DS u8:frameSets the end frame of the actor’s 3D sprite animation.
0x2DSTART_ANIM_3DS u8:fpsStarts the actor’s 3D sprite animation.
0x2ESTOP_ANIM_3DSStops the actor’s 3D sprite animation.
0x2FWAIT_ANIM_3DSWaits until the actor’s 3D sprite animation ends or is stopped.
0x30WAIT_FRAME_3DS u8:frameWaits until the actor’s 3D sprite animation reaches the given frame.
0x31WAIT_NUM_DECISECONDS_RND u8:max u32:0Waits for a random number of deciseconds, up to a maximum.
0x32INTERVAL int16:intervalSets the interval between sample repeats.
0x33FREQUENCY i16:frequencySets the frequency for sample playback.
0x34VOLUME u8:volumeSets the volume for sample playback.