Scenario Scripts

Scenario scripts can control a general mission sequence or define specific features such as rejoins or special player placement. For documentation of the scripting language see C4Script.

Callbacks in Scenario Scripts

At the start of each round, before the players have joined, the engine calls the function "Initialize" in the scenario script, if defined. Within this function a scenario can perform special object placement or start the scenario scripting sequence.
func Initialize()
{
  Message("Hallo"); 
  CreateObject(HUT1,250,200,0);
  ScriptGo(1);
}
Sequential scripting: at the start of a round the internal script counter is set to 0. If sequential scripting has been started with ScriptGo, the counter is increased by one every ten frames and the corresponding script function is called in the scenario script, if defined.
func Script26()
{
  Message("Diese Funktion wird nach 260 Frames ausgeführt.");
}
The script counter can also be manually adjusted using goto() to jump to certain counter positions.
After joining a new player the engine calls the function InitializePlayer in the scenario script for that player. This function is called after the basic player objects as defined in Scenario.txt have been placed, so a preliminary starting position has been selected and the player's crew and starting material and buildings are present. In this function, you can now perform more special initial placement.
func InitializePlayer(iPlr)
{
  // Eine Meldung für diesen Spieler
  Message( "Spieler Nr. %d ist beigetreten", 0, iPlr );
  Sound("Ding");
  // Ersten Clonk des Spielers doch an einer anderen Stelle starten lassen
  SetPosition( Random(LandscapeWidth()), Random(LandscapeHeight()), GetCrew(iPlr));
}
When a player leaves a round, the function RemovePlayer is called.
If a round is ended through the game i.e. by player elimination, fulfillment of all goals as defined in Scenario.txt section [Game]), or by the script command GameOver, the engine will call the function OnGameOver in the scenario script. This will not be called if the round was aborted.
func OnGameOver()
{
  Sound("Trumpet");
  // Hier bietet sich die Möglichkeit für spezielle Rundenauswertung in der Log-Datei Clonk4.log
  Log("Vermögen von Spieler 1: %d", GetWealth(0));
}
Sven2, April 2002