Menu

PL2 Scripting Language

ingen58 crazycatz00

OPL2 is written in Python/C++, however, like the original PL2 game it supports a simple in-house scripting language, which is very similar to the BASIC programming language, but with only few dozen commands available for doing tasks related to GUI, camera controls, models, animations and lightning, as well as some general commands for defining and jumping to labels, going to other scripts, pausing script execution, etc.

OPL2 has a parser-interpreter which calls the corresponding Python function when encountering a PL2 script command.


  • Commands always begin with a percent sign (%)
  • Commands that have arguments always end with a semicolon (;)
    • Arguments are separated by colons (,)
    • Separating colons and semicolons must be present even if the arguments are empty
  • Commands are case-sensitive
  • Comments begin with a hash symbol (#)
    • May either be at the beginning of a line or after other commands
  • Some commands refer to "positions" in a room, which are embedded as points in room models. There are 3 that are in most rooms:
    • loc_pos00 - Normally near the center of the room, a "standard" location
    • loc_pos01 - Normally with something that one can sit on behind, such as a bed
    • loc_pos02 - Normally on top of something, such as on top of a bed
          Alternatively a different location\rotation in the room
    • A location that doesn't exist in the model will use (0,0,0)(x,y,z).
  • Tabs, not spaces, should be used for spacing
  • Filenames are specified without extensions, and are not case-sensitive
  • Commands are be encoded as ASCII text
  • Text shown to the player must be encoded in Shift-JIS (JASCII)
  • In-game variables are supported:
    • Variables are identified by a number, from between 0 and 255 (Higher numbers may cause random crashes)
    • Variables store numbers (as a signed long integer)
    • Default value is 0
    • They are global, and are shared between all script files
      • Variables 128 to 255 are also stored between game runs (in the pl2state.dat file)
  • In addition to commands, there are a few "statements"
  • Text to show the player is simply put where you want it to display; there is no special command

Statements

Statement Action Example
:<StrA:Label>; Label :next;
&<0=male, 1=female> Replaced with the character's name; If used in %n it is automatically colored
Defaults are "Oniiーchan" for male and "Sanae" for female
&0

Commands

Bool: 0 for False, 1 for True
Dec: Decimal Number
Flt: Floating Point Number
StrA: ASCII Text
StrJ: Shift-JIS Text

Command Function Example
Flow Control
%f<Dec:0=3D only, 1=Everything>,<Dec:Opacity>,<Dec:Frames>; Fade screen
[Notes]
%f1,255,120;
%G<StrA:.txt File>; Run script %Gtitle;
%i{*}<StrJ:Text>,<StrA:Label>; Define button that goes to label when clicked
[Notes]
%iTalk to Her,zen01;
%i*Talk to Her,zen01;
%I Show defined buttons and wait for one to be clicked
[Notes]
%I
%J<StrA:Label>; Go to label in current script file %Jnext;
%Q Exit the game %Q
%w<Dec:Frames>; Wait specified time %w100;
Variables
%S<StrA:Var Name>,<Operation>,<Dec:Number>; Set variable %S18,=,1;
%E<StrA:Var Name>,<Comparison>,<Dec:Number>,<StrA:Label>; Compare variable and goto Label if true %E18,=,1,h_mode;
Character Model Interactions
%ma<Dec:Char Index>,<Dec:Part Index>,<StrA:.tmb File>; Load item %ma0,1,imo_eye_01;
%mc<Dec:Char Index>,<0=Lower front, 1=Lower behind, 2=Mouth>,<Bool:Censor>; Censor area %mc0,0,1;
%md<Dec:Char Index>,<Dec:Part Index>; Remove item %md0,5;
%mh<Dec:Char Index>,<0=Upper UW, 1=Lower UW>,<0=On, 1=Half Off, 2=Off>; Toggle underwear state %mh0,1,1;
%ml<Dec:Char Index>,<StrA:.tmb File>; Load body; Removes all other items %ml0,imo_bodyA_00;
%mm<Dec:Char Index>,<StrA:.tsb File>; Load animation %mm0,event_01;
%mp<Dec:Char Index>,<StrA:Position>; Set position in room; If invalid, resets to (0,0,0) %mp0,loc_pos00;
%mr Resets animation to first frame; Also clears the text field (not including %n text) %mr
%mv<Dec:Char Index>,<Bool:Show>; Show or hide character %mv1,1;
Room Model Interactions
%mb<Dec:Room Index>,{<StrA:.tmb File>}; Load specified TMB to object; If no file specified, remove the object %mb1,room_03A;
%mb1,;
%mn<Dec:Room Index>,<StrA:.tsb File>; Load animation %mn1,room_03A;
%mV<Dec:Room Index>,<Bool:Show>; Show or hide room %mV0,0;
Lighting [Notes]
%lv<Dec:Light Index>,<Flt:X>,<Flt:Y>,<Flt:Z>; Sets the rotation of the directional light %lv1,1,1,1;
%la<Dec:Light Index>,<Flt:Red>,<Flt:Green>,<Flt:Blue>; Set the ambient color %la1,0.2,0.2,0.2;
%ld<Dec:Light Index>,<Flt:Red>,<Flt:Green>,<Flt:Blue>; Set the diffuse color %ld1,0.2,0.2,0.2;
%le<Dec:Light Index>,<Bool:Show>; Show or hide light %le1,1;
%ls<Dec:Light Index>,<Flt:Red>,<Flt:Green>,<Flt:Blue>; Set the specular color %ls1,0.8,0.8,0.8;
Camera
%c{<StrA:.tcm File>},<0=Once, 1=Repeat>; Runs camera file %ccam2_3,0;
%c,0;
%cl<Bool:Lock>; Lock or unlock camera %cl0;
%cp<StrA:Position>; Set position in room; Only works when camera is locked %cploc_pos00;
Audio
%M{<StrA:.ogg File>},0; Plays audio file as music; If no file specified, stop current music
Uses music volume and repeats
%MBGM01,0;
%M,0;
%MA{<StrA:.ogg File>},0; Plays audio file as environment sound; If no file specified, stop current ES
Uses effect volume and repeats
%MAse09,0;
%MA,0;
%MS{<StrA:.ogg File>},0; Plays audio file as sound effect; If no file specified, stop current SE
Uses effect volume and does not repeat
%MSse30,0;
%MS,0;
%o{<StrA:.ogg File>}; Plays audio file as voice; If no file specified, stop current voice
Uses voice volume and does not repeat
%o0002;
%o;
%oR0,<Dec:.ogg File 1>,<Dec:.ogg File 2>,<Flt:Time boundary>,<Flt:Time boundary>; Play both voice files with random delays, which is between the boundaries. See notes!
Uses voice volume and repeats randomly
User Interface Control
%g{<StrA:.psd File>}; Show image on-screen; Only shows the first layer
If no file specified, hide any currently showing image
%gtitle2;
%g;
%q<Bool:Enabled>; Enable or Disable Esc Key %q1;
%T<Bool:Show>; Show or hide title image %T1;
%w<Dec:Frames>; Wait specified time %w100;
%W<Bool:Show>; Show or hide text field %W1;
%WG<Bool:Show>; Show or hide character gauges [Notes] %WG1;
%X Close the dressing room
Only useful in ':SystemExit;', as code execution pauses when in the dressing room.
%X
%Z1; Open dressing room %Z1;
Text Output (into Text Field) [Notes]
%k Pause the text field (Press enter to continue); Does not clear the field. %k
%K Pause the text field (Press enter to continue), then clears the text field (not including %n text) %K
%n{<Color code>}{<StrJ:Text>}; Set header text; This appears on the first line, is usually a name, and is not cleared until %n is called again. Can color the text based on the color code. Does NOT print any text from before the color code (if there is one).
If the options aren't specified, this clears the text field.
%nText;
%n&0;
%n;
%r Line break %r
%R Clear the text field (not including %n text) %R
Unknown Commands
%cu<Dec>,<Flt>,<Flt>,<Flt>; ? (Calls sub_403920) %cu0,0.0,1.0,0.0;
%cv<Dec>,<Dec>; ? (Calls sub_403920) %cv0,1;

%f

  • Opacity can be any number from 0 to 512.
  • 0 is completely black
  • 255 is completely transparent (can see)
  • 512 is completely colored (Uses fade.psd; Normally white)

%i

  • There is a maximum of 8 buttons per set; Any more causes crashes.
  • If the first character of a button is "*", the button will be un-clickable. The * will not be visible.
  • When linking multiple menus together, use "%W0;" at the start of each menu list to prevent the dialogue box from flashing.

%oR

  • This command can only play audio files whose filename is 0000 to 9999.
    • It must have all 4 numbers, including zeros
    • All non-numbers are invalid
  • If file 1 is less then 0, it stops repeating sounds.
  • Time boundaries are in seconds; %oR1,2,0.5,1; means the delay will be in-between 1/2 a second and a second
  • It does not access the file until the delay is up; That means if the file does not exist you will not get the error until the delay is up.
  • This will crash if:
    • Run before a normal %o<StrA:File>; command
    • The last %o command was "%o;"
    • "%o;" is run while %oR is running

%q

  • When Esc is enabled and pressed, the game will go to the "SystemExit" label. If this label does not exist, it will load the "script.txt" script.
  • If the game is waiting at a %k or %K command, it will wait until enter is pressed before jumping.

%WG

Character gauges are controlled by two variables: 128 for the female bar and 129 for the male bar.
The bar is full if the var is 100 or higher.

Operations

Operation Action
= Sets the variable equal to the number
+ Adds the number to the variable
- Subtracts the number from the variable

Comparisons

Comparison True if
= The value is equal to the number
!= The value is not equal to the number
< The value is less then the number
> The value is greater then the number
>= The value is greater then OR equal to the number

Note that there is no "less then or equal to" comparison.

Character/Room Indices

  • These indices are a number that represents each character/room in-game.
  • Normally 0 is the girl and 1 is the boy.

Lighting

  • Values for Red, Green, and Blue are numbers between 0 and 1.
  • Lights do not affect rooms; Vertex colors (stored in the room TMB) are used for shadows in rooms.

Part Indices

  1. Body (Use %ml instead of %ma to load the body)
  2. Eyes
  3. Upper Underwear
  4. Lower Underwear
  5. Socks
  6. Upper Clothes
  7. Lower Clothes
  8. Head Item
  9. Face Item
  10. Neck Item
  11. Arm\Hand Item
  12. Shoes
  13. Hair

Text Output

  • A '%n;' is not necessary unless a "%n<text>;" line was before it.
  • A '%r' is helpful when you don't want a word to get cut in half. Alternatively, if the 25th character is a space, you don't have to change anything because of the game's auto-cut function. But if the 25th character is the last letter in a word, then you have to take out the space entirely, or the next line will start with that space.
  • If '%K''s aren't used, text will run into the next dialog's text. (It won't stop to let you read it.)

Color Codes

Character Color Hex Code
 Blue 01
 Pink 02
  • Hold alt and type the hex code using the numeric pad to insert these characters
    • Not all text editors can insert or display these characters!

Related

Wiki: Home
Wiki: PL2 File Format Specifications

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.