-
Notifications
You must be signed in to change notification settings - Fork 31
MissionScriptsDynamic
Missions can be easily extended with custom scripts to add special events to them. Each missions script is located in \Maps\map_name\map_name.script
file, which can be opened in any plain text editor (e.g. Notepad). Scripts are written in PascalScript language (syntax is very similar to usual Pascal).
Script has 4 ways of interacting with the game - Events, States, Actions and Utils. Events get called by the game when they happen. States are values that can be queried from the game. Actions are way to tell the game what to do. Utils contains some usefull functions for different purposes. Scripts get verified on mission load and any errors are output in a message to a player and logged into map_name.log.txt
file.
Script file consists of several parts:
//Global constants section, accessible from any place in the script.
//Useful to make parameters easy to change in one place.
const MY_CONSTANT = 7; //by convention constants are written in upper case
//Global variables section, accessible from any place in the script and stored in game memory
var
I: Integer; //variable number
A: array [0..3] of Boolean; //array of 4 booleans accessible as A[0], A[1] etc.
//Event handler, when the event happens ingame this function gets called
procedure OnHouseBuilt(..); //Each event has different input parameters list
var //Local variables, they exist only within this procedure
L: Integer; //variable number
begin
//Event code
L := 7; //assignment of number to a variable
Actions.ShowMsg(L,'hello'); //Calling a games action with 2 parameters: L and a string 'hello'
end;
//Event handler for "tick" event, which happens 10 times per second (on each game logic update).
procedure OnTick;
begin
//Code here
if States.GameTime = 60 then //Check game time and show a message
Actions.ShowMsg(0,'<>'); //<> is markup to fetch text ID 3 from LIBX translation file
end;
Here is Battle Tutorial script explained:
procedure OnPlayerDefeated(aIndex: Integer);
begin
if aIndex = 2 then Actions.ShowMsg(0, '<$2>');
if aIndex = 3 then Actions.ShowMsg(0, '<$3>');
if aIndex = 4 then Actions.ShowMsg(0, '<$4>');
end;
procedure OnTick;
begin
if States.GameTime = 20 then
Actions.ShowMsg(0, '<$1>');
end;
Above line means that when PlayerDefeated
event comes from the game, we check the index of the player that was defeated (aIndex) and issue a command to show certain message to specified player (0, who is human). Also, each tick we check the games time and on tick 20 (2 seconds from mission starting) we show another message. Message text is retrieved from the mission's .LIBX file using the markup <$123> (fetches text ID 123 from LIBX), meaning it will be in the player's own language if a translation has been made.
- Events list
- Actions list
- States list
- Utils list
- Types list
- Lookup tables (unit/house/ware types)
- Scripting tutorial
- Scripting hints
- Language reference: Delphi basics (note: our scripts don't have all the features of Delphi, but this is still a useful reference)