Jump to content

Yanzari's-Modder/SRB2Python

From SRB2 Wiki
This article or section is incomplete. It doesn't have all of the necessary core information on this topic. Please help the SRB2 Wiki by finishing this article.

SRB2Python is a branch of SRB2 2.0, with Python scripting capabilities. This means that SRB2 can now be scripted with Python for greater control and interactivity. Right now it is at a very early alpha stage, with a WIP release in the SRB2MB

Discussion topic and SRB2Python prototype can be found here

New console commands

openpyconsole: Opens a GUI console for modifying game data in real time (not available on PowerPC builds of SRB2Python).

python '[code]': Runs a single line of Python. Must be in quotes.

Example

Say you wanted to make your rings 9999 for whatever reason in Single Player. The code for this would look like:

player = srb2.get_player(0)

player.health = 10000

player.mo.health = 10000

srb2.set_player(0,player)

Let's go over what this does line-by-line:

Line 1: The variable 'player' is defined to be a reference to the first player in the game.

Line 2: The player's ring count is set to 9999. (Note that health = 1 + rings)

Line 3: The player's map object ring count is set to 9999.

Line 4: The modified player data is pushed back into the game state. If you do not do this, no player state changes will be reflected.

Another caveat: Upon SP death, the player reference is invalid and a new one has to be fetched.

Another another caveat: Netgames will lag like no tomorrow if you try pulling something like this as the host. Doing it as a client has not been tested, but it likely will not work.

Documentation