Menu

Python modding

ingen58

Python plugins (mods) have been added in R2.

Any Python script put in the folder "opl2_data/plugins/startup" is imported on startup.
Also an additional "%PY" command has been added to the PL2 scripting language, which allows you to import Python scripts from PL2 TXT scripts, from the folder "opl2_data/plugins".
Keep in mind that the "%PY" command is obviously not available in the original game, so by using it you make your TXT script invalid for the original PL2 game engine.

Another very important thing must be noted: Python is a general-purpose programming language, which means Python plugins for OPL2 can do anything any other program can: from downloading files from the internet to erasing entire folders. So "with great power, comes great responsibility", don't sue us if someone made a fake plugin which is really virus.

There are some example plugins here: http://sourceforge.net/projects/opl2/files/sample-plugins/

A tip to plugin writers: if your plugin needs some media/data files, here's how have them in the same folder (or subfolder) as the plugin and be able to open them with Python:

import os
dir = pl2base.getCurrentDir(__file__) # the current dir
file = open(dir + 'test.txt', 'r')

Also check out the "OPL2 manual" and "OPL2 API reference" here: https://sourceforge.net/projects/opl2/files/docs/

Recently OPL2 has added support to "hook" your own functions to OPL2 functions. This makes it easier to add functionality to existing features of the game by not making you rewrite the whole code of that feature and just add parts to run before or after it. More info in the API reference.

-PAGE UNDER CONSTRUCTION-


Related

Wiki: Home