Results 1 to 9 of 9

Thread: -The Long Road- Campaign Script System

  1. #1

    Default -The Long Road- Campaign Script System

    - The Long Road Campaign Script System -
    =====================================================================

    - Introduction -

    Since I started modding about 6 months ago I’ve been very focused on the possibilities generated by the campaign script. Having recently released a beta version for TLR 3.0 I decided to make some tutorials on how the events work. After a gentle nudge from St. Polycarpe I’ll re post that tutorial here. I will however be elaborating on the actual skeleton structure since the event system will only function within a similar script. Which will make this into a more in depth ( read longer) article and you’ll probably want at least some basic knowledge of scripting.

    If you’re not interested in all the technicalities but do want to help TLR by making some events, skip to the second part of this tutorial.

    One final note; this mod is for M2TW and since I couldn’t get “pure” choice events to work for some inexplicable reason ( and believe me I have tried ) it works with a work around that’s based on the Toggle left/right buttons.

    Mod Vision:
    What I was trying to achieve was a mod which gave the player a lot more control over his realm and random events that affected/were affected this internal balance of things. The map has therefore been divided into 105 scripted counties and kingdoms etc that play a major role in the campaign.

    The current version will be containing 40 events per county and to see how that all works without interfering with eachother will be explained now.

    Part 1:
    The Campaign Script

    The first thing anyone will discover modding the campaign script is that it slows down things especially turn ends. Mainly because of all the monitors that are run in very close succession and probably overload the calculating capacity of the game ( I think that’s what happens at least).Therefor I tried to make a script that only runs when I need it to, a lot of trial and error and bad ideas later this is what I came up with: Ladies and gentlement I proudly present

    The Long Roads Loop Script!

    An example bare skeleton script with just 3 factions, England, France and Slave
    Spoiler Alert, click show to read: 

    script

    Start up/ Counter Declaration

    Declare counters:
    declare_counter englandCurrent
    declare_counter franceCurrent
    declare_counter slaveCurrent
    declare_counter localCurrent

    Start up:
    if I_LocalFaction == england
    set_counter englandCurrent 2
    set_counter localCurrent 2
    end_if

    if I_LocalFaction == france
    set_counter englandCurrent 2
    set_counter localCurrent 2
    end_if

    This part is pretty basic really, It sets the counters correctly so the right loops run in turn 0
    Master loop:
    while TrueCondition
    The difference with a normal script however is that ours hits the while True condition ( master loop) and remains forever looping that. Subsequently the most important while loop of them all, keeps the script going, as opposed to having it stop after the game went over it once..

    Spoiler Alert, click show to read: 

    Local player loop :
    This loop which will contain all the monitors for the local player, will remain from the local turn start until the
    player ends his/her turn. All the more mundane monitors etc are included in this part of the script.
    This part runs regardless of the what faction is being played by the local player.
    while I_CompareCounter localCurrent > 0

    Spoiler Alert, click show to read: 

    Faction Specific One Time Loops:
    The one time loops, like the name says only run 1 time ( at the start of the turn. and don’t run again until the next. These are faction specific, so the England one will only run when the local faction is England, ( same for France obviously).
    This space in the script is reserved for nation specific events (e.g. Normandian claim to the English crown, etc ) But also compares/processes part of the county script.

    Spoiler Alert, click show to read: 

    One time events in the case that England is the local faction.
    Code:
    while I_CompareCounter englandCurrent == 2
    set_counter englandCurrent 0
    end_while
    One time events in the case that France is the local faction.
    Code:
    while I_CompareCounter franceCurrent == 2
    set_counter franceCurrent 0
    end_while

    Local Player specific loop:
    Spoiler Alert, click show to read: 

    Local Player specific One Time Loop:
    This is where the bulk of the random events go. as mentioned in the intro TLR uses a lot of choice events, these events are triggered during the slave turn ( see later) .
    for more info on how the actual events work I’ll have to refer you to the second part of this tutorial which deals with event making.
    These events are in essence faction neutral.
    Code:
    while I_CompareCounter localCurrent == 2
    set_counter localCurrent 1
    end_while
    Local loop ender:
    This just sets the counter so that the loop stops running when you end your turn
    Code:
    monitor_event FactionTurnEnd FactionIsLocal
    set_counter localCurrent 0
    end_monitor


    end_while


    England AI loop :
    A loop that contains all the monitors you want to apply to the English bot player.
    while I_CompareCounter englandCurrent > 0
    Spoiler Alert, click show to read: 

    England AI one time loop:
    Used to process parts of the script and to inc/decrease counter values
    Code:
    while I_CompareCounter englandCurrent == 2
    set_counter englandCurrent 1
    end_while
    Ai England loop ender:
    Ends the loop
    Code:
    monitor_event FactionTurnEnd FactionType england
    set_counter englandCurrent 0
    end_monitor

    end_while


    France AI loop:
    while I_CompareCounter franceCurrent > 0
    Spoiler Alert, click show to read: 

    France AI one time loop:
    Code:
    while I_CompareCounter franceCurrent == 2
    set_counter franceCurrent 1
    end_while
    Ai France loop ender:
    Code:
    monitor_event FactionTurnEnd FactionType france
    set_counter franceCurrent 0
    end_monitor

    end_while

    Slave Loop:
    while I_CompareCounter slaveCurrent > 0
    Spoiler Alert, click show to read: 

    Slave AI one time loop:
    Contains a whole lot of if statements that trigger all sorts of things by setting counters
    Code:
    while I_CompareCounter slaveCurrent == 2
    set_counter slaveCurrent 1
    end_while
    Ai Slave loop ender:
    Code:
    monitor_event FactionTurnEnd FactionType slave
    set_counter slaveCurrent 0
    end_monitor


    end_while

    Loop Start triggers:
    Spoiler Alert, click show to read: 

    monitor_event FactionTurnStart FactionType england
    set_counter englandCurrent 2
    if I_LocalFaction england
    set_counter LocalCurrent 2
    end_if
    end_monitor


    monitor_event FactionTurnStart FactionType france
    set_counter franceCurrent 2
    if I_LocalFaction france
    set_counter LocalCurrent 2
    end_if
    end_monitor


    monitor_event FactionTurnStart FactionType slave
    set_counter slaveCurrent 2
    end_monitor

    end_while

    wait_monitors
    end_script
    Last edited by ilmrik; July 24, 2011 at 03:28 PM.

  2. #2

    Default Re: -The Long Road- Campaign Script System

    Part 2:
    Event making

    As mentioned in the Beta tester forum I would be making a tutorial on how the events on the TLR work so hopefully some active souls can help by diversifying the events.
    The events that are included in the Beta while in essence fine tend to be rather generic. But with a bit of practice however you will be able to help us by making your own and if enough people pitch in significantly increase the flavor of TLR as well as lessen the burden on Alec and myself.

    Anyway first things first!

    What kind of events is he talking about?

    Well to be honest pretty much anything goes! However try to keep a sense of medieval realism in them, the matters at hand have to be big enough for a king to be asked to deal with them. I have to admit that the events I put in are sometimes very borderline but still, a lot of great minds and historical knowledge out there. I’m sure you can do better!

    To give an example of some of the events that are included.
    Noblemen pledge loyalty
    Noblemen defy you openly
    Large tournament proposed
    Market district fire
    Trade booms

    etc
    all these events are both choice events as well, so you'll have to decide how to deal with the issue which in turn will change certain balances in the counties and in your nation.

    How are these events triggered ?

    Well these events are triggered during the slave turn, which is basically all you need to know about it really! A bit more info will be given later on.

    How many are there ?

    At the moment there are 40 events linked to every county ( well the ones I already went over which are about 30 )
    20 of these positive/ 20 of these negative
    divided into 10 Noble events and 10 Merchant events
    those 10 are divided into 1 huge/ 3 large / 3 medium / 3 small events

    this might be altered later to make room for some Innovative/ conservative events etc, but that's totally unimportant right now. we’ll see how it evolves and they are playable right now.

    How do they work?

    Ah, now were getting to the crunch. Well the easiest way to explain is by putting in an example of one!

    Code:
     ;Flanders Noble Negative Huge Event: Noblemen Openly defy the king's law
    
     if I_CompareCounter FlandersNobNHuge == 1
          historic_event FLANDERS_NOB_N_HUGE1 true
        end_if
    
        while I_CompareCounter FlandersNobNHuge == 1
    
             monitor_event ButtonPressed ButtonPressed hud_select_prev_item_cycle
             ;Rally the support in neighbouring lands to teach them a lesson
                inc_counter FlandersMerchantsFeudal -10
                inc_counter LocalWeakMinded -4
                inc_counter FlandersHappy 10
                console_command add_money -15000
                inc_counter LocalMerchantsFeudal -3
                console_command add_population Antwerp -125
                console_command add_population Bruges -125
                set_counter FlandersNobNHuge 0
             end_monitor
    
             monitor_event ButtonPressed ButtonPressed hud_select_next_item_cycle
             ;Turn a blind eye in return for their continued support
                inc_counter FlandersMerchantsFeudal 8
                inc_counter LocalMerchantsFeudal 6
                inc_counter FlandersHappy -80
                inc_counter LocalWeakMinded 4
                console_command add_money -3000
                set_counter FlandersNobNHuge 0
             end_monitor
    
        end_while
    Tadaaa there it is!
    Huh?! didn't he say it was going to be easy ? Yes I did, so lets go over that again in slow motion shall we!
    -important note- the script is always read top to bottom by the game

    Code:
    ;Flanders Noble Negative Huge Event: Noblemen Openly defy the king's law
    
    so now this is just a comment to help me remember what it's all about:
    every line of text denoted by an ";" will not be read into a script.
    This comment obviously just tells me what categories the events falls under and what happens.
    
       if I_CompareCounter FlandersNobNHuge == 1
    
    Now  this is a lot more  important, and includes a few important tools to the  scripter ( don't  worry I'll be adding a docudemon of important things  later on )
    the first thing we see is an "if" followed by a "condition check". What does this all do then?
    well  simply put it checks  whether or not the conditions are true, if they  are it will execute all  the commands following it, if not if will skip  over them to the end_if
    
    A  bit more information on  the condition, Counters are what the game uses  to store all sorts of  data to use them again later, in this case the  counters name is  FlandersNobNHuge,
    this  counter is part of a  group of counters that is used to trigger the  events. If the event is  triggered the value of it is changed from 0  -> 1 during  the slaves  turn.
    now  at this moment were  asking to compare the value of the counter to a  fixed number ( in this  case 1 )  if it is 1 we want this event to run!  if it is not we don't  want anything to happen.
    
        historic_event FLANDERS_NOB_N_HUGE1 true
    This  is what the game is  supposed to do if the value of the counter is 1,  it's pretty straight  forward in this case, if just gives you an historic  event scroll, in  this case the name of the event is  FLANDERS_NOB_N_HUGE1,
    It's name is linked to the text.string files so the game knows what text is supposed to go onto the scroll.
    
      end_if
    Essential part of the “if” statement
    
    while I_CompareCounter FlandersNobNHuge == 1
    
    A “while loop” is in many ways similar to the "if" statements but it's function is different,
    what happens: the game reaches the “while” statement and checks the condition,
    (just for your information, since you won't have to change it really it's part of the skeleton.)
    if false it skips directly to the end_while ( see below)
    if  it is true if will read  everything in between until it reaches the  end_while, if at this point  the condition is still true it will jump  back to the initial while,  essentially looping over a particular part of  script until something  changes. This in reality pauses the script.
    Okay so the script is now looping merrily as long as the counter "FlandersNobNHuge" remains at value 1, that’s a bit silly!
    
    well thats where the monitors come in!
    we  have 2: pushing the  toggle right button and pressing the toggle left  button ( anyone who  has had a choice event will know what they are  about)
    knowing  how they work isn't  very important really just remember doing one or  the other will  activate the command lines in the monitor!
    
      monitor_event ButtonPressed ButtonPressed hud_select_prev_item_cycle
    A description of the monitor, don't worry about it you won't have to change it
    
             ;Rally the support in neighbouring lands to teach them a lesson
    so another comment, no scripting value
    
             inc_counter FlandersMerchantsFeudal -10
                inc_counter LocalWeakMinded -4
                inc_counter FlandersHappy 10
                console_command add_money -15000
                inc_counter LocalMerchantsFeudal -3
                console_command add_population Antwerp -125
                console_command add_population Bruges -125
    A bunch of effects, we'll get to those in the step by step event builder
    
     set_counter FlandersNobNHuge 0
    A  very important command,  the tech savvy will immediately realise this  means the value of  "FlandersNobNHuge" is no longer 1 and so the next  time we hit the  end_while we will move on in the script,
    or in human words,
    the script pauses until I decide how to react by pressing the appropriate toggle, then it continues.
    
    end_monitor
    Similar to the end_if / end_while
    
          monitor_event ButtonPressed ButtonPressed hud_select_next_item_cycle
             ;Turn a blind eye in return for their continued support
                inc_counter FlandersMerchantsFeudal 8
                inc_counter LocalMerchantsFeudal 6
                inc_counter FlandersHappy -80
                inc_counter LocalWeakMinded 4
                console_command add_money -3000
                set_counter FlandersNobNHuge 0
             end_monitor
    
    Just the same as the other one, but with the effects if you react differently.
    
    end_while
    Essential part of the while loop
    Okay, so that’s how it works, how nice... but how do I make my own events ?


    Well here comes!
    The great step plan!

    Step 1

    Decide which event you want to flavorise. Make sure no one else already altered it or is altering it.
    I'll be starting a separate thread to coordinate everything, this one will stay open for questions etc
    Ok, no one else on it, it's all yours then

    So make the skeleton. I'll be adding a lists of counter names etc,

    Say I decided to go for a small negative merchant event in Brittany
    so the counter name would be BrittanyMerNSmallA ( or BrittanyMerNSmallB or BrittanyMerNSmallC )
    and the correct event name would be BRITTANY_MER_N_SMALL_A1
    Getting these names correct it vital, an incorrect/non existant event name will cause CTD’s when the game tries to run it, an incorrect counter name and the event will never trigger.

    Code:
        if I_CompareCounter BrittanyMerNSmallA == 1
          historic_event BRITTANY_MER_N_SMALL_A1 true
        end_if
    
        while I_CompareCounter BrittanyMerNSmallA == 1
    
    
             monitor_event ButtonPressed ButtonPressed hud_select_prev_item_cycle
    
                set_counter BrittanyMerNSmallA 0
             end_monitor
    
    
             monitor_event ButtonPressed ButtonPressed hud_select_next_item_cycle
    
                set_counter BrittanyMerNSmallA 0
             end_monitor
    
        end_while
    Easy enough but make sure you get it right, no typo’s etc, failing to do so induces terrible headaches and delirium!

    Step 2:

    Decide what your event actually is, Perhaps a fire, serious raiding parties, Border disputes etc etc
    Either way this is when you start thinking about the impact your event has and how to represent it.

    In this example I'll be going for a famine due to prolonged bad harvests

    there are 3 places where these commands go in the full skeleton we made earlier
    Code:
        if I_CompareCounter BrittanyMerNSmallA == 1
          historic_event BRITTANY_MER_N_SMALL_A1 true
    
        XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
                      Intitial event effects (optional)
               XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    end_if
    
    while I_CompareCounter BrittanyMerNSmallA == 1
    
    
             monitor_event ButtonPressed ButtonPressed hud_select_prev_item_cycle
    
             AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                    Choice A effects
                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    
    
                set_counter BrittanyMerNSmallA 0
             end_monitor
    
    
             monitor_event ButtonPressed ButtonPressed hud_select_next_item_cycle
    
                BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
                    Choice B effects
                BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
    
             set_counter BrittanyMerNSmallA 0
             end_monitor
    
        end_while
    The initial effects are optional for events like say,
    cathedral fire!
    whatever you decide the cathedral will be damaged.

    Choice A and B are pretty self explanatory.

    Now these effects are a list of commands,
    I'll first add the interesting ones down here, with some extra information

    Spoiler Alert, click show to read: 

    console_command add_money

    example:
    console_command add_money 500

    effect:
    well it adds the specified amount of money to the treasury of the local player
    notes:
    the value can be negative.

    console_command add_population

    example:
    console_command add_population Antwerp_Province 120

    effect:
    well it adds the specified amount people to the city specified
    notes:
    Value can be negative
    Province names can be found in the docudemon

    console_command set_building_health

    example:
    console_command set_building_health Antwerp sea_trade 23

    effect:
    damages the building in the tree specified, in this case setting it to 23% health
    notes:
    Value is a percentage and so between 1-100
    building tree names can be found in the docudemon

    inc_recruit_pool and set_recruit_pool

    examples:
    inc_recruit_pool Coimbra_Province 2 Dismounted Portuguese Knights

    and
    set_recruit_pool Coimbra_Province 2 Dismounted Portuguese Knights


    effect: well pretty much as advertised, inc increases the available number by 2; set sets the available number to 2

    notes:
    if the unit isn't naturally available already you can't increase/set the pool
    list of usable units included in the docudemon


    create_unit

    example:
    create_unit Antwerp Flemish_Pikemen , num 1, exp 1, arm 0, wep 0,

    effect: creates one unit of Flemish pikemen with 1 exp in Antwerp
    notes:
    unit syntax is different to the one in the inc/set recruit pool
    settlement name is the name of the city not of the province


    inc_counter
    okay, this is a very important one

    example:
    inc_counter FlandersMerchantsFeudal 8

    effects: increases the value of the counter FlandersMerchantsFeudal by 8

    what does that mean?
    As said earlier counters are what the script uses to keep track of information, this counter is no different:
    The FlandersMerchantsFeudal counter in the example keeps track of the balance of power between the merchants and the feudal lords in Flanders,
    The lower it goes the more power the merchants have , the higher the more power the feudal lords have.

    Several counters for you to play with have been included in the script and affect the way the world is shaped.


    Full list of supported counters for Flanders:
    (note all counties have these counters, just substitute Flanders with the appropriate county name see docudemon)


    FlandersHappy
    This is a catch all counter, depicting the happiness/prosperity of the region.
    the scale goes between -200 and +200



    FlandersMerchantsFeudal
    FlandersConservativeInnovative
    FlandersTraditionalIndustry
    FlandersNavalLand
    FlandersRoyaltyFreeCities

    these all work similarly to the Merchants Feudal counter in the example,
    a negative value gives more power to the first party, a positive value to the second
    value between -15 and +15

    If any of these counters hit certain thresholds it will effect the region
    eg

    if FlandersHappy goes over 175 the region will be very happy and get bonuses in health, trade, recruitment slots, upkeep slots and speed/number of units available
    if FlandersMerchantsFeudal goes under -10 if will gain extra trade fleets and trade boosts
    etc

    A list of the "local" counters

    LocalPious

    keeps track of how good a Christian the player is,
    value between 0 and 500
    hitting 500 will make you sole defender of the fate,


    LocalRoyaltyFreeCities
    LocalCentreDecentre
    LocalConservativeInnovative
    LocalTraditionalIndustry
    LocalMerchantsFeudal
    LocalFeudalProfessional
    LocalNavalLand

    same as the their County oriented counterparts, except more thresholds and the effects are nation wide
    value between -100 and 100
    note: effects on nation not yet implemented but high on the to do list.
    basically try to have every county based decision have some sort of effect on the nation wide politics.
    this will make people that often pick for naval choices to get a culture of sailing in their nation.

    LocalWeakMinded
    A sneaky bugger, the higher the weaker the mind of the king
    the lower the better, if there is an easy way out which would weaken the kings position use this counter.


    step 3:
    Okay, an overwhelming amount of information there but back to our example that should clear things up.
    First I'll add the comment lines so everyone knows whats going on ( remember the ";" )
    note: the ; only works for one line, but once in a txt.file the comment lines will fit onto a single line

    Code:
    if I_CompareCounter BrittanyMerNSmallA == 1
          historic_event BRITTANY_MER_N_SMALL_A1 true
        ;Brittany famine due to poor management and bad harvests
        XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
                 intitial event effects (optional)
                XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
        end_if
    
        while I_CompareCounter BrittanyMerNSmallA == 1
    
    
             monitor_event ButtonPressed ButtonPressed hud_select_prev_item_cycle
                ;significantly lower the taxes for the farmers, they need to grow food for our nation don't  
    take the grain they need to sew  
             AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                    Choice A effects
                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    
    
                set_counter BrittanyMerNSmallA 0
             end_monitor
    
    
             monitor_event ButtonPressed ButtonPressed hud_select_next_item_cycle
    ;Bastards, god himself granted me the right to rule these lands, have the feudal lords deal 
    with it firmly!
             BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
                    Choice B effects
                BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
    
                set_counter BrittanyMerNSmallA 0
             end_monitor
    
        end_while
    Okay, so now lets put the actual effects in. Brittany is a 1 province county (Rennes_Province, again this will all be in the docudemon)

    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    intitial event effects (optional)
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    ;Brittany famine due to poor management and bad harvests

    okay, it's a famine so people starve to death
    console_command add_population Rennes_Province -320

    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    Choice A effects
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    ;significantly lower the taxes for the farmers, they need to grow food for our nation don't take the grain they need to sew

    okay, so I lower the taxes, that should cost me money
    console_command add_money -783

    I make the farmers happy so
    inc_counter BrittanyHappy 45

    I piss of the feudal lords by reducing their income
    inc_counter BrittanyMerchantsFeudal -3
    inc_counter LocalMerchantsFeudal -2

    BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
    Choice B effects
    BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
    ;Bastards, god himself granted me the right to rule these lands, have the feudal lords deal with it firmly!

    okay, taxes as normal and I'm pretty sure they'll be collected with vigour
    console_command add_money 982

    Detrimental for happiness:
    inc_counter BrittanyHappy -55

    Well atleast the feudal lords are happy
    inc_counter BrittanyMerchantsFeudal 3
    inc_counter LocalMerchantsFeudal 2

    Lets just say it didn't all go peaceful + the farms are out of sowing goods
    console_command add_population Rennes_Province -47
    console_command set_building_health Rennes hinterland_farms 16
    But the feudal lords are clamping down as is expected of them
    create_unit Rennes Dismounted_Mailed_Knights , num 1, exp 0, arm 0, wep 0,

    Okay so lets see what we've got:

    Code:
        if I_CompareCounter BrittanyMerNSmallA == 1
          historic_event BRITTANY_MER_N_SMALL_A1 true
      ;Brittany famine due to poor management and bad harvests
          console_command add_population Rennes_Province -320
        end_if
    
        while I_CompareCounter BrittanyMerNSmallA == 1
    
    
      monitor_event ButtonPressed ButtonPressed hud_select_prev_item_cycle
             ;significantly lower the taxes for the farmers, they need to grow food for our nation don't  
    take the grain they need to sew  
     console_command add_money -783
                inc_counter BrittanyHappy 45
                inc_counter BrittanyMerchantsFeudal -3
                inc_counter LocalMerchantsFeudal -2
             set_counter BrittanyMerNSmallA 0
             end_monitor
    
    
             monitor_event ButtonPressed ButtonPressed hud_select_next_item_cycle
    ;Bastards, god himself granted me the right to rule these lands, have the feudal lords deal 
    with it firmly!
         console_command add_money 982
                inc_counter BrittanyHappy -55
                inc_counter BrittanyMerchantsFeudal 3
                inc_counter LocalMerchantsFeudal 2
                console_command add_population Rennes_Province -47
                console_command set_building_health Rennes hinterland_farms 16
                create_unit Rennes Dismounted_Mailed_Knights , num 1, exp 0, arm 0, wep 0,
         set_counter BrittanyMerNSmallA 0
             end_monitor
    
        end_while
    Now with that done, the BRITTANY_MER_N_SMALL_A1 event still doesn't know whats going on, so lets fix that next:

    So we want the text to look like this ( the official TLR lay out :p to keep some sense of unity).

    Famine in Brittany

    The harsh winters and dry summers have led to several bad harvests.it was inevitable that this would lead to a famine. A significant number of the population has already succumbed to hunger and cold! What’s even worse is that currently the farmers will have to eat their sewing grain which will mean lower production next year. Perhaps we should lower the taxes so that the farmers have enough grain left to sew all the fields next year.

    TOGGLE LEFT
    decrease the taxes, the castles of Brittany can survive a lean year or two so that its
    people may once again prosper.
    +Prosperity of Brittany
    -783 florins
    +Support of Merchants

    TOGGLE RIGHT
    I'm sure the nobles can handle this in their own special way. Make sure they don't go soft
    on those insolent peasants!
    -Prosperity Brittany
    +982 florins
    +Support Feudal Lords

    so the way it will look in the text string file will be like this:
    {BRITTANY_MER_N_SMALL_A1_TITLE}Famine in Brittany

    the title obviously
    {BRITTANY_MER_N_SMALL_A1_BODY}The harsh winters and dry summers have led to several bad harvests.it was inevitable that this would lead to a famine.A significant number of the population has already succumbed to hunger and cold!What’s even worse is that currently the farmers will have to eat their sewing grain which will mean lower production next year. Perhaps we should lower the taxes so that the farmers have enough grain left to sew all the fields next year.\n\nTOGGLE LEFT:\ndecrease the taxes, the castles of Brittany can survive a lean year or two so that its people may once again prosper.\n+Prosperity of Brittany\n-783 florins\n+Support of Merchants\n\nTOGGLE RIGHT \nI'm sure the nobles can handle this in their own special way. Make sure they don't go soft on those insolent peasants!\n-Prosperity Brittany\n+982 florins\n+Support Feudal Lords\n\n
    The body, since it's a text string I can't type the white lines, however adding a \n has the text start on a new line and so \n\n is a white line, it's important that you don't type a space behind this,
    just continue straight on with the text like in the example above.

    Also note the \n\n at the end, this is just for lay out purposes and should be added as it makes the event scroll more agreeable.
    Congratulations, if you did all this diligently your event is now ready to be implemented, just put this in a txt file and put it on the forum:
    This is what should be in there:

    Code:
        ;Brittany famine due to poor management and bad harvests
    
        if I_CompareCounter BrittanyMerNSmallA == 1
          historic_event BRITTANY_MER_N_SMALL_A1 true
          console_command add_population Rennes_Province -320
        end_if
    
        while I_CompareCounter BrittanyMerNSmallA == 1
    
    
             monitor_event ButtonPressed ButtonPressed hud_select_prev_item_cycle
                 ;significantly  lower the taxes for the farmers, they need to  grow food for our nation  don't take the grain they need to sew  
                console_command add_money -783
                inc_counter BrittanyHappy 45
                inc_counter BrittanyMerchantsFeudal -3
                inc_counter LocalMerchantsFeudal -2
                set_counter BrittanyMerNSmallA 0
             end_monitor
    
    
             monitor_event ButtonPressed ButtonPressed hud_select_next_item_cycle
                ;Bastards, god himself granted me the right to rule these lands, have the feudal lords deal with it firmly!
                console_command add_money 982
                inc_counter BrittanyHappy -55
                inc_counter BrittanyMerchantsFeudal 3
                inc_counter LocalMerchantsFeudal 2
                console_command add_population Rennes_Province -47
                console_command set_building_health Rennes hinterland_farms 16
                create_unit Rennes Dismounted_Mailed_Knights , num 1, exp 0, arm 0, wep 0,
                set_counter BrittanyMerNSmallA 0
             end_monitor
    
        end_while
    
    {BRITTANY_MER_N_SMALL_A1_TITLE}Famine in Brittany
    {BRITTANY_MER_N_SMALL_A1_BODY}The   harsh winters and dry summers have led to several bad harvests, it was   inevitable that this would lead to a famine perhaps we should lower  the  taxes so that the farmers have enough grain left to sew all the  fields  next year.\n\nTOGGLE LEFT:\ndecrease the taxes, the castles of  Brittany  can survive a lean year or two so that its people may once  again  prosper.\n+Prosperity of Brittany\n-783 florins\n+Support of   Merchants\n\nTOGGLE RIGHT \nI'm sure the nobles can handle this in  their  own special way. Make sure they don't go soft on those insolent   peasants!\n-Prosperity Brittany\n+982 florins\n+Support Feudal  Lords\n\n
    Well that's it for our basic tutorial, I'll be adding an advanced one soon,
    This will handle, multi turn events, more time/nation specific events, adding building effects and much more!

    So stay tuned this is only the beginning,

    for all questions I refer you to the forum, I never wrote a tutorial before so it might be unclear.
    For those already more experienced in modding I apologize for the constantly restating of the obvious, I wanted the tutorial to be as accesible as possible
    Last edited by ilmrik; July 24, 2011 at 12:35 PM.

  3. #3

    Default Guide to Campaing Script Events -Part III added-

    part 3:
    Advanced event making


    So I discussed the build up of the script and the basic events. I’ll now be elaborating on some of the possibilities for those willing to take it to the next level. Remember some of the things mentioned here will only work under a while-looped script build. They are however easily converted and I will be making the tutorial more general.
    First up, a bit more insight into how events are triggered.

    Let’s recap some things from part II and I
    From part II

    Code:
    if I_CompareCounter FlandersNobNHuge == 1
          historic_event FLANDERS_NOB_N_HUGE1 true
    end_if


    Now like mentioned before this means the event will run when the counter is 1, This counter is activated during the Slave turn One time loop.
    However basically this would work,
    I’m not elaborating on all extra conditions in TLR, just remember that a check is in place that only triggers events for counties completely under the local players control (FlandersUnited counter )

    Code:
    if RandomPercent < 6
    and I_CompareCounter RandomEventOne == 0 
         set_counter RandomEventOne 1 
     end_if
    Since the script runs from top to bottom you can just line them up like normal. Be careful however if you are planning on adding a lot of events, you should make some sort of system that prevents over stacking of events. I use this system ( you’ll recognise it in various other places later too)

    Code:
    set_counter FallTrough 1
    if RandomPercent < 34 
         set_counter RandomEventOne 1 
         set_counter FallTrough 0
     end_if 
     if RandomPercent < 51
     and I_CompareCounter FallTrough == 1
         set_counter RandomEventTwo 1 
         set_counter FallTrough 0
     end_if 
     if I_CompareCounter FallTrough == 1
         set_counter RandomEventThree 1 
         set_counter FallTrough 0
     end_if 
    The idea is simple and revolves around the utility counter: FallTrough, basically if any event is triggered it prevents any others by resetting the FallTrough counter, wich is a requirement.
    This particular part of script will have an equal chance of triggering event 1,2 or 3 ( but will always trigger one) it will however never trigger 2 of them at the same time.

    Now in general I try to keep the triggering in the slave turn as simple and uniform as possible.(having a 105 counties this makes the script read easier). This is however subject to change depending on how many events you wish to insert etc.

    There are however a lot of options that sprout from this part:

    Code:
    if I_CompareCounter FlandersNobNHuge == 1
          historic_event FLANDERS_NOB_N_HUGE1 true
    end_if


    Now at the moment it’s all very linear and proper, But we could use “if” statements to make a lot of interesting changes. say:
    Code:
     if I_CompareCounter FlandersNobNHuge == 1
     if (any possible condition/ combination of conditions) 
           historic_event FLANDERS_EVENT_ONE  true
           set_counter FlandersNobNHuge 2
     end_if
     if (any possible condition/ combination of conditions) 
           historic_event FLANDERS_EVENT_TWO  true
           set_counter FlandersNobNHuge 3
     end_if
     end_if 
    
    Now instead of the single Loop we’d have to have 2 loops following it,
    e.g.
    Code:
     While I_CompareCounter FlandersNobNHuge == 2
     ( insert the 2 options for the FLANDERS_EVENT_ONE here exactly as explained in part II) 
     end_while 
    
      While I_CompareCounter FlandersNobNHuge == 3
     ( insert the 2 options for the FLANDERS_EVENT_TWO here exactly as explained in part II) 
     end_while 
    
    Now it’s time to get creative, I’ll be showing some options based on our earlier example from part II.
    All in all I’m quite happy with my event, but it could be better. Firstly I think I’ll make it run over several turns. With different effects depending on what I choose.


    Multi Turn Events



    This is one of the more invasive alterations, but once you get the hang of how the script works you’ll see it’s not that difficult and you can make it as easy or as complex as you want really.

    So lets look at our famine in more detail shall we? What did actually cause it ? how could the situation evolve? This asks for some creative thinking.
    Lets say it all started with us needing a lot of troops ( never could have enough of those if you were a medieval ruler it seems)
    We’ll be including a new event,
    Event 1: Breton nobles can’t afford to send more troops:

    options:
    A) Pshh, nonsense, if they can’t afford it they should just increase he taxes, and their are plenty of able bodied men on the fields.

    B) Okay, we’ll find the support elsewhere, we've been fighting so long perhaps now is a time for peace and rebuilding.

    Without further explanation:
    -I left out the effect lines for convenience they’ll be added once they become relevant again.-
    Code:
          if I_CompareCounter EventTriggerCounter == 1
          historic_event BRITTANY_EVENT_1 true
          - usual effect go here- 
         ;Brittany nobles cannot afford more troops 
        end_if
    
         while I_CompareCounter EventTriggerCounter == 1
    
    
               monitor_event ButtonPressed ButtonPressed hud_select_prev_item_cycle
      ;Pss if they can’t afford it maybe they should raise  the taxes.           
                -The usual effects go here-
                set_counter EventTriggerCounter 2
             Now this is important, instead of setting the counter to 0 I set it to 2, 
             both end the loop as it only runs for I_CompareCounter EventTriggerCounter == 1 
             you’ll see why in the next step 
             end_monitor
    
    
               monitor_event ButtonPressed ButtonPressed hud_select_next_item_cycle
                ;Yes we have asked toomuch of them already, give them time to recuperate
              -The usual effects go here- 
                set_counter EventTriggerCounter 0
             end_monitor
    
         end_while
    
    So the event ran we picked a choice ( the first ) and the EventTriggerCounter = 2 now,
    At this point we’ll be adding our famine event we made earlier, with a few small changes.
    An important thing to remember here is that the script is read only once at the start of the local players turn and from the top to the bottom.
    The way it’s put written here does the following,

    The event triggers during the slave turn
    I pick A
    turn ends

    turn start.
    My decision causes a famine event

    If you put the “famine loop” below the “nobles can’t afford troops loop” both events will run in the same turn.
    Code:
    
    
    Code:
    if I_CompareCounter EventTriggerCounter == 1
          historic_event BRITTANY_EVENT_1 true
     - usual effect go here- 
          ;Brittany nobles cannot afford more troops 
        end_if
    
      if I_CompareCounter EventTriggerCounter == 2
          historic_event BRITTANY_EVENT_2 true
          -Initial famine effects go here-  
        end_if
    
      while I_CompareCounter EventTriggerCounter == 2
    
    
               monitor_event ButtonPressed ButtonPressed hud_select_prev_item_cycle
      ;significantly lower the taxes for the farmers,         
                -The usual famine effects go here-
                set_counter EventTriggerCounter 0
             end_monitor
    
    
               monitor_event ButtonPressed ButtonPressed hud_select_next_item_cycle
                ;Bastards, god himself granted me the right to rule these lands,
                -The usual famine effects go here-
                set_counter EventTriggerCounter 0
             end_monitor
    
         end_while
    
    
          while I_CompareCounter EventTriggerCounter == 1
    
    
               monitor_event ButtonPressed ButtonPressed hud_select_prev_item_cycle
      ;Pss if they can’t afford it maybe they should raise  the taxes.           
                -The usual effects go here-
                set_counter EventTriggerCounter 2
             end_monitor
    
    
               monitor_event ButtonPressed ButtonPressed hud_select_next_item_cycle
                ;Yes we have asked toomuch of them already, give them time to recuperate
              -The usual effects go here- 
                set_counter EventTriggerCounter 0
             end_monitor
    
         end_while
    
    Code:
    
    

    Important notes:
    If you are going to make events multi turn you need to add a ‘safety’ in the event triggering lines: to prevent the same event interfering with itself ( unlikely but possible).

    Code:
    if RandomPercent < 6
    Code:
    and I_CompareCounter EventTriggerCounter == 0 
         set_counter RandomEventOne 1 
     end_if

    I now have a multi turn event, but I still have some things I want to add,


    Expanded conditionals



    These come in all shapes and sizes really and can be used to flavor pretty much everything and anything. Some examples, using the event we just wrote.

    Well lets say I only want my famine event to run in the winter
    TLR has a counter named Quarter that keeps track of the season,
    Quarter == 1 : summer
    Quarter == 2 : winter

    So I just add this line:
    Code:
    
    
    Code:
    if I_CompareCounter EventTriggerCounter == 2
        and I CompareCounter Quarter == 2
          historic_event BRITTANY_EVENT_2 true
          -Initial famine effects go here-  
        end_if
    
    Simple as that! Now instead of running the turn after I forced the nobles to extort the farmers it runs the next winter.

    Another kind of conditional effect, is basically an “if” statement ( being scripting most things boil down to this really), some examples:

    I was thinking; Maybe it’s a bit odd that picking option A causes a famine every time, I think I’ll make it give you 1 in 3 chance of causing famines:

    Again a few simple lines to add:
    Code:
    
    
    Code:
       monitor_event ButtonPressed ButtonPressed hud_select_prev_item_cycle
      ;Pss if they can’t afford it maybe they should raise  the taxes.           
                -The usual effects go here-
                set_counter EventTriggerCounter 0 
     This will end the event without a famine resulting from it next winter however:
             if RandomPercent  < 34
                set_counter EventTriggerCounter 2
             end_if
     This  will end the event with a famine following after it next winter, ( see  above) , 
    remember the order of things is important!!  
    The script runs  from top to bottom!! 
    if you put this part above the “set_counter EventTriggerCounter 0”  
    you’ll never get a famine as it will reset your counter! 
             end_monitor
    

    A list of interesting conditions, see the “docudemons conditions” for more info! pretty much all the I_conditions work I restricted myself to the ones I find interesting.

    Some of these are nation specific, which means either you’ll have to make a work around (see below) or you can only use them for nation specific events ( where you already know which faction you need)
    Spoiler Alert, click show to read: 

    Spoiler Alert, click show to read: 
    I_ModeTaxLevel

    example:
    I_ModeTaxLevel england > tax_high

    checks:
    Average tax level trough out england
    notes:
    Faction specific
    tax level (tax_low, tax_normal, tax_high, tax_extortionate)

    I_LosingMoney

    example:
    I_LosingMoney england

    checks:
    Or England will make a profit at the end of the turn
    notes:
    Faction specific

    I_NumberOfSettlements

    example:
    I_NumberOfSettlements england > 3

    checks:
    The number of settlements England controles
    notes:
    Faction specific

    I_EventCounter

    example:
    I_EventCounter GUNPOWDER == 1

    checks:
    check whether or not an event has already been triggered
    notes:
    Any event name will do, note that you can also set event counters via script, they don’t require you to add them anywhere else this way.

    I_CrusadeInProgress/ I_JihadInProgress

    example:
    I_CrusadeInProgress
    checks:
    checks or their is currently a crusade/jihad in progress
    notes:
    semi nation specific

    I_SettlementOwner

    example:
    I_SettlementOwner Antwerp = england
    checks:
    checks or the settlement is owned by england
    notes:
    nation specific


    I_SettlementUnderSiege

    example:
    I_SettlementUnderSiege Antwerp

    checks:
    checks or the settlement is under siege
    notes:

    I_LocalFaction

    example:
    I_LocalFaction england

    checks:
    checks or england is the local faction
    notes:
    mainly important for the work around

    RandomPercent
    example:
    RandomPercent < 34
    checks:
    gives you a 33% chance of it triggering
    notes:
    just generally a handy thing to have ^.^


    I_CompareCounter

    example:
    I_CompareCounter LocalPious > 50

    checks:
    checks or the value of the mentioned counter ( LocalPious ) is more than 50

    notes:
    any counter you use has to be declared in the script, just put “declare_counter LocalPious” in there somewhere and you can use it.
    This is pretty much the most important conditional of them all when making events, A counter can be used to keep track of pretty much anything. and is a major part of any script.

    They allow you to use pretty much every event and conditional! e.g.

    declare_counter OMGFinancialCrisisWhateverWillWeDo

    monitor_event FactionTurnStart FactionIsLocal
    and Treasury < -10000
    and LosingMoney
    set_counter OMGFinancialCrisisWhateverWillWeDo 1
    end_monitor

    You can now use this counter anywhere as a condition!
    This is pretty much how the workaround for the nation specifics works too:

    Code:
     
     monitor_event FactionTurnStart FactionIsLocal 
         if I_LocalFaction == england
     I_ModeTaxLevel england = tax_extortionate
         set_counter GreedyBastard 2
     end_if 
    
      I_ModeTaxLevel england = tax_high
         set_counter GreedyBastard 1
     end_if 
    
      etc etc 
         end_if 
     end_monitor 
    
    example counter (specific for comparing) from TLR
    BrittanyUnited, value’s 0 and 1; 0 meaning it’s not under control of the local player 1 meaning it is.
    See part II for more examples of counters.



    This can obviously be used everywhere in your events, so a creative person can make no end of cool events with this.
    Some examples:

    A Noble asks you to back him up in some large struggle for land with the local bishop, in return he will give you is support however the bishop mustn't find out! and he might also just fail in his endeavour! just put some “ RandomPercent” in the effects.
    -I assume everyone gets the event basics by now so I’m not going to be repeating everything-


    Code:
      
       monitor_event ButtonPressed ButtonPressed hud_select_prev_item_cycle
      ;support him      
      set_counter EventTriggerCounter 0
      set_counter FallTrough 1
     effects
     if RandomPercent < 67 
    
                      ;Yay he did it ! 
                     set_counter FallTrough 0
                     effects 
     if RandomPercent  < 26 
                        ;Bishop found out, not so yay!
                        effects 
     end_if 
     end_if 
    
                  if RandomPercent < 51
     and I_CompareCounter FallTrough == 1
     ;he failed and the bishop found out about your support :/ I geuss it’s just not your day 
       effects 
     end_if
    
              end_monitor
    
    So there are a few things in here, Firstly there are 3 if statements, creating 4 possible scenario’s if you wish to support him:

    he succeeds bishop doesn’t find out
    he succeeds bishop finds out

    he fails bishop doesn’t find out
    he fails bishop finds out

    Secondly as you can see the “FallTrough” counter is back,
    it just makes sure that if he succeeds the bisshop can only find out in the first if statement.
    The second one is in case he fails only, as you can see the chance of the bishop finding out if he fails are larger.

    Events and the EDB



    Now we’ve explored the options of the campaign script itself, we’ll be going into how this can all link to the other files, first up the EDB! I’m not going to explain the entire EDB here there are plenty of good tutorials on it out there I suggest you read one of those ^^.
    I’ll be showing 2 things:

    1. Events and building effects

    The campaign script doesn’t have a lot of ways it can connect with the other files. in fact in only has one!
    The “set_event_counter” command, this event counter can than be referred to in other files,
    An example:

    The merchants are asking for an expansion of the harbor so they can maintain more trade fleets.
    part of the event:
    Code:
      monitor_event ButtonPressed ButtonPressed hud_select_prev_item_cycle
      ;yes a fantastic idea 
      set_counter EventTriggerCounter 0
              set_event_counter MORE_FLEETS 1 
     other effects
               end_monitor
    
    EDB:
    Code:
    
    
    Code:
     trade_fleet  bonus 3 requires factions { all, } and event_counter MORE_FLEETS 1 (  followed by the hidden resources of the city in question )
    
    Simple enough, however there is a catch.
    What happens if this event runs twice, obviously it won’t add any fleets the second time.
    So we need to add this as well:

    Code:
     
     if I_CompareCounter EventTriggerCounter == 1
     if I_EventCounter MORE_FLEETS == 0   
              historic_event HARBOR_EXPANSION true
         end_if 
         if I_EventCounter MORE_FLEETS == 1
         set_counter FallTrough 1 
             if RandomPercent < 51 
               set_counter FallTrough 1 
           set_counter EventTriggerCounter 2 
               historic_event  TRADE_BOOMS true 
             end_if 
    
              if I_CompareCounter FallTrough == 1
               set_counter FallTrough 0 
               set_counter EventTriggerCounter 3 
               historic_event PIRATES true 
             end_if 
         end_if 
    
         end_if
    
    So I decided to go a bit creative, say the port expansion hasn’t been built yet and the event triggers:

    You’ll get the event asking you or you want to build it so thats fine,

    Say you’ve already built the harbor expansion and the event triggers again, now this time there are 2 options, with a 50/50 chance between them ( again with the FallTrough system).

    1: The trade booms
    2: Pirates appear to prey on the poor sailors

    Note both have their own effects loop! As is to be expected of course as they are essentially 3 different events.

    This way of adding building effects can be used for any of the building effects in M2TW as well as for the adding of recruitable units. Full lists of the building effects can be found in one of the many EDB docudemons found on this website.

    2. Creating entire buildings

    This is a bit of a mixed bag, on one hand most things can be represented by just adding building effects which is easier and less work on the other hand creating real buildings is fancier and makes it more obvious for the player where things are located.


    An important thing to remember when using an event to create buildings is that the game just creates the building without any form of checks. You’d think that is the general idea but this means it is possible to have multiples of the same building in a city. Therefore I’d advice against the use of the campaign script to create buildings that you can build normally as well. This also makes it impossible to use the campaign script to upgrade a building etc.

    You could potentially make a monitor to check or the building already exists but you always run the risk that the building is queued up at the moment the event triggers. Which will again result in having the same building twice.

    Buildings that you can’t build normally are however great candidates and can lead to some fine events. It all revolves around this: console_command create_building

    create_building <settlement_name> <building_level_id> : creates a building of the specified type in a settlement; for building level id's see export_descr_building.txt

    An event example from an earlier TLR version:
    Flanders (Antwerp and Bruges ) was historically very well known for it’s trade in fleece and lace, so why not make a Fleece Fair building, Now I could just add this building to the buildings you can normally build in Flanders but I decided to make it a bit more special.
    Fairs of all kinds required the permission of a feudal lord to be held and several rules applied but the revenues were often considerable.

    Firstly we’ll need to add a new building to the EDB, in this case the fleece fair:
    I gave it 3 levels just for kicks and giggles really, As you can see the first level can’t be build thanks to a conveniently named event counter that will never be 1 , The upgrades however are not since you can’t use the script to upgrade it.

    I did add another event counter to them this is to keep them hidden in the building browser until the first one appears, no need to spoil the surprise.

    The bonus itself is only granted in summer, as it’s an annual event more than a real building.

    Code:
     
     building hinterland_fleece_fair
     {
         levels small_fleece_fair, large_fleece_fair, huge_fleece_fair
         {
             small_fleece_fair requires factions { all, } and event_counter NOT_BUILDABLE 1
             {
                 capability
                 {
    
                      trade_level_bonus bonus 20 requires factions { all, } and event_counter SUMMER 1
                     agent_limit merchant 1
                }
                 material wooden
                 construction  1
                 cost  1
                 settlement_min village
                 upgrades
                 {
             large_fleece_fair
                 }
             }
             large_fleece_fair requires factions { all, } and event_counter FLEECE_FAIRS 1
             {
                 capability
                 {
    
                      trade_level_bonus bonus 40 requires factions { all, } and event_counter SUMMER 1
                     agent_limit merchant 1
    
    
                  }
                 material wooden
                 construction  1
                 cost  1
                 settlement_min large_town
                 upgrades
                 {
             huge_fleece_fair
                 }
             }
             huge_fleece_fair requires factions { all, } and event_counter FLEECE_FAIRS 1
             {
                 capability
                 {
    
                      trade_level_bonus bonus 60 requires factions { all, } and event_counter SUMMER 1
                     agent_limit merchant 1
    
    
                   }
                 material wooden
                 construction  1
                 cost  1
                 settlement_min huge_city
                 upgrades
                 {
     }
         plugins
         {
         }
     }
    
    Now the actual events

    Basically the same build up as the others:

    Flemish fleece fair

    Flanders is fast becoming a centre of trade for wool, fleece and textile from all over Europe and many of the local merchants are now asking for the right to hold annual fairs. Tough the permission to hold a small fair can be granted by the local feudal lords. This fair is based in their large cities and will grant them considerable bonuses in income and trade and will make Flanders one of the indisputable authorities on the main land.

    Code:
     
       monitor_event ButtonPressed ButtonPressed hud_select_prev_item_cycle
      ;yes a fantastic idea 
      set_counter EventTriggerCounter 0
              console_command create_building Antwerp small_fleece_fair
     other effects
               end_monitor
    
    
    Now I have a number of things that I have to change, and a number of things I want to change in this event to make it more interesting this being the advanced tutorial and all.

    1. I have to make sure this event is not repeated as it will lead to multiples of the same building
    2. I want the player to be able to chose to build the fair in Bruges or in Antwerp,
    3. I want their to be a limit on the total of fleece fairs number in Northern Europe, certain other counties will be able to build them as well.
    4. I want to have the starting of a fleece fair to have an effect on the other regions with one.

    So this is how it would look and why:

    1.I have to make sure this event is not repeated as it will lead to multiples of the same building
    very easy, the idea is similar to the one we used for the trade fleet, but this time we use a normal counter.
    The counter is named FlandersFleeceFairs, it’s values are 0 and 1
    0 means there are still possibilities for extra fairs
    1 meaning it’s full

    The counters for the other counties work in a similar fashion.

    2. This is similar to the multi turn event, but this time I want the second event to run immediately after the first, not the next turn as earlier, also if I already have a fleece fair in either of the cities this event becomes redundant and I don’t want it to run. this is the FLANDERS_CHOICEFLEECEFAIR event.
    Spoiler Alert, click show to read: 

    Spoiler Alert, click show to read: 
    {FLANDERS_CHOICEFLEECEFAIR_TITLE}Flemish Dispute
    {FLANDERS_CHOICEFLEECEFAIR_BODY}Since both Flemish cities have a thriving business in all sorts of textiles and so an equal claim to the rights of a fair you will have to decide which city you want the new annual fleece fair to be held. TOGGLE LEFT: Fleece fair in Antwerp TOGGLE RIGHT: Fleece Fair in Bruges.

    2 extra counters are also included, to keep track of which city already has a fair;
    AntwerpFleeceFair
    BrugeFleeceFair


    3. yet another counter, this one keeps track of the total number of fleece fairs out there, if it hits a certain number I skip the fleece fair event entirely
    NE_FleeceFairs;

    4. this will be achieved by a series of ”if“ statements nested in the event effects.
    each one checking whether or not one of the counties has a fleece fair and reducing its prosperity if it has.

    All counters have to be declared again for them to work

    Code:
     
        if I_CompareCounter EventTriggerCounter == 1
           set_counter FallTrough 1
         if I_CompareCounter NE_FleeceFairs < 3 
     Since I only ever want 3 large fleece fairs in Northern Europe it’s value has to remain <= 3
     and I_CompareCounter FlandersFleeceFairs == 0
     if there are still opertunities for an extra fleece fair in Flanders I want the event to run, if not I want it to be skipped 
          historic_event FLANDERS_FLEECE_FAIR true
          ;the merchants ask for the fair
          set_counter FallTrough 0
     end_if
    
      if I_CompareCounter FallTrough == 1
        historic_event  FLANDERS_FINE_WOOL_YEAR true 
    
                 if I_CompareCounter BrugesFleeceFair == 1
                      inc_counter FlandersHappy 30
                end_if
                if I_CompareCounter AntwerpFleeceFair == 1
                     inc_counter FlandersHappy 30
                end_if
     Having one or more fairs means that a good year for the wool is a good year for Flanders
     if I_CompareCounter FlandersFleeceFairs = 1
     Having 2 of the 3 fairs in Northern Europe an extra boost is in order when wool trade booms.
               inc_counter FlandersHappy 15
             end_if 
        set_counter  EventTriggerCounter 0
        set_counter FallTrough 0
     end_if 
    
      This  event isn’t a choice event, because I didn’t see the need for it to be,  it’s just a normal historic event. even tough it does change some  behind the scenes counters. obviously extra effects could be added. 
        end_if
    
    
    
           while I_CompareCounter EventTriggerCounter == 1
    
    
               monitor_event ButtonPressed ButtonPressed hud_select_prev_item_cycle
      ;sure the money is more than welcome       
                set_counter EventTriggerCounter 2
    
                 if I_CompareCounter BrugesFleeceFair == 1
                      inc_counter FlandersHappy 15
                end_if
                if I_CompareCounter AntwerpFleeceFair == 1
                      inc_counter FlandersHappy 15
                end_if
     Flanders  already has 1 fleece fair, so getting a second one will mean they have a   very strong grasps on the wool trade which will increase it’s  prosperity !  
    
      if I_CompareCounter BrittanyFleeceFair == 1
                     inc_counter BrittanyHappy -30
                end_if
                if I_CompareCounter AquatineAndGasconyFleeceFair == 1
                     inc_counter AquatineAndGasconyHappy -30
                end_if
                if I_CompareCounter PoitouAndAnjouFleeceFair == 1
                      inc_counter PoitouAndAnjouHappy -30
                end_if
                if I_CompareCounter NormandyFleeceFair == 1
                      inc_counter NormandyHappy -30
                end_if
                if I_CompareCounter ChampagneFleeceFair == 1
                      inc_counter ChampagneHappy -30
                end_if
                if I_CompareCounter IsleDeFranceFleeceFair == 1
                      inc_counter IsleDeFranceHappy -30
                end_if
                if I_CompareCounter MarseilleFleeceFair == 1
                      inc_counter MarseilleHappy -30
                end_if
                if I_CompareCounter DijonFleeceFair == 1
                     inc_counter DijonHappy -30
                end_if
                if I_CompareCounter LondonFleeceFair == 1
                      inc_counter EnglandHappy -30
                end_if
                if I_CompareCounter ExeterFleeceFair == 1
                      inc_counter EnglandHappy -30
                end_if
                if I_CompareCounter ScotlandFleeceFair == 1
                      inc_counter ScotlandHappy -30
                end_if
    
                     if I_CompareCounter BrugesFleeceFair == 1
     Bruges already has a fleece fair so the next one is automatically placed in Antwerp
                         console_command create_building Antwerp small_fleece_fair
                         set_counter FlandersFleeceFair 1
     Both cities in Flanders now have a fleece fair so this counter needs to be set to 1
                         inc_counter NE_FleeceFairs 1
     A fleece fair has been build in NE so this counter needs to be increased 
                    end_if
                    if I_CompareCounter AntwerpFleeceFair == 1
     Antwerp already has a fleece fair so the next one is automatically placed in Bruges
                        console_command create_building Bruges small_fleece_fair
                        set_counter FlandersFleeceFair 1
     Both cities in Flanders now have a fleece fair so this counter needs to be set to 1
                     inc_counter NE_FleeceFairs 1
     A fleece fair has been build in NE so this counter needs to be increased 
                    end_if
             if I_CompareCounter BrugesFleeceFair == 0
                and I_CompareCounter AntwerpFleeceFair == 0
     Neither of the Cities in Flanders has a fair yet, so I get to choose 
                     historic_event FLANDERS_CHOICEFLEECEFAIR true
                     set_counter EventTriggerCounter 2
     Sets the counter so the next loop activates
                end_if
             end_monitor
    
    
               monitor_event ButtonPressed ButtonPressed hud_select_next_item_cycle
                ;no  I don’t want a fair
              -The usual effects go here- 
                set_counter EventTriggerCounter 0
             end_monitor
    
         end_while
    
      while I_CompareCounter EventTriggerCounter == 2
    
    
               monitor_event ButtonPressed ButtonPressed hud_select_prev_item_cycle
      ;put it in Antwerp     
                   set_counter AntwerpFleeceFair 1
     Antwerp now has a fair
               set_counter EventTriggerCounter 0
     inc_counter NE_FleeceFairs 1
     A fleece fair has been build in NE so this counter needs to be increased 
                   console_command create_building Antwerp small_fleece_fair 
            end_monitor
    
    
             monitor_event ButtonPressed ButtonPressed hud_select_next_item_cycle
                ;put it in Bruges
                   set_counter BrugesFleeceFair 1
     Bruges now has a fair
                 set_counter EventTriggerCounter 0
     inc_counter NE_FleeceFairs 1
     A fleece fair has been build in NE so this counter needs to be increased 
                   console_command create_building Bruges small_fleece_fair 
                set_counter EventTriggerCounter 0
             end_monitor
    
         end_while
    
    There you have it,
    One last thing to note is that these events only run for the local player, which in turn would mean that only regions under his control would ever get one of these fairs. Since this hardly seems fair I added one final monitor to the script to finish this event of for Flanders. ( a similar one is obviously also included for Bruges )

    Code:
     
     monitor_event SettlementTurnEnd Not SettlementIsLocal 
     and I_CompareCounter NE_FleeceFairs < 3
     and I_CompareCounter AntwerpFleeceFair == 0 
     and SettlementName Antwerp 
     and RandomPercent < 2 
          set_counter AntwerpFleeceFair 1
          inc_counter NE_FleeceFairs 1
          inc_counter FlandersHappy 30
         console_command create_building Antwerp small_fleece_fair 
         if I_CompareCounter BrugesFleeceFair == 1
           set_counter FlandersFleeceFairs 1 
        inc_counter FlandersHappy 15
         end_if 
                if I_CompareCounter BrittanyFleeceFair == 1
                     inc_counter BrittanyHappy -30
                end_if
                if I_CompareCounter AquatineAndGasconyFleeceFair == 1
                     inc_counter AquatineAndGasconyHappy -30
                end_if
                if I_CompareCounter PoitouAndAnjouFleeceFair == 1
                      inc_counter PoitouAndAnjouHappy -30
                end_if
                if I_CompareCounter NormandyFleeceFair == 1
                      inc_counter NormandyHappy -30
                end_if
                if I_CompareCounter ChampagneFleeceFair == 1
                      inc_counter ChampagneHappy -30
                end_if
                if I_CompareCounter IsleDeFranceFleeceFair == 1
                      inc_counter IsleDeFranceHappy -30
                end_if
                if I_CompareCounter MarseilleFleeceFair == 1
                      inc_counter MarseilleHappy -30
                end_if
                if I_CompareCounter DijonFleeceFair == 1
                     inc_counter DijonHappy -30
                end_if
                if I_CompareCounter LondonFleeceFair == 1
                      inc_counter EnglandHappy -30
                end_if
                if I_CompareCounter ExeterFleeceFair == 1
                      inc_counter EnglandHappy -30
                end_if
                if I_CompareCounter ScotlandFleeceFair == 1
                      inc_counter ScotlandHappy -30
                end_if
     end_monitor 
    
    Some Final notes on creating buildings trough script:
    A very interesting part of scripted buildings is that you don’t need the “lowest level” building to be at the start of a chain.
    For example say I want a scripted event building that represents some or other expansion of the roads, say royal guard posts or something like that:
    This has 2 main advantages:
    1) you don’t burn trough building slots like crazy, with the ability to add up to 9 scripted buildings to a single chain, not that I ever heard of anyone ever having reached the max allowed number of buildings ( tough I would have with TLR if I had put every regional town centre in a different building chain)

    2) which is a lot more important, if you look in the building browser the “royal guard posts” will be listed under the same title as the roads, which prevents an seemingly endless stream of building chains and looks a lot cleaner in general, the game is even as kind as to sort it by the size of building needed to build and not linear based on the upgrade sequence.

    Not very important in this case, but if you had a building like say “Expanded warehouses” with 4 levels as part of your market chain, it would be nice to have the sorted that way.

    Code:
     
     building hinterland_roads
     {
         convert_to hinterland_castle_roads
         levels roads paved_roads guard_posts
         {
             roads city requires factions { northern_european, middle_eastern, eastern_european, greek, southern_european, }
             {
                 convert_to 0
                 capability
                 {
                     road_level 0
                 }
                 material wooden
                 construction  1
                 cost  400
                 settlement_min town
                 upgrades
                 {
                     paved_roads
                 }
             }
             paved_roads city requires factions { northern_european, middle_eastern, eastern_european, greek, southern_european, }
             {
                 convert_to 1
                 capability
                 {
                     road_level 1
                 }
                 material wooden
                 construction  3
                 cost  1200
                 settlement_min city
                 upgrades
                 {
     guard_posts
                 }
              guard_posts city requires factions { northern_european,  middle_eastern, eastern_european, greek, southern_european, } and  event_counter NOT_BUILDABLE 1
             {
                 convert_to 2
                 capability
                 {
                                 trade_level_bonus bonus 6    
                 }
                 material wooden
                 construction  3
                 cost  1200
                 settlement_min city
                 upgrades
             }
         }
         plugins
         {
         }
     }
    
    Well then, this concludes my tutorial on event making, I hope you enjoyed it!
    I may add an extra chapters on the EDA and EDCT later.
    Until then any questions are suggestions are welcome. or of you are working on events for your own mod and would like some input/help be sure to let me know. I’d be glad to help.
    I'll be working on making these tutorials more general, as the intitial plan was to make a tutorial for people helping with TLR, it isn't really what you'd expect from a tutorial
    Last edited by ilmrik; August 04, 2011 at 10:58 PM.

  4. #4

    Default Re: -The Long Road- Campaign Script System

    Part III added -bump-
    Also if a moderator could explain to me where the random undeletable code boxes keep coming from ? they are like weeds!! the more I try to get rid of them the more of them appear :S
    Last edited by ilmrik; August 04, 2011 at 11:00 PM.

  5. #5

    Default Re: -The Long Road- Campaign Script System

    Good attempt.
    And there is nothing random or not deletable while posting, so dunno what you are referring to.

  6. #6

    Default Re: -The Long Road- Campaign Script System

    well every attempt I made to delete all the odd empty coding boxes has failed, as well as the duplicate empty spoiler boxes and I sure didn't put them there!!
    what is even stranger is that there are more now than when I started trying to remove them.

    feel free to try and edit my post and get rid of them... I dare you

    There is one just above and below the second part of script in the Multi turn events part.

  7. #7
    Vegas_Bear's Avatar Biarchus
    Join Date
    Sep 2005
    Location
    Las Vegas, NV
    Posts
    605

    Default Re: -The Long Road- Campaign Script System

    Nice post, a lot of good information here. Keep up the good work. This is very helpful.

    Vegas_Bear

  8. #8

    Default Re: -The Long Road- Campaign Script System

    Thanks, it needs some cleaning up tough :-) Lay out was never my strongest point.

  9. #9
    Caudillo87's Avatar Semisalis
    Join Date
    Mar 2008
    Location
    Fontana, Ca (Alta California)
    Posts
    451

    Default Re: -The Long Road- Campaign Script System

    Excellent! Simply excellent! +rep

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •