I start the next step with the almost empty script opened in the game as I create my scripts 99% directly inside the game.
(Hint: While having started a match with an own script hitting F12 on the keyboard opens the script editor, making it possible to edit it ingame. Pressing Ctrl+G shows the log.)
If you want to edit your script outside of the game you will need to restart ManiaPlanet after any change as it caches files constantly and it therefore won’t see changes in the code.
I would like to be able to walk around the map needing me to be spawned.
For this act I will use the
PlayLoop label of the ModeBase script.
Each label defined in the ModeBase can be used as a point to insert our own code.
Label locations are defined via
---Name--- and the actual code for the label is surrounded by a structure like this:
// Our code
--- means that only the most derived implementation of the label will be used while
+++ uses every implementation. (Other scripts could extend our own script leading to more derivation levels.)
PlayLoop is the place where you can insert code that’s executed all the time during the actual gameplay. There are other labels like for example
StartRound in which it’s possible to prepare the used resources or
EndMatch in which you will probably announce the winner of the match.
PlayLoop I loop through all players in order spawn or unspawn them if needed by checking their
SpawnStatus and possible team change or spectating requests.
For spawning I will use an own extra function in order to keep the code more clean as it might get more complex in the future.
Furthermore I use the file
SM.Script.txt by Nadeo for the actual spawning action, the script needs to be included with the
#Include directive first.
#Include "Libs/Nadeo/ShootMania/SM.Script.txt" as SM
This makes it possible to access functions declared in this script via the namespace “SM”.
Currently the players get simply spawned in the first spawn block I can find.
In order to be able to move around 3 more statements are needed.
UseClans = True;
Activates a team based game play which will be needed for Defusing.
StartTime = Now;
StartTime defines the begin of the match. Players can only spawn and perform actions after the match has started, which basically means that
Now needs to be bigger than or equal to
UIManager.UIAll.UISequence = CUIConfig::EUISequence::Playing;
Let players move around with their characters. There are other sequences like for example the Intro or the Podium sequence during which the players will only be able to watch mediatracker clips.
After adding all this stuff and hitting “Save and Test” the script is saved, the match restarted and my character is actually being spawned. I’m able to move around! Yeeyy!
You can find the current version of the script here: Defusing1.Script.txt
I’ve tried to add meaningful comments. ;)