For information about course materials see this thread. Whatever mod folder you use make sure you start with an empty campaign_script. The requirements for this class are that you be able to set up your own mod folder and be familiar with the structure.
Some terms you need to be familiar with:
Monitor
This simply starts the script by checking (monitoring) whether or not the events and conditions you have listed have happened. The most common use is monitor_event which is what we will mostly be working with, but you can also use monitor_conditions. When a monitor of either type is called, it loops through the conditions to determine a true/false value. If the value returned is true then the commands will run.
Command
Something you want the game to do, such as add or remove money or create units. There is a list of valid commands in the Docudemons but you can also use console_command and run the commands that you would normally run through the shell.
Event
Something that happens during the course of gameplay. Most of the time this is related to factions, settlements, and characters but can also be used to check things like when a counter changes or a building gets constructed.
Condition
Conditions are the core of your script. Improperly listing conditions will cause your script to fail. Consider this like a true/false question. If the result of the listed conditions is True, then the commands in the script fire.
Counter
This is the only variable we have to work with, and you can only use numbers. You use counters as extra conditions so that you can expand your options when firing commands. Counters must be declared in the top of your script and can be set to a static number or moved up and down using the inc_counter command, or set to a specific number using the set_counter command.
EventCounter
Similar to a Counter, but when used in the EDB or Traits files it only returns a true/false value. Anything other than 0 returns True to the script. This confuses some people but consider it like this: With an event there are only two options; either the event has happened, or it has not happened.
Local
This is simply used to determine whether the character, faction, or settlement belongs to the player or to the AI. If something is Local it belongs to the player, if not then it belongs to an AI faction.
Not
Usually when you are checking conditions you are looking for something that returns a True value, but occasionally you will want to know when something is False. This is where the Not value comes in.
Export
Not all Events can be used with all Conditions. When an Event fires, the game engine puts several things into memory for that particular monitor such as the faction type or the settlement name or details about a character. Those items that are placed into memory are called Exports and are listed in the Docudemons for each Event.
Trigger Requirement
Each condition will have a list of Trigger Requirements, these are items that must be available from the event for the condition to be able to check them. If the Event does not Export the Trigger Requirement, then you cannot use the Condition inside the monitor.
Now its time to write your first script. When I am writing a new script I use the same process every time. What do I want to happen (command), and when exactly do I want it to happen (event + condition). First find the command or the console_command you want to run, and run it inside a generic monitor that you KNOW has valid conditions. The reason I always do this is so that if something doesn't work properly then I know its the command syntax and not the monitor itself. For this I usually use:
FactionTurnEnd is simply the end of a factions processing turn. We throw the FactionIsLocal condition on the end of it so that the monitor only fires once, for whatever faction the player happens to select. If we did not include a condition the script would fire true and run the command up to 31 times, once for each faction in the game. If we wanted to check a specific faction then we would do it like this:Code:monitor_event FactionTurnEnd FactionIsLocal commands go here end_monitor
Note that we have included the FactionType condition, followed by a valid faction name. If you compare the Export of FactionTurnEnd you will see that it exports faction and that FactionType has a trigger requirement of faction. If we wanted to check every faction except the faction the player is using, then we would use the not command like this:Code:monitor_event FactionTurnEnd FactionType england commands go here end_monitor
For our first script we are going to write a money script. Kingdoms has a scripting command for adding money to a faction, M2TW does not so we have to do it through a console_command:Code:monitor_event FactionTurnEnd not FactionIsLocal commands go here end_monitor
console_command add_money england, 2000
So our entire monitor will look like this:
With this script, every time the player clicks the TurnEnd button England will have 2000 added to its treasury. You can verify this by playing as England and just clicking TurnEnd a few times. But a money script that only adds money to 1 faction every turn isnt really much good. We need to add more conditions to get it tweaked exactly how we want it. For this we will have to build a monitor for each faction.Code:monitor_event FactionTurnEnd FactionIsLocal console_command add_money england, 2000 end_monitor
This will fire for each faction we build a monitor for, no matter if the faction belongs to the player or the AI.
If we want it to only fire for the AI factions and not for the player, then we add another condition by using AND and NOT.Code:monitor_event FactionTurnEnd FactionType england console_command add_money england, 2000 end_monitor monitor_event FactionTurnEnd FactionType sicily console_command add_money sicily, 2000 end_monitor monitor_event FactionTurnEnd FactionType hre console_command add_money hre, 2000 end_monitor
Now we are getting somewhere. Our money script will add_money 2000 to each faction we build a monitor for, but will not give any help to the player. But there are no real options included, it will just happen every turn. To get some real flexibility we have to add a few more conditions and monitors. If a faction doesnt need help, then there is no point adding money to their treasury. Likewise some factions may need more help than others.Code:monitor_event FactionTurnEnd FactionType england and not FactionIsLocal console_command add_money england, 2000 end_monitor monitor_event FactionTurnEnd FactionType sicily and not FactionIsLocal console_command add_money sicily, 2000 end_monitor monitor_event FactionTurnEnd FactionType hre and not FactionIsLocal console_command add_money hre, 2000 end_monitor
Your task will be to build at least 4 monitors for a single faction to either add or subtract money based on their current condition. Some of the conditions you can use are:
Treasury
LosingMoney
Feel free to mix and match other conditions if you wish, and please post your scripts in spoilers.

















