Page 1 of 4 1234 LastLast
Results 1 to 20 of 70

Thread: MTW2 Battle Scripting

  1. #1
    z3n's Avatar State of Mind
    took an arrow to the knee

    Join Date
    Aug 2011
    Posts
    4,640

    Default MTW2 Battle Scripting

    EDIT 2019/03/11:
    Full list of (personally) known AI GTA plan sets
    http://www.twcenter.net/forums/showt...1#post15093711

    EDIT 2016/10/27:

    A word of warning, this tutorial is merely left here to explain the basics behind battle scripting. The finalized version of the script is included in the 'Skynet AI' resource in the world/maps/campaign/imperial_campaign add_into_campaign_script text file.

    That script is the finalized version and was implemented directly into the campaign as the campaign rather than custom battles were viewed as most important. It was in my opinion the best way to implement things as the script is automatically executed that way (via the campaign script). Some people get confused as to what to do with the click on the advisor method, even if that way works for custom & campaign battles.



    OP (2015ish):

    First an explanation, I by no means suggest this is the only way or the best way this script was designed with several principles in mind. Further it does everything in a relatively efficient fashion, in my opinion of course. According to our feedback it lacks any major issues like battle CTD's and so on due to its design premise which is based around as few monitors as possible with the maximum effect. Note that you want as few monitors as possible, so as to lessen the load on the CPU/frame rates as well as the chance of a crash related to scripts.

    I am very interested in people trying to improve upon this current design.

    1) That it would be a custom/campaign battle script activated via advisor.

    2) That it could alternatively be implemented into a campaign based script. Doing this would involve two steps, one naming your script at the bottom of the descr_strat. This is the current implementation in the dev build of EBII.

    3) That it would execute repetitively through every battle rather than terminate.

    Creating a campaign based script is simple, you just write this at the bottom of your descr_strat located in your mod/data/world/maps/campaign/imperial_campiagn

    Code:
    script
    campaign_script.txt
    Then create a text file named campaign_script in your mod/data/world/maps/campaign/imperial_campiagn
    This will execute your script upon starting or continuing a new campaign.

    You will have to paste the full script (located in the second post), into the campaign_script you just created. If you are modding a pre existing mod though with 'script' and 'end_script' already existing in the campaign script make sure you remove those two lines (located at the top and very bottom respectively).

    For some history on the script, several difficulties born from pre-existing engine limitations and quirks (which are in fact sensible), made this script (the campaign script version as it is different from a background script version) a very drawn out creation lasting about 3-4 months of iterations and testing to iron out several different things. For example, thanks to Gigantus I was able to allow trace logs to become readable and avoid the point of no return in regards to text editors.

    The advantage of a campaign script version is that it will be automatic and always activate in any battle, even sally out battles. On the other hand, it will not activate in custom battles.

    The advisor based script will activate in custom battles, as well as the campaign battles with the exception of sally out battles unless it was previously activated during the script game state, note that the scripting game state is refreshed every time you close the game.

    Activation via a trigger based advisor script must be written into the export_descr_advice file. (if you do not go the campaign script route)
    Code:
    ;------------------------------------------
    AdviceThread BackgroundScriptThread
        GameArea Battle
    
    
        Item Background_Script_Text_01
            Uninhibitable
            Verbosity  0
            Priority  6
            Threshold  1
            MaxRepeats  0
            RepeatInterval  1
            Attitude Excited 
            Presentation Default
            Title Background_Script_Title
        On_display scripts\show_me\background_script.txt
            Text Background_Script_Text1
    A MaxRepeats of 0 means an infinite amount. It is activated via the On_Display command rather than Script.
    This would be Script, which means you have to use the Show Me How button to activate it rather than activation via simply clicking the advisor portrait.
    Code:
    ;------------------------------------------
    AdviceThread BackgroundScriptThread
        GameArea Battle
    
    
        Item Background_Script_Text_01
            Uninhibitable
            Verbosity  0
            Priority  6
            Threshold  1
            MaxRepeats  0
            RepeatInterval  1
            Attitude Excited 
            Presentation Default
            Title Background_Script_Title
        Script scripts\show_me\background_script.txt
            Text Background_Script_Text1
    There are triggers required within this file that cause this advice thread to fire.
    This is a simple trigger, with a WhenToTest line which tells the exe when to fire the command, and a superflous condition of 'I_InBattle'. This could according to Gigantus be further supplemented.

    Code:
    ;------------------------------------------
    Trigger background_script_trigger_1
       WhenToTest BattleDeploymentPhaseCommenced
    
    
        Condition I_InBattle
    
    
              AdviceThread BackgroundScriptThread  1
    Using the Condition line as TrueCondition could according to a test run by Gigantus make the script fire automatically without intervention/clicking the portrait by the player. Note that I have not tested this myself as I instead moved the battle script to the campaign script where it is automatically executed by the descr_strat + campaign script. (The descr_strat must have a reference to the script so that a campaign based script fires).

    Code:
    ;------------------------------------------
    Trigger background_script_trigger_1
       WhenToTest BattleDeploymentPhaseCommenced
    
    
        Condition TrueCondition
    
    
              AdviceThread BackgroundScriptThread  1
    Using it inside of a campaign script does give a couple of theoretical advantanges, namely you can use event counters/randomly generated counters which in turn set other counters which are then used by the battle script. This may sound terribly complicated but it is a simple idea.

    The foundations of battle scripting are ways to trigger/code the script itself and then unit/group labels and other related commands. Once these are written in you can start to script anything you so desire. (you can without unit/group labels but it is rather useful to have them)

    script (lower case intentional) this is your basic command which leds the exe know the file contains a script. There is also an end_script command which terminates the script and lets the exe know that is the end of the script.

    So far our code looks like this.

    Code:
    script
    This part appears in some of the historical battle scripts, I included it just because there did not seem to be any adverse effect. It seems to say say execute the script while the battle deployment is not finished.

    Code:
    script
    
    
    while ! I_BattleStarted
    end_while

    A similar command rears its head at the bottom of the script.

    Code:
    while I_InBattle
    end_while
    
    
    end_script
    So to be clear, this is what the script looks like at the moment.

    Code:
    script ; Start of our script
    
    
    while ! I_BattleStarted
    end_while
    
    
    while I_InBattle
    end_while
    
    
    end_script ; End of our script
    Now we have some initial and somewhat unnecessary stuff to add, just to let ourselves know 'yay our script works!' and so on. However there is one part worth noting/explaining the 'restart_timer'. This is a basic command which restarts a timer. A timer is a way of tracking how much time passed in the game. There are different types of timers as well, one for the strat and one for the battle.

    Code:
    ;;;;*************************************************************************************************
    ;;;;    Initialize Battle
    ;;;;*************************************************************************************************
    
    
    log always EBII Battle Scripts 
    log always Activated
    restart_timer deployment_timer
    I try to declare my counters at the very top of the script because it keeps things organized and as far as I can see there is no untoward effect. Logically, there should not be either as the time a timer is declared until it is used is a non issue.

    Of course these counters are all named and have a purpose specifically for my own script, so if you don't need them in your own (removing them immediately would be something only advanced modders should do by the way, otherwise it will mess up your script if you use mine as as base), you can remove these.


    Code:
    ;;;;*************************************************************************************************
    ;;;;    Counters
    ;;;;*************************************************************************************************
    
    
    declare_counter deploy_check
    declare_counter start_battle
    declare_counter FaW_and_S
    declare_counter Release_Labels
    declare_counter End_Labels
    declare_counter AI_GRP
    declare_counter AI_HTC
    declare_counter AI_reinforcements
    declare_timer deployment_timer
    declare_timer AI_reinforcements_timer
    ;suspend_unscripted_advice true

    What this first line means here is that we are monitoring the timer we just declared called the 'deployment_timer'. The logic token > means if the timer is more than 101 milliseconds and we are in battle but the deployment phase has not ended restart the deployment timer and set those specific counters to 0.

    Note I only make those counters get set to 0 so that they clear up any previous battle related settings in those counters. This may make more sense once we progress further through the tutorial with more of the script appearing but in essence, what happens is certain counters get incremented/set to numbers higher than 0 after a battle is finished, so we must 'clear' these up for a new battle.

    Code:
    monitor_conditions I_TimerElapsed deployment_timer > 101
    and I_InBattle
    and not I_BattleStarted
    
    
    restart_timer deployment_timer
    set_counter AI_GRP 0
    set_counter AI_reinforcements 0
    
    
    end_monitor
    This condition is meant to be reliant on the first condition which controls whether the timer is restarted or not. It is meant to do two things, 1) Clear any of the previous labels 2) reset the help the AI captain vs player family members script 3) set the deploy check to 1.

    Code:
    monitor_conditions I_TimerElapsed deployment_timer < 101
    and I_InBattle
    
    
    prepare_for_battle
    set_counter AI_HTC 0
    set_counter deploy_check 1
    
    
    end_monitor
    Once the deploy check is fired, this means the rest of the scripts start to fire.

    To explain this logic, the first monitor checks if whether the deployment phase has ended or not, the second monitor is a safeguard to prevent future CTD's in regards to unit labels.

    This code is the second monitor. Note the most important command here is the 'prepare_for_battle' which clears the external unit labels. There are two types of labels, 1) internal unit labels and 2) external unit labels. We will get into that soon as well.
    Code:
    monitor_conditions I_TimerElapsed deployment_timer < 101
    and I_InBattle
    
    
    prepare_for_battle
    set_counter AI_HTC 0
    set_counter deploy_check 1
    
    
    end_monitor

    This code here is what tells the script, 'yes we are in battle and it has started with the deployment phase ended'.

    Code:
    monitor_conditions I_CompareCounter deploy_check = 1
    and I_BattleStarted
    
    
    set_counter start_battle 1
    
    
    end_monitor
    So the counter for 'start_battle' is now set to 1, which means this monitor can now fire if the battle is started.
    Here we can see several new and important functions, I apologize for the length of this monitor and the numerous topics we might get into but to start explaining, here is the foundation of a battle script (other than starting one which executes repeatedly).

    1) An internal unit label, all internal unit labels start with three things.

    The first 0, the second 0, and the third 0.

    The first 0 is a reference to the 'team/alliance' number. 0 is generally considered the enemy alliance number, whereas 1 is the player (note! this scheme changes when there is a second reinforcing AI army *third as well no doubt but I have never been able to test that or have reason to).

    What this means is that if you label an internally named unit with an external label. (extracted the bolded external unit label so I could explain), then it may have its AI automatically turned off unless the command 'release_unit 0 0 0 MAu1' is used as well. Normally, as the players units do not have an AI in the first place except when directly placed under the AI by the player, this does not matter.

    However it will matter if you have an AI reinforcing army. Hence you have to remember to release all the units or suffer grave consequences with a mostly unresponsive/defensive AI.

    Next, we have the ability to name 'groups' of units. Naming a unit group repeatedly would be redundant, hence I just went and named them all at once. (also note that unit group commands still work doing it this way even if the external/internal unit labels do not exist because there are not enough units in the battle to cover them all).

    This issue of internal/external unit labels is a non fatal issue by the way, and is simply reported in the log. I suppose it doesn't crash as some of CA's coders for historical battles may have encountered the issue as well. In any case, it is what allows us to definitively label all units/unit groups in any battle.

    Code:
    label_unit 0 0 0 MAu1
    Code:
    monitor_conditions I_CompareCounter start_battle = 1
    and I_BattleStarted
    
    
    set_counter Release_Labels 1
    set_counter FaW_and_S 1
    
    
    if I_CompareCounter Release_Labels = 1
    set_counter start_battle 0
    end_if
    
    
    ;;;;*************************************************************************************************
    ;;;;    Create Labels
    ;;;;*************************************************************************************************
    ; *********************************************************************************************
    ;    Main Army Unit Labels
    ; *********************************************************************************************
    
    
        label_unit 0 0 0 MAu1
        label_unit 0 0 1 MAu2
        label_unit 0 0 2 MAu3
        label_unit 0 0 3 MAu4
        label_unit 0 0 4 MAu5
        label_unit 0 0 5 MAu6
        label_unit 0 0 6 MAu7
        label_unit 0 0 7 MAu8
        label_unit 0 0 8 MAu9
        label_unit 0 0 9 MAu10
        label_unit 0 0 10 MAu11
        label_unit 0 0 11 MAu12
        label_unit 0 0 12 MAu13
        label_unit 0 0 13 MAu14
        label_unit 0 0 14 MAu15
        label_unit 0 0 15 MAu16
        label_unit 0 0 16 MAu17
        label_unit 0 0 17 MAu18
        label_unit 0 0 18 MAu19
        label_unit 0 0 19 MAu20
        label_unit 0 0 20 MAu21
        label_unit 0 0 21 MAu22
        label_unit 0 0 22 MAu23
        label_unit 0 0 23 MAu24
        label_unit 0 0 24 MAu25
        label_unit 0 0 25 MAu26
        label_unit 0 0 26 MAu27
        label_unit 0 0 27 MAu28
        label_unit 0 0 28 MAu29
        label_unit 0 0 29 MAu30
        label_unit 0 0 30 MAu31
        label_unit 0 0 31 MAu32
        label_unit 0 0 32 MAu33
        label_unit 0 0 33 MAu34
        label_unit 0 0 34 MAu35
        label_unit 0 0 35 MAu36
        label_unit 0 0 36 MAu37
        label_unit 0 0 37 MAu38
        label_unit 0 0 38 MAu39
        label_unit 0 0 39 MAu40
    
    
    ; *********************************************************************************************
    ;    Allied Unit Labels
    ; *********************************************************************************************
    
    
        label_unit 1 0 0 Eu1
        label_unit 1 0 1 Eu2
        label_unit 1 0 2 Eu3
        label_unit 1 0 3 Eu4
        label_unit 1 0 4 Eu5
        label_unit 1 0 5 Eu6
        label_unit 1 0 6 Eu7
        label_unit 1 0 7 Eu8
        label_unit 1 0 8 Eu9
        label_unit 1 0 9 Eu10
        label_unit 1 0 10 Eu11
        label_unit 1 0 11 Eu12
        label_unit 1 0 12 Eu13
        label_unit 1 0 13 Eu14
        label_unit 1 0 14 Eu15
        label_unit 1 0 15 Eu16
        label_unit 1 0 16 Eu17
        label_unit 1 0 17 Eu18
        label_unit 1 0 18 Eu19
        label_unit 1 0 19 Eu20
        label_unit 1 0 20 Eu21
        label_unit 1 0 21 Eu22
        label_unit 1 0 22 Eu23
        label_unit 1 0 23 Eu24
        label_unit 1 0 24 Eu25
        label_unit 1 0 25 Eu26
        label_unit 1 0 26 Eu27
        label_unit 1 0 27 Eu28
        label_unit 1 0 28 Eu29
        label_unit 1 0 29 Eu30
        label_unit 1 0 30 Eu31
        label_unit 1 0 31 Eu32
        label_unit 1 0 32 Eu33
        label_unit 1 0 33 Eu34
        label_unit 1 0 34 Eu35
        label_unit 1 0 35 Eu36
        label_unit 1 0 36 Eu37
        label_unit 1 0 37 Eu38
        label_unit 1 0 38 Eu39
        label_unit 1 0 39 Eu40
    
    
    ; *********************************************************************************************
    ;    Group Labels
    ; *********************************************************************************************
    
    
    define_unit_group Allies MAu1 MAu2 MAu3 MAu4 MAu5 MAu6 MAu7 MAu8 MAu9 MAu10 MAu11 MAu12 MAu13 MAu14 MAu15 MAu16 MAu17 MAu18 MAu19 MAu20 MAu21 MAu22 MAu23 MAu24 MAu25 MAu26 MAu27 MAu28 MAu29 MAu30 MAu31 MAu32 MAu33 MAu34 MAu35 MAu36 MAu37 MAu38 MAu39 MAu40
    
    
    define_unit_group Enemy Eu1 Eu2 Eu3 Eu4 Eu5 Eu6 Eu7 Eu8 Eu9 Eu10 Eu11 Eu12 Eu13 Eu14 Eu15 Eu16 Eu17 Eu18 Eu19 Eu20 Eu21 Eu22 Eu23 Eu24 Eu25 Eu26 Eu27 Eu28 Eu29 Eu30 Eu31 Eu32 Eu33 Eu34 Eu35 Eu36 Eu37 Eu38 Eu39 Eu40
    
    
    end_monitor
    Next we have the fire at will commands applied directly after the units are labeled. Again this may throw out an error about a certain unit not being defined internally/externally but it doesn't matter here either.

    What it does is set the fire at will mode on automatically for player units, whereas vanilla had it off by default for the player. And in my opinion the AI as well, unfortunately the reloading bug is compounded by this default off decision by the AI/game. It should have been on by default which may have meant the reloading bug we often see with precursor units would have been less prevalent. I do have eventual plans one day to try to address it once again but at preliminary tests scripting doesn't seem to be helpful in fixing this either.

    Code:
    monitor_conditions I_CompareCounter FaW_and_S > 0
    and I_BattleStarted
    
    
    set_counter End_Labels 1
    
    
    ; *********************************************************************************************
    ;    FaW - Active
    ; *********************************************************************************************
    
    
    ; *********************************************************************************************
    ;    FaW - Player
    ; *********************************************************************************************
    
    
        unit_set_fire_at_will_mode MAu1 on
        unit_set_fire_at_will_mode MAu2 on
        unit_set_fire_at_will_mode MAu3 on
        unit_set_fire_at_will_mode MAu4 on
        unit_set_fire_at_will_mode MAu5 on
        unit_set_fire_at_will_mode MAu6 on
        unit_set_fire_at_will_mode MAu7 on
        unit_set_fire_at_will_mode MAu8 on
        unit_set_fire_at_will_mode MAu9 on
        unit_set_fire_at_will_mode MAu10 on
        unit_set_fire_at_will_mode MAu11 on
        unit_set_fire_at_will_mode MAu12 on
        unit_set_fire_at_will_mode MAu13 on
        unit_set_fire_at_will_mode MAu14 on
        unit_set_fire_at_will_mode MAu15 on
        unit_set_fire_at_will_mode MAu16 on
        unit_set_fire_at_will_mode MAu17 on
        unit_set_fire_at_will_mode MAu18 on
        unit_set_fire_at_will_mode MAu19 on
        unit_set_fire_at_will_mode MAu20 on
        unit_set_fire_at_will_mode MAu21 on
        unit_set_fire_at_will_mode MAu22 on
        unit_set_fire_at_will_mode MAu23 on
        unit_set_fire_at_will_mode MAu24 on
        unit_set_fire_at_will_mode MAu25 on
        unit_set_fire_at_will_mode MAu26 on
        unit_set_fire_at_will_mode MAu27 on
        unit_set_fire_at_will_mode MAu28 on
        unit_set_fire_at_will_mode MAu29 on
        unit_set_fire_at_will_mode MAu30 on
        unit_set_fire_at_will_mode MAu31 on
        unit_set_fire_at_will_mode MAu32 on
        unit_set_fire_at_will_mode MAu33 on
        unit_set_fire_at_will_mode MAu34 on
        unit_set_fire_at_will_mode MAu35 on
        unit_set_fire_at_will_mode MAu36 on
        unit_set_fire_at_will_mode MAu37 on
        unit_set_fire_at_will_mode MAu38 on
        unit_set_fire_at_will_mode MAu39 on
        unit_set_fire_at_will_mode MAu40 on
    
    
    ; *********************************************************************************************
    ;    FaW - AI
    ; *********************************************************************************************
    
    
        unit_set_fire_at_will_mode Eu1 on
        unit_set_fire_at_will_mode Eu2 on
        unit_set_fire_at_will_mode Eu3 on
        unit_set_fire_at_will_mode Eu4 on
        unit_set_fire_at_will_mode Eu5 on
        unit_set_fire_at_will_mode Eu6 on
        unit_set_fire_at_will_mode Eu7 on
        unit_set_fire_at_will_mode Eu8 on
        unit_set_fire_at_will_mode Eu9 on
        unit_set_fire_at_will_mode Eu10 on
        unit_set_fire_at_will_mode Eu11 on
        unit_set_fire_at_will_mode Eu12 on
        unit_set_fire_at_will_mode Eu13 on
        unit_set_fire_at_will_mode Eu14 on
        unit_set_fire_at_will_mode Eu15 on
        unit_set_fire_at_will_mode Eu16 on
        unit_set_fire_at_will_mode Eu17 on
        unit_set_fire_at_will_mode Eu18 on
        unit_set_fire_at_will_mode Eu19 on
        unit_set_fire_at_will_mode Eu20 on
        unit_set_fire_at_will_mode Eu21 on
        unit_set_fire_at_will_mode Eu22 on
        unit_set_fire_at_will_mode Eu23 on
        unit_set_fire_at_will_mode Eu24 on
        unit_set_fire_at_will_mode Eu25 on
        unit_set_fire_at_will_mode Eu26 on
        unit_set_fire_at_will_mode Eu27 on
        unit_set_fire_at_will_mode Eu28 on
        unit_set_fire_at_will_mode Eu29 on
        unit_set_fire_at_will_mode Eu30 on
        unit_set_fire_at_will_mode Eu31 on
        unit_set_fire_at_will_mode Eu32 on
        unit_set_fire_at_will_mode Eu33 on
        unit_set_fire_at_will_mode Eu34 on
        unit_set_fire_at_will_mode Eu35 on
        unit_set_fire_at_will_mode Eu36 on
        unit_set_fire_at_will_mode Eu37 on
        unit_set_fire_at_will_mode Eu38 on
        unit_set_fire_at_will_mode Eu39 on
        unit_set_fire_at_will_mode Eu40 on
    
    
    ; *********************************************************************************************
    ;    Skirmish Mode - Active
    ; *********************************************************************************************
    
    
        unit_set_skirmish_mode Eu1 on
        unit_set_skirmish_mode Eu2 on
        unit_set_skirmish_mode Eu3 on
        unit_set_skirmish_mode Eu4 on
        unit_set_skirmish_mode Eu5 on
        unit_set_skirmish_mode Eu6 on
        unit_set_skirmish_mode Eu7 on
        unit_set_skirmish_mode Eu8 on
        unit_set_skirmish_mode Eu9 on
        unit_set_skirmish_mode Eu10 on
        unit_set_skirmish_mode Eu11 on
        unit_set_skirmish_mode Eu12 on
        unit_set_skirmish_mode Eu13 on
        unit_set_skirmish_mode Eu14 on
        unit_set_skirmish_mode Eu15 on
        unit_set_skirmish_mode Eu16 on
        unit_set_skirmish_mode Eu17 on
        unit_set_skirmish_mode Eu18 on
        unit_set_skirmish_mode Eu19 on
        unit_set_skirmish_mode Eu20 on
        unit_set_skirmish_mode Eu21 on
        unit_set_skirmish_mode Eu22 on
        unit_set_skirmish_mode Eu23 on
        unit_set_skirmish_mode Eu24 on
        unit_set_skirmish_mode Eu25 on
        unit_set_skirmish_mode Eu26 on
        unit_set_skirmish_mode Eu27 on
        unit_set_skirmish_mode Eu28 on
        unit_set_skirmish_mode Eu29 on
        unit_set_skirmish_mode Eu30 on
        unit_set_skirmish_mode Eu31 on
        unit_set_skirmish_mode Eu32 on
        unit_set_skirmish_mode Eu33 on
        unit_set_skirmish_mode Eu34 on
        unit_set_skirmish_mode Eu35 on
        unit_set_skirmish_mode Eu36 on
        unit_set_skirmish_mode Eu37 on
        unit_set_skirmish_mode Eu38 on
        unit_set_skirmish_mode Eu39 on
        unit_set_skirmish_mode Eu40 on
    
    
    end_monitor

    Next we have the 'release' back to the AI control for the units as stated before, this is necessary or you will see the AI in a stasis in certain battles.

    Code:
    monitor_conditions I_CompareCounter Release_Labels > 0
    and I_BattleStarted
    
    
    ;Must release Main Army, internal army label is recalibrated upon arrival of AI reinforcements causing 1 (previously the main AI army) to become 0 and 1 to become the secondary AI army.
        release_unit MAu1
        release_unit MAu2
        release_unit MAu3
        release_unit MAu4
        release_unit MAu5
        release_unit MAu6
        release_unit MAu7
        release_unit MAu8
        release_unit MAu9
        release_unit MAu10
        release_unit MAu11
        release_unit MAu12
        release_unit MAu13
        release_unit MAu14
        release_unit MAu15
        release_unit MAu16
        release_unit MAu17
        release_unit MAu18
        release_unit MAu19
        release_unit MAu20
        release_unit MAu21
        release_unit MAu22
        release_unit MAu23
        release_unit MAu24
        release_unit MAu25
        release_unit MAu26
        release_unit MAu27
        release_unit MAu28
        release_unit MAu29
        release_unit MAu30
        release_unit MAu31
        release_unit MAu32
        release_unit MAu33
        release_unit MAu34
        release_unit MAu35
        release_unit MAu36
        release_unit MAu37
        release_unit MAu38
        release_unit MAu39
        release_unit MAu40
        release_unit Eu1
        release_unit Eu2
        release_unit Eu3
        release_unit Eu4
        release_unit Eu5
        release_unit Eu6
        release_unit Eu7
        release_unit Eu8
        release_unit Eu9
        release_unit Eu10
        release_unit Eu11
        release_unit Eu12
        release_unit Eu13
        release_unit Eu14
        release_unit Eu15
        release_unit Eu16
        release_unit Eu17
        release_unit Eu18
        release_unit Eu19
        release_unit Eu20
        release_unit Eu21
        release_unit Eu22
        release_unit Eu23
        release_unit Eu24
        release_unit Eu25
        release_unit Eu26
        release_unit Eu27
        release_unit Eu28
        release_unit Eu29
        release_unit Eu30
        release_unit Eu31
        release_unit Eu32
        release_unit Eu33
        release_unit Eu34
        release_unit Eu35
        release_unit Eu36
        release_unit Eu37
        release_unit Eu38
        release_unit Eu39
        release_unit Eu40
    
    
    end_monitor
    Then we have 'cleanup' for all these counters.

    Code:
    monitor_conditions I_CompareCounter End_Labels = 1
    and I_BattleStarted
    
    
    set_counter Release_Labels 0
    
    
    if I_CompareCounter Release_Labels = 0
    set_counter FaW_and_S 0
    set_counter End_Labels 0
    set_counter deploy_check 0
    end_if
    
    
    end_monitor

    This is a nearly finished idea based around ordering the AI armies to do a specific task defend until a reinforcement based timer completes upon the condition that it has not lost a certain percentage of units. Although these monitors have not been shown yet, I am just explaining the concept behind an event monitor for reinforcements.

    According to player feedback it does work to an extent, but as usual I am trying to perfect it.

    Code:
    ; *********************************************************************************************
    ;    Initialize Battle Plans & Monitors
    ; *********************************************************************************************
    
    
    ; *********************************************************************************************
    ;    Shared Reinforcements Monitor 
    ; *********************************************************************************************
    monitor_event BattleReinforcementsArrive
    
    
    ;AI Reinforcements
    inc_counter AI_reinforcements 1
    
    
    if I_CompareCounter AI_reinforcements = 1
    restart_timer AI_reinforcements_timer
    end_if
    
    
    end_monitor

    Here we can see the AI Reinforcements functions based on the timer (again revolving around the principle of a 'restart_timer' command and comparisons to counters). Note that ai_gta_add_objective may likely require a direct AI related label for the internal unit. However internal EBII testing indicated that some users have problems with this command for some reason causing their game to crash. In any case I included it regardless as it doesn't have a negative side effect and there are future plans for including such a thing if possible.

    Code:
    ; *********************************************************************************************
    ;    AI Reinforcements Defend Plan 
    ; *********************************************************************************************
    
    
    monitor_conditions I_CompareCounter AI_reinforcements > 0
    and I_BattlePlayerAllianceOddsInFavour > 1
    and I_TimerElapsed AI_reinforcements_timer < 90000
    
    
    ;AI Units from Army 1 Battle Objective
    ai_gta_add_objective 0 DEFEND_LINE 999
    ;AI Army 1 Battle Objective
    ai_gta_plan_set 0 DEFEND_FEATURE
    ;AI Units from Army 2 Battle Objective
    ai_gta_add_objective 1 DEFEND_LINE 999
    ;AI Army 2 Battle Objective
    ai_gta_plan_set 1 DEFEND_FEATURE
    
    
    end_monitor
    
    
    ; *********************************************************************************************
    ;    AI Reinforcements Attack Plan
    ; *********************************************************************************************
    
    
    monitor_conditions I_CompareCounter AI_reinforcements > 0
    and not I_BattlePlayerArmyIsAttacker
    and I_TimerElapsed AI_reinforcements_timer > 90000
    
    
    ;AI Units from Army 1 Battle Objective
    ai_gta_add_objective 0 ATTACK_ENEMY_BATTLEGROUP 999
    ;AI Army 1 Battle Objective
    ai_gta_plan_set 0 ATTACK_ALL
    ;AI Units from Army 2 Battle Objective
    ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
    ;AI Army 2 Battle Objective
    ai_gta_plan_set 1 ATTACK_ALL
    
    
    end_monitor
    Next we have this part, it monitors certain AI units. Namely the general unit, if the general is under attack the entire army switches into an attack state regardless of its previous AI based orders. (often players including myself would exploit the poor defensive AI by killing off its general in several repetitive cavalry charges during which the AI wouldn't react very well if at all). Further there is an army based one that kicks the AI into gear if under fire/being attacked in some way or another, this is to limit another player exploit we all used at one point or another firing at the uncaring enemy with our archers.

    Code:
    ; *********************************************************************************************
    ;    AI Unit Monitors & AI Reactions
    ; *********************************************************************************************
    
    
    monitor_conditions I_PercentageUnitKilled Eu1 > 5
    and I_BattleStarted
    and not I_BattleIsSiegeBattle
    
    
    inc_counter AI_GRP 1
    
    
    ;AI Units Battle Objective
    ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
    ;AI Alliance Battle Objective
    ai_gta_plan_set 1 ATTACK_ALL
    
    
    end_monitor
    
    
    monitor_conditions I_PercentageOfArmyKilled 1 0 > 3
    and I_BattleStarted
    and I_BattlePlayerArmyIsAttacker
    and not I_BattleIsSiegeBattle
    
    
    inc_counter AI_GRP 1
    
    
    ;AI Units Battle Objective
    ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
    ;AI Alliance Battle Objective
    ai_gta_plan_set 1 ATTACK_ALL
    
    
    end_monitor

    Here is the help the captain script, which revolves around two principles 1) the CAI often sends large captain stacks around without a FM to help it, and inadvertedly attacks the player with such a stack, an overwhelming majority voted for the AI led captain stacks to receive a buff in regards to morale if attacked or attacking a player army led by a family member. Hence this script.


    Code:
    monitor_conditions I_BattlePlayerArmyNumberOfAttribute general_unit > 0
    and I_BattleEnemyArmyNumberOfAttribute general_unit = 0
    and I_InBattle
    
    
    ; *********************************************************************************************
    ;    Help The Captain - AI (35% chance of an experienced captain)
    ; *********************************************************************************************
        unit_set_experience Eu1 3
        unit_set_experience Eu2 3
        unit_set_experience Eu3 3
        unit_set_experience Eu4 3
        unit_set_experience Eu5 3
        unit_set_experience Eu6 3
        unit_set_experience Eu7 3
        unit_set_experience Eu8 3
        unit_set_experience Eu9 3
        unit_set_experience Eu10 3
        unit_set_experience Eu11 3
        unit_set_experience Eu12 3
        unit_set_experience Eu13 3
        unit_set_experience Eu14 3
        unit_set_experience Eu15 3
        unit_set_experience Eu16 3
        unit_set_experience Eu17 3
        unit_set_experience Eu18 3
        unit_set_experience Eu19 3
        unit_set_experience Eu20 3
        unit_set_experience Eu21 3
        unit_set_experience Eu22 3
        unit_set_experience Eu23 3
        unit_set_experience Eu24 3
        unit_set_experience Eu25 3
        unit_set_experience Eu26 3
        unit_set_experience Eu27 3
        unit_set_experience Eu28 3
        unit_set_experience Eu29 3
        unit_set_experience Eu30 3
        unit_set_experience Eu31 3
        unit_set_experience Eu32 3
        unit_set_experience Eu33 3
        unit_set_experience Eu34 3
        unit_set_experience Eu35 3
        unit_set_experience Eu36 3
        unit_set_experience Eu37 3
        unit_set_experience Eu38 3
        unit_set_experience Eu39 3
        unit_set_experience Eu40 3
    
    
    ;AI Reinforcements/Main Army get set to the internal label 0 which was previously the players when reinforced
    ;AI Reinforcing Army = MA = 0, AI Reinforcing Army 2 = (E) = 1, Player Army = 2 when there are two reinforcing AI armies
    ;Internal Labels are counted from 0 onwards 
    ;No Random Help The Captain Conditions as this would be an important army/battle if two reinforcements
    if I_CompareCounter AI_Reinforcements > 0
        unit_set_experience MAu1 3
        unit_set_experience MAu2 3
        unit_set_experience MAu3 3
        unit_set_experience MAu4 3
        unit_set_experience MAu5 3
        unit_set_experience MAu6 3
        unit_set_experience MAu7 3
        unit_set_experience MAu8 3
        unit_set_experience MAu9 3
        unit_set_experience MAu10 3
        unit_set_experience MAu11 3
        unit_set_experience MAu12 3
        unit_set_experience MAu13 3
        unit_set_experience MAu14 3
        unit_set_experience MAu15 3
        unit_set_experience MAu16 3
        unit_set_experience MAu17 3
        unit_set_experience MAu18 3
        unit_set_experience MAu19 3
        unit_set_experience MAu20 3
        unit_set_experience MAu21 3
        unit_set_experience MAu22 3
        unit_set_experience MAu23 3
        unit_set_experience MAu24 3
        unit_set_experience MAu25 3
        unit_set_experience MAu26 3
        unit_set_experience MAu27 3
        unit_set_experience MAu28 3
        unit_set_experience MAu29 3
        unit_set_experience MAu30 3
        unit_set_experience MAu31 3
        unit_set_experience MAu32 3
        unit_set_experience MAu33 3
        unit_set_experience MAu34 3
        unit_set_experience MAu35 3
        unit_set_experience MAu36 3
        unit_set_experience MAu37 3
        unit_set_experience MAu38 3
        unit_set_experience MAu39 3
        unit_set_experience MAu40 3
        unit_set_experience Eu1 3
        unit_set_experience Eu2 3
        unit_set_experience Eu3 3
        unit_set_experience Eu4 3
        unit_set_experience Eu5 3
        unit_set_experience Eu6 3
        unit_set_experience Eu7 3
        unit_set_experience Eu8 3
        unit_set_experience Eu9 3
        unit_set_experience Eu10 3
        unit_set_experience Eu11 3
        unit_set_experience Eu12 3
        unit_set_experience Eu13 3
        unit_set_experience Eu14 3
        unit_set_experience Eu15 3
        unit_set_experience Eu16 3
        unit_set_experience Eu17 3
        unit_set_experience Eu18 3
        unit_set_experience Eu19 3
        unit_set_experience Eu20 3
        unit_set_experience Eu21 3
        unit_set_experience Eu22 3
        unit_set_experience Eu23 3
        unit_set_experience Eu24 3
        unit_set_experience Eu25 3
        unit_set_experience Eu26 3
        unit_set_experience Eu27 3
        unit_set_experience Eu28 3
        unit_set_experience Eu29 3
        unit_set_experience Eu30 3
        unit_set_experience Eu31 3
        unit_set_experience Eu32 3
        unit_set_experience Eu33 3
        unit_set_experience Eu34 3
        unit_set_experience Eu35 3
        unit_set_experience Eu36 3
        unit_set_experience Eu37 3
        unit_set_experience Eu38 3
        unit_set_experience Eu39 3
        unit_set_experience Eu40 3
    end_if
    
    
    end_monitor
    Next we have a couple scripts meant to force certain behaviors that should always happen to happen. As the AI has been known to refuse to attack when it attacked you etc. As you can see some of them are also counter dependant and based around certain conditions, this is because in battle scripting you must exclude certain behaviours and make sure they are not overwritten in any way by previous commands.

    Code:
    ; *********************************************************************************************
    ;    Normal Attack Plan
    ; *********************************************************************************************
    
    
    monitor_conditions I_CompareCounter AI_reinforcements = 0
    and I_ConflictType Normal
    and I_InBattle
    and not I_BattlePlayerArmyIsAttacker
    
    
    ;AI Units Battle Objective
    ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
    ;AI Alliance Battle Objective
    ai_gta_plan_set 1 ATTACK_ALL
    
    
    end_monitor
    
    
    ; *********************************************************************************************
    ;    Normal Defend Plan
    ;    Recurring counters fire above 0
    ; *********************************************************************************************
    
    
    monitor_conditions I_CompareCounter AI_reinforcements = 0
    and I_ConflictType Normal
    and I_InBattle
    and not I_BattleAiAttacking
    and I_BattlePlayerArmyIsAttacker
    
    
    if I_CompareCounter AI_GRP = 0
    ;AI Units Battle Objective Main Army
    ai_gta_add_objective 1 DEFEND_LINE 999
    ;AI Alliance Battle Objective Main Army
    ai_gta_plan_set 1 DEFEND_FEATURE
    end_if
    
    
    if I_CompareCounter AI_GRP > 0
    ;AI Units Battle Objective
    ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
    ;AI Alliance Battle Objective
    ai_gta_plan_set 1 ATTACK_ALL
    end_if
    
    
    end_monitor
    
    
    ; *********************************************************************************************
    ;     Assault Crossing
    ; *********************************************************************************************
    
    
    monitor_conditions I_BattleIsRiverBattle
    and I_InBattle
    and not I_BattlePlayerArmyIsAttacker
    
    
    ;AI Units Battle Objective
    ai_gta_add_objective 1 ASSAULT_CROSSING 999
    ;AI Alliance Battle Objective
    ai_gta_plan_set 1 ATTACK_ALL
    
    
    end_monitor
    
    
    ; *********************************************************************************************
    ;     Assault Settlement 
    ; *********************************************************************************************
    
    
    monitor_conditions I_BattleIsSiegeBattle
    and I_InBattle
    and not I_BattlePlayerArmyIsAttacker
    
    
    ;AI Alliance Battle Objective
    ai_gta_plan_set 1 ATTACK_SETTLEMENT
    
    
    end_monitor
    
    
    ; *********************************************************************************************
    ;     Sally Out 
    ; *********************************************************************************************
    
    
    monitor_conditions I_BattleIsSallyOutBattle
    and I_InBattle
    and not I_BattlePlayerArmyIsAttacker
    
    
    ;AI Units Battle Objective
    ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
    ;AI Alliance Battle Objective
    ai_gta_plan_set 1 ATTACK_ALL
    
    
    end_monitor
    Hopefully this tutorial clarified at least a couple of things for you, if you still have any questions feel free to ask!


    I'll include a quick/final summary here.

    1) A way of executing a battle script is necessary, you should either write your script into export_descr_advice or a campaign_script (or whatever name you prefer).
    2) Your script must be able to execute repetatively in more than one battle to prevent issues with a second battle not starting or crashing due to a lack of the prepare_for_battle implemented in your script.
    3) Your script must contain valid commands, everything is parsed, use the docudemons for ideas on scripting conditions and or commands/events. You can use excel viewer (free software provided by microsoft) if you do not have excel to view them.


    Lastly here is what the final script looks like.


    Code:
    ; *********************************************************************************************
    ;    EBII Battle Scripts
    ;    27/1/2015
    ;    z3n
    ; *********************************************************************************************
    
    
    script
    
    
    while ! I_BattleStarted
    end_while
    
    
    ;;;;*************************************************************************************************
    ;;;;    Initialize Battle
    ;;;;*************************************************************************************************
    
    
    log always EBII Battle Scripts 
    log always Activated
    restart_timer deployment_timer
    ;generate_random_counter AI_RHTC 1 100 (event counter only works in the campaign script)
    
    
    ;;;;*************************************************************************************************
    ;;;;    Counters
    ;;;;*************************************************************************************************
    
    
    declare_counter deploy_check
    declare_counter start_battle
    declare_counter FaW_and_S
    declare_counter Release_Labels
    declare_counter End_Labels
    declare_counter AI_GRP
    declare_counter AI_HTC
    declare_counter AI_reinforcements
    declare_timer deployment_timer
    declare_timer AI_reinforcements_timer
    ;suspend_unscripted_advice true
    
    
    monitor_conditions I_TimerElapsed deployment_timer > 101
    and I_InBattle
    and not I_BattleStarted
    
    
    restart_timer deployment_timer
    set_counter AI_GRP 0
    set_counter AI_reinforcements 0
    
    
    end_monitor
    
    
    monitor_conditions I_TimerElapsed deployment_timer < 101
    and I_InBattle
    
    
    prepare_for_battle
    set_counter AI_HTC 0
    set_counter deploy_check 1
    
    
    end_monitor
    
    
    monitor_conditions I_CompareCounter deploy_check = 1
    and I_BattleStarted
    
    
    set_counter start_battle 1
    
    
    end_monitor
    
    
    monitor_conditions I_CompareCounter start_battle = 1
    and I_BattleStarted
    
    
    set_counter Release_Labels 1
    set_counter FaW_and_S 1
    
    
    if I_CompareCounter Release_Labels = 1
    set_counter start_battle 0
    end_if
    
    
    ;;;;*************************************************************************************************
    ;;;;    Create Labels
    ;;;;*************************************************************************************************
    ; *********************************************************************************************
    ;    Main Army Unit Labels
    ; *********************************************************************************************
    
    
        label_unit 0 0 0 MAu1
        label_unit 0 0 1 MAu2
        label_unit 0 0 2 MAu3
        label_unit 0 0 3 MAu4
        label_unit 0 0 4 MAu5
        label_unit 0 0 5 MAu6
        label_unit 0 0 6 MAu7
        label_unit 0 0 7 MAu8
        label_unit 0 0 8 MAu9
        label_unit 0 0 9 MAu10
        label_unit 0 0 10 MAu11
        label_unit 0 0 11 MAu12
        label_unit 0 0 12 MAu13
        label_unit 0 0 13 MAu14
        label_unit 0 0 14 MAu15
        label_unit 0 0 15 MAu16
        label_unit 0 0 16 MAu17
        label_unit 0 0 17 MAu18
        label_unit 0 0 18 MAu19
        label_unit 0 0 19 MAu20
        label_unit 0 0 20 MAu21
        label_unit 0 0 21 MAu22
        label_unit 0 0 22 MAu23
        label_unit 0 0 23 MAu24
        label_unit 0 0 24 MAu25
        label_unit 0 0 25 MAu26
        label_unit 0 0 26 MAu27
        label_unit 0 0 27 MAu28
        label_unit 0 0 28 MAu29
        label_unit 0 0 29 MAu30
        label_unit 0 0 30 MAu31
        label_unit 0 0 31 MAu32
        label_unit 0 0 32 MAu33
        label_unit 0 0 33 MAu34
        label_unit 0 0 34 MAu35
        label_unit 0 0 35 MAu36
        label_unit 0 0 36 MAu37
        label_unit 0 0 37 MAu38
        label_unit 0 0 38 MAu39
        label_unit 0 0 39 MAu40
    
    
    ; *********************************************************************************************
    ;    Allied Unit Labels
    ; *********************************************************************************************
    
    
        label_unit 1 0 0 Eu1
        label_unit 1 0 1 Eu2
        label_unit 1 0 2 Eu3
        label_unit 1 0 3 Eu4
        label_unit 1 0 4 Eu5
        label_unit 1 0 5 Eu6
        label_unit 1 0 6 Eu7
        label_unit 1 0 7 Eu8
        label_unit 1 0 8 Eu9
        label_unit 1 0 9 Eu10
        label_unit 1 0 10 Eu11
        label_unit 1 0 11 Eu12
        label_unit 1 0 12 Eu13
        label_unit 1 0 13 Eu14
        label_unit 1 0 14 Eu15
        label_unit 1 0 15 Eu16
        label_unit 1 0 16 Eu17
        label_unit 1 0 17 Eu18
        label_unit 1 0 18 Eu19
        label_unit 1 0 19 Eu20
        label_unit 1 0 20 Eu21
        label_unit 1 0 21 Eu22
        label_unit 1 0 22 Eu23
        label_unit 1 0 23 Eu24
        label_unit 1 0 24 Eu25
        label_unit 1 0 25 Eu26
        label_unit 1 0 26 Eu27
        label_unit 1 0 27 Eu28
        label_unit 1 0 28 Eu29
        label_unit 1 0 29 Eu30
        label_unit 1 0 30 Eu31
        label_unit 1 0 31 Eu32
        label_unit 1 0 32 Eu33
        label_unit 1 0 33 Eu34
        label_unit 1 0 34 Eu35
        label_unit 1 0 35 Eu36
        label_unit 1 0 36 Eu37
        label_unit 1 0 37 Eu38
        label_unit 1 0 38 Eu39
        label_unit 1 0 39 Eu40
    
    
    ; *********************************************************************************************
    ;    Group Labels
    ; *********************************************************************************************
    
    
    define_unit_group Allies MAu1 MAu2 MAu3 MAu4 MAu5 MAu6 MAu7 MAu8 MAu9 MAu10 MAu11 MAu12 MAu13 MAu14 MAu15 MAu16 MAu17 MAu18 MAu19 MAu20 MAu21 MAu22 MAu23 MAu24 MAu25 MAu26 MAu27 MAu28 MAu29 MAu30 MAu31 MAu32 MAu33 MAu34 MAu35 MAu36 MAu37 MAu38 MAu39 MAu40
    
    
    define_unit_group Enemy Eu1 Eu2 Eu3 Eu4 Eu5 Eu6 Eu7 Eu8 Eu9 Eu10 Eu11 Eu12 Eu13 Eu14 Eu15 Eu16 Eu17 Eu18 Eu19 Eu20 Eu21 Eu22 Eu23 Eu24 Eu25 Eu26 Eu27 Eu28 Eu29 Eu30 Eu31 Eu32 Eu33 Eu34 Eu35 Eu36 Eu37 Eu38 Eu39 Eu40
    
    
    end_monitor
    
    
    monitor_conditions I_CompareCounter FaW_and_S > 0
    and I_BattleStarted
    
    
    set_counter End_Labels 1
    
    
    ; *********************************************************************************************
    ;    FaW - Active
    ; *********************************************************************************************
    
    
    ; *********************************************************************************************
    ;    FaW - Player
    ; *********************************************************************************************
    
    
        unit_set_fire_at_will_mode MAu1 on
        unit_set_fire_at_will_mode MAu2 on
        unit_set_fire_at_will_mode MAu3 on
        unit_set_fire_at_will_mode MAu4 on
        unit_set_fire_at_will_mode MAu5 on
        unit_set_fire_at_will_mode MAu6 on
        unit_set_fire_at_will_mode MAu7 on
        unit_set_fire_at_will_mode MAu8 on
        unit_set_fire_at_will_mode MAu9 on
        unit_set_fire_at_will_mode MAu10 on
        unit_set_fire_at_will_mode MAu11 on
        unit_set_fire_at_will_mode MAu12 on
        unit_set_fire_at_will_mode MAu13 on
        unit_set_fire_at_will_mode MAu14 on
        unit_set_fire_at_will_mode MAu15 on
        unit_set_fire_at_will_mode MAu16 on
        unit_set_fire_at_will_mode MAu17 on
        unit_set_fire_at_will_mode MAu18 on
        unit_set_fire_at_will_mode MAu19 on
        unit_set_fire_at_will_mode MAu20 on
        unit_set_fire_at_will_mode MAu21 on
        unit_set_fire_at_will_mode MAu22 on
        unit_set_fire_at_will_mode MAu23 on
        unit_set_fire_at_will_mode MAu24 on
        unit_set_fire_at_will_mode MAu25 on
        unit_set_fire_at_will_mode MAu26 on
        unit_set_fire_at_will_mode MAu27 on
        unit_set_fire_at_will_mode MAu28 on
        unit_set_fire_at_will_mode MAu29 on
        unit_set_fire_at_will_mode MAu30 on
        unit_set_fire_at_will_mode MAu31 on
        unit_set_fire_at_will_mode MAu32 on
        unit_set_fire_at_will_mode MAu33 on
        unit_set_fire_at_will_mode MAu34 on
        unit_set_fire_at_will_mode MAu35 on
        unit_set_fire_at_will_mode MAu36 on
        unit_set_fire_at_will_mode MAu37 on
        unit_set_fire_at_will_mode MAu38 on
        unit_set_fire_at_will_mode MAu39 on
        unit_set_fire_at_will_mode MAu40 on
    
    
    ; *********************************************************************************************
    ;    FaW - AI
    ; *********************************************************************************************
    
    
        unit_set_fire_at_will_mode Eu1 on
        unit_set_fire_at_will_mode Eu2 on
        unit_set_fire_at_will_mode Eu3 on
        unit_set_fire_at_will_mode Eu4 on
        unit_set_fire_at_will_mode Eu5 on
        unit_set_fire_at_will_mode Eu6 on
        unit_set_fire_at_will_mode Eu7 on
        unit_set_fire_at_will_mode Eu8 on
        unit_set_fire_at_will_mode Eu9 on
        unit_set_fire_at_will_mode Eu10 on
        unit_set_fire_at_will_mode Eu11 on
        unit_set_fire_at_will_mode Eu12 on
        unit_set_fire_at_will_mode Eu13 on
        unit_set_fire_at_will_mode Eu14 on
        unit_set_fire_at_will_mode Eu15 on
        unit_set_fire_at_will_mode Eu16 on
        unit_set_fire_at_will_mode Eu17 on
        unit_set_fire_at_will_mode Eu18 on
        unit_set_fire_at_will_mode Eu19 on
        unit_set_fire_at_will_mode Eu20 on
        unit_set_fire_at_will_mode Eu21 on
        unit_set_fire_at_will_mode Eu22 on
        unit_set_fire_at_will_mode Eu23 on
        unit_set_fire_at_will_mode Eu24 on
        unit_set_fire_at_will_mode Eu25 on
        unit_set_fire_at_will_mode Eu26 on
        unit_set_fire_at_will_mode Eu27 on
        unit_set_fire_at_will_mode Eu28 on
        unit_set_fire_at_will_mode Eu29 on
        unit_set_fire_at_will_mode Eu30 on
        unit_set_fire_at_will_mode Eu31 on
        unit_set_fire_at_will_mode Eu32 on
        unit_set_fire_at_will_mode Eu33 on
        unit_set_fire_at_will_mode Eu34 on
        unit_set_fire_at_will_mode Eu35 on
        unit_set_fire_at_will_mode Eu36 on
        unit_set_fire_at_will_mode Eu37 on
        unit_set_fire_at_will_mode Eu38 on
        unit_set_fire_at_will_mode Eu39 on
        unit_set_fire_at_will_mode Eu40 on
    
    
    ; *********************************************************************************************
    ;    Skirmish Mode - Active
    ; *********************************************************************************************
    
    
        unit_set_skirmish_mode Eu1 on
        unit_set_skirmish_mode Eu2 on
        unit_set_skirmish_mode Eu3 on
        unit_set_skirmish_mode Eu4 on
        unit_set_skirmish_mode Eu5 on
        unit_set_skirmish_mode Eu6 on
        unit_set_skirmish_mode Eu7 on
        unit_set_skirmish_mode Eu8 on
        unit_set_skirmish_mode Eu9 on
        unit_set_skirmish_mode Eu10 on
        unit_set_skirmish_mode Eu11 on
        unit_set_skirmish_mode Eu12 on
        unit_set_skirmish_mode Eu13 on
        unit_set_skirmish_mode Eu14 on
        unit_set_skirmish_mode Eu15 on
        unit_set_skirmish_mode Eu16 on
        unit_set_skirmish_mode Eu17 on
        unit_set_skirmish_mode Eu18 on
        unit_set_skirmish_mode Eu19 on
        unit_set_skirmish_mode Eu20 on
        unit_set_skirmish_mode Eu21 on
        unit_set_skirmish_mode Eu22 on
        unit_set_skirmish_mode Eu23 on
        unit_set_skirmish_mode Eu24 on
        unit_set_skirmish_mode Eu25 on
        unit_set_skirmish_mode Eu26 on
        unit_set_skirmish_mode Eu27 on
        unit_set_skirmish_mode Eu28 on
        unit_set_skirmish_mode Eu29 on
        unit_set_skirmish_mode Eu30 on
        unit_set_skirmish_mode Eu31 on
        unit_set_skirmish_mode Eu32 on
        unit_set_skirmish_mode Eu33 on
        unit_set_skirmish_mode Eu34 on
        unit_set_skirmish_mode Eu35 on
        unit_set_skirmish_mode Eu36 on
        unit_set_skirmish_mode Eu37 on
        unit_set_skirmish_mode Eu38 on
        unit_set_skirmish_mode Eu39 on
        unit_set_skirmish_mode Eu40 on
    
    
    end_monitor
    
    
    monitor_conditions I_CompareCounter Release_Labels > 0
    and I_BattleStarted
    
    
    ;Must release Main Army, internal army label is recalibrated upon arrival of AI reinforcements causing 1 (previously the main AI army) to become 0 and 1 to become the secondary AI army.
        release_unit MAu1
        release_unit MAu2
        release_unit MAu3
        release_unit MAu4
        release_unit MAu5
        release_unit MAu6
        release_unit MAu7
        release_unit MAu8
        release_unit MAu9
        release_unit MAu10
        release_unit MAu11
        release_unit MAu12
        release_unit MAu13
        release_unit MAu14
        release_unit MAu15
        release_unit MAu16
        release_unit MAu17
        release_unit MAu18
        release_unit MAu19
        release_unit MAu20
        release_unit MAu21
        release_unit MAu22
        release_unit MAu23
        release_unit MAu24
        release_unit MAu25
        release_unit MAu26
        release_unit MAu27
        release_unit MAu28
        release_unit MAu29
        release_unit MAu30
        release_unit MAu31
        release_unit MAu32
        release_unit MAu33
        release_unit MAu34
        release_unit MAu35
        release_unit MAu36
        release_unit MAu37
        release_unit MAu38
        release_unit MAu39
        release_unit MAu40
        release_unit Eu1
        release_unit Eu2
        release_unit Eu3
        release_unit Eu4
        release_unit Eu5
        release_unit Eu6
        release_unit Eu7
        release_unit Eu8
        release_unit Eu9
        release_unit Eu10
        release_unit Eu11
        release_unit Eu12
        release_unit Eu13
        release_unit Eu14
        release_unit Eu15
        release_unit Eu16
        release_unit Eu17
        release_unit Eu18
        release_unit Eu19
        release_unit Eu20
        release_unit Eu21
        release_unit Eu22
        release_unit Eu23
        release_unit Eu24
        release_unit Eu25
        release_unit Eu26
        release_unit Eu27
        release_unit Eu28
        release_unit Eu29
        release_unit Eu30
        release_unit Eu31
        release_unit Eu32
        release_unit Eu33
        release_unit Eu34
        release_unit Eu35
        release_unit Eu36
        release_unit Eu37
        release_unit Eu38
        release_unit Eu39
        release_unit Eu40
    
    
    end_monitor
    
    
    monitor_conditions I_CompareCounter End_Labels = 1
    and I_BattleStarted
    
    
    set_counter Release_Labels 0
    
    
    if I_CompareCounter Release_Labels = 0
    set_counter FaW_and_S 0
    set_counter End_Labels 0
    set_counter deploy_check 0
    end_if
    
    
    end_monitor
    
    
    ; *********************************************************************************************
    ;    Initialize Battle Plans & Monitors
    ; *********************************************************************************************
    
    
    ; *********************************************************************************************
    ;    Shared Reinforcements Monitor 
    ; *********************************************************************************************
    monitor_event BattleReinforcementsArrive
    
    
    ;AI Reinforcements
    inc_counter AI_reinforcements 1
    
    
    if I_CompareCounter AI_reinforcements = 1
    restart_timer AI_reinforcements_timer
    end_if
    
    
    end_monitor
    
    
    ; *********************************************************************************************
    ;    AI Reinforcements Defend Plan 
    ; *********************************************************************************************
    
    
    monitor_conditions I_CompareCounter AI_reinforcements > 0
    and I_BattlePlayerAllianceOddsInFavour > 1
    and I_TimerElapsed AI_reinforcements_timer < 90000
    
    
    ;AI Units from Army 1 Battle Objective
    ai_gta_add_objective 0 DEFEND_LINE 999
    ;AI Army 1 Battle Objective
    ai_gta_plan_set 0 DEFEND_FEATURE
    ;AI Units from Army 2 Battle Objective
    ai_gta_add_objective 1 DEFEND_LINE 999
    ;AI Army 2 Battle Objective
    ai_gta_plan_set 1 DEFEND_FEATURE
    
    
    end_monitor
    
    
    ; *********************************************************************************************
    ;    AI Reinforcements Attack Plan
    ; *********************************************************************************************
    
    
    monitor_conditions I_CompareCounter AI_reinforcements > 0
    and not I_BattlePlayerArmyIsAttacker
    and I_TimerElapsed AI_reinforcements_timer > 90000
    
    
    ;AI Units from Army 1 Battle Objective
    ai_gta_add_objective 0 ATTACK_ENEMY_BATTLEGROUP 999
    ;AI Army 1 Battle Objective
    ai_gta_plan_set 0 ATTACK_ALL
    ;AI Units from Army 2 Battle Objective
    ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
    ;AI Army 2 Battle Objective
    ai_gta_plan_set 1 ATTACK_ALL
    
    
    end_monitor
    
    
    ; *********************************************************************************************
    ;    AI Unit Monitors & AI Reactions
    ; *********************************************************************************************
    
    
    monitor_conditions I_PercentageUnitKilled Eu1 > 5
    and I_BattleStarted
    and not I_BattleIsSiegeBattle
    
    
    inc_counter AI_GRP 1
    
    
    ;AI Units Battle Objective
    ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
    ;AI Alliance Battle Objective
    ai_gta_plan_set 1 ATTACK_ALL
    
    
    end_monitor
    
    
    monitor_conditions I_PercentageOfArmyKilled 1 0 > 3
    and I_BattleStarted
    and I_BattlePlayerArmyIsAttacker
    and not I_BattleIsSiegeBattle
    
    
    inc_counter AI_GRP 1
    
    
    ;AI Units Battle Objective
    ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
    ;AI Alliance Battle Objective
    ai_gta_plan_set 1 ATTACK_ALL
    
    
    end_monitor
    
    
    ; *********************************************************************************************
    ;    Unit Group Orders - Disabled
    ; *********************************************************************************************
    
    
    ;monitor_conditions I_InBattle
    ;and I_ConflictType Normal
    ;and I_BattleEnemyArmyNumberOfClassAndCategory missile cavalry > 9
    ;and I_PercentageOfArmyKilled 1 0 >= 5
    
    
    ;unit_group_set_morale Enemy routing
    
    
    ;end_monitor
    
    
    monitor_conditions I_BattlePlayerArmyNumberOfAttribute general_unit > 0
    and I_BattleEnemyArmyNumberOfAttribute general_unit = 0
    and I_InBattle
    
    
    ; *********************************************************************************************
    ;    Help The Captain - AI (35% chance of an experienced captain)
    ; *********************************************************************************************
        unit_set_experience Eu1 3
        unit_set_experience Eu2 3
        unit_set_experience Eu3 3
        unit_set_experience Eu4 3
        unit_set_experience Eu5 3
        unit_set_experience Eu6 3
        unit_set_experience Eu7 3
        unit_set_experience Eu8 3
        unit_set_experience Eu9 3
        unit_set_experience Eu10 3
        unit_set_experience Eu11 3
        unit_set_experience Eu12 3
        unit_set_experience Eu13 3
        unit_set_experience Eu14 3
        unit_set_experience Eu15 3
        unit_set_experience Eu16 3
        unit_set_experience Eu17 3
        unit_set_experience Eu18 3
        unit_set_experience Eu19 3
        unit_set_experience Eu20 3
        unit_set_experience Eu21 3
        unit_set_experience Eu22 3
        unit_set_experience Eu23 3
        unit_set_experience Eu24 3
        unit_set_experience Eu25 3
        unit_set_experience Eu26 3
        unit_set_experience Eu27 3
        unit_set_experience Eu28 3
        unit_set_experience Eu29 3
        unit_set_experience Eu30 3
        unit_set_experience Eu31 3
        unit_set_experience Eu32 3
        unit_set_experience Eu33 3
        unit_set_experience Eu34 3
        unit_set_experience Eu35 3
        unit_set_experience Eu36 3
        unit_set_experience Eu37 3
        unit_set_experience Eu38 3
        unit_set_experience Eu39 3
        unit_set_experience Eu40 3
    
    
    ;AI Reinforcements/Main Army get set to the internal label 0 which was previously the players when reinforced
    ;AI Reinforcing Army = MA = 0, AI Reinforcing Army 2 = (E) = 1, Player Army = 2 when there are two reinforcing AI armies
    ;Internal Labels are counted from 0 onwards 
    ;No Random Help The Captain Conditions as this would be an important army/battle if two reinforcements
    if I_CompareCounter AI_Reinforcements > 0
        unit_set_experience MAu1 3
        unit_set_experience MAu2 3
        unit_set_experience MAu3 3
        unit_set_experience MAu4 3
        unit_set_experience MAu5 3
        unit_set_experience MAu6 3
        unit_set_experience MAu7 3
        unit_set_experience MAu8 3
        unit_set_experience MAu9 3
        unit_set_experience MAu10 3
        unit_set_experience MAu11 3
        unit_set_experience MAu12 3
        unit_set_experience MAu13 3
        unit_set_experience MAu14 3
        unit_set_experience MAu15 3
        unit_set_experience MAu16 3
        unit_set_experience MAu17 3
        unit_set_experience MAu18 3
        unit_set_experience MAu19 3
        unit_set_experience MAu20 3
        unit_set_experience MAu21 3
        unit_set_experience MAu22 3
        unit_set_experience MAu23 3
        unit_set_experience MAu24 3
        unit_set_experience MAu25 3
        unit_set_experience MAu26 3
        unit_set_experience MAu27 3
        unit_set_experience MAu28 3
        unit_set_experience MAu29 3
        unit_set_experience MAu30 3
        unit_set_experience MAu31 3
        unit_set_experience MAu32 3
        unit_set_experience MAu33 3
        unit_set_experience MAu34 3
        unit_set_experience MAu35 3
        unit_set_experience MAu36 3
        unit_set_experience MAu37 3
        unit_set_experience MAu38 3
        unit_set_experience MAu39 3
        unit_set_experience MAu40 3
        unit_set_experience Eu1 3
        unit_set_experience Eu2 3
        unit_set_experience Eu3 3
        unit_set_experience Eu4 3
        unit_set_experience Eu5 3
        unit_set_experience Eu6 3
        unit_set_experience Eu7 3
        unit_set_experience Eu8 3
        unit_set_experience Eu9 3
        unit_set_experience Eu10 3
        unit_set_experience Eu11 3
        unit_set_experience Eu12 3
        unit_set_experience Eu13 3
        unit_set_experience Eu14 3
        unit_set_experience Eu15 3
        unit_set_experience Eu16 3
        unit_set_experience Eu17 3
        unit_set_experience Eu18 3
        unit_set_experience Eu19 3
        unit_set_experience Eu20 3
        unit_set_experience Eu21 3
        unit_set_experience Eu22 3
        unit_set_experience Eu23 3
        unit_set_experience Eu24 3
        unit_set_experience Eu25 3
        unit_set_experience Eu26 3
        unit_set_experience Eu27 3
        unit_set_experience Eu28 3
        unit_set_experience Eu29 3
        unit_set_experience Eu30 3
        unit_set_experience Eu31 3
        unit_set_experience Eu32 3
        unit_set_experience Eu33 3
        unit_set_experience Eu34 3
        unit_set_experience Eu35 3
        unit_set_experience Eu36 3
        unit_set_experience Eu37 3
        unit_set_experience Eu38 3
        unit_set_experience Eu39 3
        unit_set_experience Eu40 3
    end_if
    
    
    end_monitor
    
    
    ;Test Order - Player Allies Only 
    ; unit_group_order_relative_move_formed Allies 0 200
    ; I_UnitGroupInRangeOfUnitGroup
    ; I_PercentageUnitGroupKilled
    
    
    ; *********************************************************************************************
    ;    Normal Attack Plan
    ; *********************************************************************************************
    
    
    monitor_conditions I_CompareCounter AI_reinforcements = 0
    and I_ConflictType Normal
    and I_InBattle
    and not I_BattlePlayerArmyIsAttacker
    
    
    ;AI Units Battle Objective
    ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
    ;AI Alliance Battle Objective
    ai_gta_plan_set 1 ATTACK_ALL
    
    
    end_monitor
    
    
    ; *********************************************************************************************
    ;    Normal Defend Plan
    ;    Recurring counters fire above 0
    ; *********************************************************************************************
    
    
    monitor_conditions I_CompareCounter AI_reinforcements = 0
    and I_ConflictType Normal
    and I_InBattle
    and not I_BattleAiAttacking
    and I_BattlePlayerArmyIsAttacker
    
    
    if I_CompareCounter AI_GRP = 0
    ;AI Units Battle Objective Main Army
    ai_gta_add_objective 1 DEFEND_LINE 999
    ;AI Alliance Battle Objective Main Army
    ai_gta_plan_set 1 DEFEND_FEATURE
    end_if
    
    
    if I_CompareCounter AI_GRP > 0
    ;AI Units Battle Objective
    ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
    ;AI Alliance Battle Objective
    ai_gta_plan_set 1 ATTACK_ALL
    end_if
    
    
    end_monitor
    
    
    ; *********************************************************************************************
    ;     Assault Crossing
    ; *********************************************************************************************
    
    
    monitor_conditions I_BattleIsRiverBattle
    and I_InBattle
    and not I_BattlePlayerArmyIsAttacker
    
    
    ;AI Units Battle Objective
    ai_gta_add_objective 1 ASSAULT_CROSSING 999
    ;AI Alliance Battle Objective
    ai_gta_plan_set 1 ATTACK_ALL
    
    
    end_monitor
    
    
    ; *********************************************************************************************
    ;     Assault Settlement 
    ; *********************************************************************************************
    
    
    monitor_conditions I_BattleIsSiegeBattle
    and I_InBattle
    and not I_BattlePlayerArmyIsAttacker
    
    
    ;AI Alliance Battle Objective
    ai_gta_plan_set 1 ATTACK_SETTLEMENT
    
    
    end_monitor
    
    
    ; *********************************************************************************************
    ;     Sally Out 
    ; *********************************************************************************************
    
    
    monitor_conditions I_BattleIsSallyOutBattle
    and I_InBattle
    and not I_BattlePlayerArmyIsAttacker
    
    
    ;AI Units Battle Objective
    ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
    ;AI Alliance Battle Objective
    ai_gta_plan_set 1 ATTACK_ALL
    
    
    end_monitor
    
    
    while I_InBattle
    end_while
    
    
    end_script
    Last edited by z3n; March 11, 2019 at 01:14 PM. Reason: updated
    The AI Workshop Creator
    Europa Barbaroum II AI/Game Mechanics Developer
    The Northern Crusades Lead Developer
    Classical Age Total War Retired Lead Developer
    Rome: Total Realism Animation Developer
    RTW Workshop Assistance MTW2 AI Tutorial & Assistance
    Broken Crescent Submod (M2TW)/IB VGR Submod (BI)/Animation (RTW/BI/ALX)/TATW PCP Submod (M2TW)/TATW DaC Submod (M2TW)/DeI Submod (TWR2)/SS6.4 Northern European UI Mod (M2TW)

  2. #2
    z3n's Avatar State of Mind
    took an arrow to the knee

    Join Date
    Aug 2011
    Posts
    4,640

    Default Re: MTW2 Battle Scripting

    This is the campaign script version (instructions on how to create a campaign script are in the OP). It includes two superfluous parts, one the custom formations and two the customized attribute check created by either Gigantus or QuintusSertorius or a combination of the two. I'm not entirely certain.

    Code:
        ; *********************************************************************************************
        ;    EBII Battle Scripts
        ;    18/4/2016
        ;    z3n
        ; *********************************************************************************************
    
    
        while ! I_BattleStarted
        end_while
    
    
        ; *********************************************************************************************
        ;    EBII Battle Script Counteres/Timers
        ; *********************************************************************************************
    
    
        declare_counter command_and_control
        declare_counter deploy_check
        declare_counter start_battle
        declare_counter FaW_and_S
        declare_counter Release_Labels
        declare_counter AI_GRP
        declare_counter AI_HTC
        declare_counter AI_reinforcements
        declare_counter AI_reinforcements_tc
        declare_timer AI_reinforcements_timer
    
    
        log always EBII Campaign Based Battle Scripts
        log always Activated
    
    
        ; *********************************************************************************************
        ;    EBII Battle Script Frequency Check - sum of battle_wait = total seconds between repeats
        ; *********************************************************************************************
    
    
        monitor_conditions I_InBattle
    
    
            inc_counter command_and_control 1
    
    
            if I_CompareCounter command_and_control = 125
                set_counter command_and_control 0
            end_if
    
    
        end_monitor
    
    
        ; *********************************************************************************************
        ;    Game Reloaded
        ; *********************************************************************************************
    
    
        monitor_event GameReloaded
    
    
            log always Game Reloaded
            set_counter deploy_check 0
            set_counter Release_Labels 0
            set_counter command_and_control 0
            set_counter AI_GRP 0
            set_counter AI_reinforcements 0
            set_counter AI_HTC 0
            log always Battle Scripts Reset
    
    
        end_monitor
    
    
        ; *********************************************************************************************
        ;    Battle Starting
        ; *********************************************************************************************
    
    
        monitor_event ScrollClosed ScrollClosed prebattle_scroll
    
    
            prepare_for_battle
            set_counter command_and_control 0
            set_counter Release_Labels 0
            set_counter AI_GRP 0
            set_counter AI_reinforcements 0
            set_counter AI_HTC 0
            set_counter deploy_check 0
            set_counter capture_pike 0
            set_counter capture_hoplite 0
            set_counter medium_battle 0
            set_counter large_battle 0
            restart_timer AI_reinforcements_timer
    
    
            if I_CompareCounter deploy_check = 0
                log always Battle Loading
            end_if
    
    
        end_monitor
    
    
    
    
        ; *********************************************************************************************
        ;    Shared Reinforcements Monitor
        ; *********************************************************************************************
    
    
        monitor_event BattleReinforcementsArrive
    
    
            ;AI Reinforcements - Set Counter - Fires Once Per Battle
            set_counter AI_reinforcements 1
    
    
        end_monitor
    
    
    
    
        ; *********************************************************************************************
        ;    Battle Started
        ; *********************************************************************************************
    
    
        monitor_conditions I_BattleStarted
    
    
            inc_counter deploy_check 1
    
    
            if I_CompareCounter deploy_check = 1
                log always Battle Started
                set_counter start_battle 1
            end_if
    
    
    
    
        end_monitor
    
    
        ;;;;*************************************************************************************************
        ;;;;    Create Labels
        ;;;;*************************************************************************************************
    
    
        monitor_conditions I_BattleStarted
            and I_CompareCounter start_battle = 1
    
    
            set_counter Release_Labels 1
            set_counter FaW_and_S 1
    
    
            if I_CompareCounter Release_Labels = 1
                set_counter start_battle 0
            end_if
    
    
            if I_CompareCounter deploy_check = 1
                ; *********************************************************************************************
                ;    Main Army unit    Labels
                ; *********************************************************************************************
                label_unit    0 0 0 MAu1
                label_unit    0 0 1 MAu2
                label_unit    0 0 2 MAu3
                label_unit    0 0 3 MAu4
                label_unit    0 0 4 MAu5
                label_unit    0 0 5 MAu6
                label_unit    0 0 6 MAu7
                label_unit    0 0 7 MAu8
                label_unit    0 0 8 MAu9
                label_unit    0 0 9 MAu10
                label_unit    0 0 10 MAu11
                label_unit    0 0 11 MAu12
                label_unit    0 0 12 MAu13
                label_unit    0 0 13 MAu14
                label_unit    0 0 14 MAu15
                label_unit    0 0 15 MAu16
                label_unit    0 0 16 MAu17
                label_unit    0 0 17 MAu18
                label_unit    0 0 18 MAu19
                label_unit    0 0 19 MAu20
                label_unit    0 0 20 MAu21
                label_unit    0 0 21 MAu22
                label_unit    0 0 22 MAu23
                label_unit    0 0 23 MAu24
                label_unit    0 0 24 MAu25
                label_unit    0 0 25 MAu26
                label_unit    0 0 26 MAu27
                label_unit    0 0 27 MAu28
                label_unit    0 0 28 MAu29
                label_unit    0 0 29 MAu30
                label_unit    0 0 30 MAu31
                label_unit    0 0 31 MAu32
                label_unit    0 0 32 MAu33
                label_unit    0 0 33 MAu34
                label_unit    0 0 34 MAu35
                label_unit    0 0 35 MAu36
                label_unit    0 0 36 MAu37
                label_unit    0 0 37 MAu38
                label_unit    0 0 38 MAu39
                label_unit    0 0 39 MAu40
                ; *********************************************************************************************
                ;    Allied unit    Labels
                ; *********************************************************************************************
                label_unit    1 0 0 Eu1
                label_unit    1 0 1 Eu2
                label_unit    1 0 2 Eu3
                label_unit    1 0 3 Eu4
                label_unit    1 0 4 Eu5
                label_unit    1 0 5 Eu6
                label_unit    1 0 6 Eu7
                label_unit    1 0 7 Eu8
                label_unit    1 0 8 Eu9
                label_unit    1 0 9 Eu10
                label_unit    1 0 10 Eu11
                label_unit    1 0 11 Eu12
                label_unit    1 0 12 Eu13
                label_unit    1 0 13 Eu14
                label_unit    1 0 14 Eu15
                label_unit    1 0 15 Eu16
                label_unit    1 0 16 Eu17
                label_unit    1 0 17 Eu18
                label_unit    1 0 18 Eu19
                label_unit    1 0 19 Eu20
                label_unit    1 0 20 Eu21
                label_unit    1 0 21 Eu22
                label_unit    1 0 22 Eu23
                label_unit    1 0 23 Eu24
                label_unit    1 0 24 Eu25
                label_unit    1 0 25 Eu26
                label_unit    1 0 26 Eu27
                label_unit    1 0 27 Eu28
                label_unit    1 0 28 Eu29
                label_unit    1 0 29 Eu30
                label_unit    1 0 30 Eu31
                label_unit    1 0 31 Eu32
                label_unit    1 0 32 Eu33
                label_unit    1 0 33 Eu34
                label_unit    1 0 34 Eu35
                label_unit    1 0 35 Eu36
                label_unit    1 0 36 Eu37
                label_unit    1 0 37 Eu38
                label_unit    1 0 38 Eu39
                label_unit    1 0 39 Eu40
            end_if
    
    
        end_monitor
    
    
        monitor_conditions I_BattleStarted
            and I_BattlePlayerArmyNumberOfAttribute general_unit    > 0
            and I_BattleEnemyArmyNumberOfAttribute general_unit    = 0
    
    
            if I_CompareCounter deploy_check = 1
                ; *********************************************************************************************
                ;    Help The Captain - AI
                ; *********************************************************************************************
                unit_set_experience Eu1 6
                unit_set_experience Eu2 6
                unit_set_experience Eu3 6
                unit_set_experience Eu4 6
                unit_set_experience Eu5 6
                unit_set_experience Eu6 6
                unit_set_experience Eu7 6
                unit_set_experience Eu8 6
                unit_set_experience Eu9 6
                unit_set_experience Eu10 6
                unit_set_experience Eu11 6
                unit_set_experience Eu12 6
                unit_set_experience Eu13 6
                unit_set_experience Eu14 6
                unit_set_experience Eu15 6
                unit_set_experience Eu16 6
                unit_set_experience Eu17 6
                unit_set_experience Eu18 6
                unit_set_experience Eu19 6
                unit_set_experience Eu20 6
                unit_set_experience Eu21 6
                unit_set_experience Eu22 6
                unit_set_experience Eu23 6
                unit_set_experience Eu24 6
                unit_set_experience Eu25 6
                unit_set_experience Eu26 6
                unit_set_experience Eu27 6
                unit_set_experience Eu28 6
                unit_set_experience Eu29 6
                unit_set_experience Eu30 6
                unit_set_experience Eu31 6
                unit_set_experience Eu32 6
                unit_set_experience Eu33 6
                unit_set_experience Eu34 6
                unit_set_experience Eu35 6
                unit_set_experience Eu36 6
                unit_set_experience Eu37 6
                unit_set_experience Eu38 6
                unit_set_experience Eu39 6
                unit_set_experience Eu40 6
            end_if
    
    
        end_monitor
    
    
        monitor_conditions I_BattleStarted
            and I_CompareCounter Release_Labels = 1
    
    
            if I_CompareCounter deploy_check = 1
                ;Must release Main Army, internal army label is recalibrated upon arrival of AI reinforcements causing 1 (previously the main AI army) to become 0 and 1 to become the secondary AI army.
                release_unit    MAu1
                release_unit    MAu2
                release_unit    MAu3
                release_unit    MAu4
                release_unit    MAu5
                release_unit    MAu6
                release_unit    MAu7
                release_unit    MAu8
                release_unit    MAu9
                release_unit    MAu10
                release_unit    MAu11
                release_unit    MAu12
                release_unit    MAu13
                release_unit    MAu14
                release_unit    MAu15
                release_unit    MAu16
                release_unit    MAu17
                release_unit    MAu18
                release_unit    MAu19
                release_unit    MAu20
                release_unit    MAu21
                release_unit    MAu22
                release_unit    MAu23
                release_unit    MAu24
                release_unit    MAu25
                release_unit    MAu26
                release_unit    MAu27
                release_unit    MAu28
                release_unit    MAu29
                release_unit    MAu30
                release_unit    MAu31
                release_unit    MAu32
                release_unit    MAu33
                release_unit    MAu34
                release_unit    MAu35
                release_unit    MAu36
                release_unit    MAu37
                release_unit    MAu38
                release_unit    MAu39
                release_unit    MAu40
                release_unit    Eu1
                release_unit    Eu2
                release_unit    Eu3
                release_unit    Eu4
                release_unit    Eu5
                release_unit    Eu6
                release_unit    Eu7
                release_unit    Eu8
                release_unit    Eu9
                release_unit    Eu10
                release_unit    Eu11
                release_unit    Eu12
                release_unit    Eu13
                release_unit    Eu14
                release_unit    Eu15
                release_unit    Eu16
                release_unit    Eu17
                release_unit    Eu18
                release_unit    Eu19
                release_unit    Eu20
                release_unit    Eu21
                release_unit    Eu22
                release_unit    Eu23
                release_unit    Eu24
                release_unit    Eu25
                release_unit    Eu26
                release_unit    Eu27
                release_unit    Eu28
                release_unit    Eu29
                release_unit    Eu30
                release_unit    Eu31
                release_unit    Eu32
                release_unit    Eu33
                release_unit    Eu34
                release_unit    Eu35
                release_unit    Eu36
                release_unit    Eu37
                release_unit    Eu38
                release_unit    Eu39
                release_unit    Eu40
            end_if
    
    
        end_monitor
    
    
        monitor_conditions I_BattleStarted
            and I_CompareCounter deploy_check = 1
    
    
            set_counter Release_Labels 0
    
    
            if I_CompareCounter Release_Labels = 0
                ; *********************************************************************************************
                ;    Group Labels
                ; *********************************************************************************************
                define_unit_group Allies MAu1 MAu2 MAu3 MAu4 MAu5 MAu6 MAu7 MAu8 MAu9 MAu10 MAu11 MAu12 MAu13 MAu14 MAu15 MAu16 MAu17 MAu18 MAu19 MAu20 MAu21 MAu22 MAu23 MAu24 MAu25 MAu26 MAu27 MAu28 MAu29 MAu30 MAu31 MAu32 MAu33 MAu34 MAu35 MAu36 MAu37 MAu38 MAu39 MAu40
    
    
                define_unit_group Enemy Eu1 Eu2 Eu3 Eu4 Eu5 Eu6 Eu7 Eu8 Eu9 Eu10 Eu11 Eu12 Eu13 Eu14 Eu15 Eu16 Eu17 Eu18 Eu19 Eu20 Eu21 Eu22 Eu23 Eu24 Eu25 Eu26 Eu27 Eu28 Eu29 Eu30 Eu31 Eu32 Eu33 Eu34 Eu35 Eu36 Eu37 Eu38 Eu39 Eu40
    
    
                set_counter FaW_and_S 0
            end_if
    
    
        end_monitor
    
    
        ; *********************************************************************************************
        ;    unit    Group Orders - Disabled
        ; *********************************************************************************************
    
    
        ;monitor_conditions I_BattleStarted
        ;and I_ConflictType Normal
        ;and I_BattleEnemyArmyNumberOfClassAndCategory missile cavalry > 9
        ;and I_PercentageOfArmyKilled 1 0 >= 5
    
    
        ;unit_group_set_morale Enemy routing
    
    
        ;end_monitor
    
    
        ;Test Order - Player Allies Only
        ; unit_group_order_relative_move_formed Allies 0 200
        ; I_UnitGroupInRangeOfUnitGroup
        ; I_PercentageUnitGroupKilled
    
    
        ; *********************************************************************************************
        ;    Initialize Battle Plans & Monitors
        ; *********************************************************************************************
    
    
        ; *********************************************************************************************
        ;    AI Reinforcement Plans
        ; *********************************************************************************************
    
    
        monitor_conditions I_CompareCounter command_and_control = 10
            and I_BattleStarted
            and I_ConflictType Normal
            and I_CompareCounter AI_reinforcements > 0
    
    
            if I_TimerElapsed AI_reinforcements_timer = 5000
                inc_counter AI_reinforcements_tc 1
            end_if
    
    
            if I_TimerElapsed AI_reinforcements_timer > 5000
                restart_timer AI_reinforcements_timer
            end_if
    
    
            ; *********************************************************************************************
            ;    AI Reinforcements Defend Plan
            ; *********************************************************************************************
    
    
            if I_CompareCounter AI_GRP = 0
                and I_CompareCounter AI_reinforcements_tc < 30
                ;AI Units from Army 1 Battle Objective
                ;ai_gta_add_objective 0 DEFEND_LINE 999
                ;AI Army 1 Battle Objective
                ai_gta_plan_set 0 DEFEND_FEATURE
                ;AI Units from Army 2 Battle Objective
                ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
                ;AI Army 2 Battle Objective
                ai_gta_plan_set 1 ATTACK_ALL
            end_if
    
    
            ; *********************************************************************************************
            ;    AI Reinforcements Reaction Plan
            ; *********************************************************************************************
    
    
            if I_CompareCounter AI_reinforcements > 0
                and I_CompareCounter AI_GRP > 0
                ;AI Units from Army 1 Battle Objective
                ai_gta_add_objective 0 ATTACK_ENEMY_BATTLEGROUP 999
                ;AI Army 1 Battle Objective
                ai_gta_plan_set 0 ATTACK_ALL
                ;AI Units from Army 2 Battle Objective
                ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
                ;AI Army 2 Battle Objective
                ai_gta_plan_set 1 ATTACK_ALL
            end_if
    
    
            ; *********************************************************************************************
            ;    AI Reinforcements Attack Plan
            ; *********************************************************************************************
    
    
            if I_CompareCounter AI_reinforcements_tc > 30
                and not I_BattlePlayerArmyIsAttacker
                ;AI Units from Army 1 Battle Objective
                ai_gta_add_objective 0 ATTACK_ENEMY_BATTLEGROUP 999
                ;AI Army 1 Battle Objective
                ai_gta_plan_set 0 ATTACK_ALL
                ;AI Units from Army 2 Battle Objective
                ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
                ;AI Army 2 Battle Objective
                ai_gta_plan_set 1 ATTACK_ALL
            end_if
    
    
        end_monitor
    
    
        ; *********************************************************************************************
        ;    Normal Attack Plan
        ; *********************************************************************************************
    
    
        monitor_conditions I_CompareCounter command_and_control = 20
            and I_BattleStarted
            and I_CompareCounter AI_reinforcements = 0
            and I_ConflictType Normal
            and not I_BattlePlayerArmyIsAttacker
    
    
            ;AI Units Battle Objective
            ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
            ;AI Alliance Battle Objective
            ai_gta_plan_set 1 ATTACK_ALL
    
    
        end_monitor
    
    
        ; *********************************************************************************************
        ;    Normal Defend Plan
        ;    Recurring counters fire above 0
        ; *********************************************************************************************
    
    
        monitor_conditions I_CompareCounter command_and_control = 30
            and I_BattleStarted
            and I_CompareCounter AI_reinforcements = 0
            and I_ConflictType Normal
            and I_BattlePlayerArmyIsAttacker
    
    
            if I_CompareCounter AI_GRP = 0
                ;AI Units Battle Objective Main Army
                ;ai_gta_add_objective 1 DEFEND_LINE 999
                ;AI Alliance Battle Objective Main Army
                ai_gta_plan_set 1 DEFEND_FEATURE
            end_if
    
    
            if I_CompareCounter AI_GRP > 0
                ;AI Units Battle Objective
                ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
                ;AI Alliance Battle Objective
                ai_gta_plan_set 1 ATTACK_ALL
            end_if
    
    
        end_monitor
    
    
        ; *********************************************************************************************
        ;     Assault Crossing
        ; *********************************************************************************************
    
    
        monitor_conditions I_CompareCounter command_and_control = 40
            and I_BattleStarted
            and I_BattleIsRiverBattle
            and not I_BattlePlayerArmyIsAttacker
    
    
            if I_CompareCounter AI_reinforcements = 0
                ;AI Units from Army 2 Battle Objective
                ai_gta_add_objective 1 ASSAULT_CROSSING 999
                ;AI Units from Army 2 Battle Objective
                ai_gta_plan_set 1 ATTACK_ALL
            end_if
    
    
            if I_CompareCounter AI_reinforcements = 1
                and I_CompareCounter AI_reinforcements_tc < 30
                ;AI Alliance Battle Objective
                ai_gta_plan_set 0 DEFEND_FEATURE
                ;AI Alliance Battle Objective 2
                ai_gta_plan_set 1 ATTACK_ALL
                ;AI Units Battle Objective 2
                ai_gta_add_objective 1 ASSAULT_CROSSING 999
            end_if
    
    
            ; *********************************************************************************************
            ;     Assault Crossing - Reinforcements
            ; *********************************************************************************************
    
    
            if I_CompareCounter AI_reinforcements = 1
                and I_CompareCounter AI_reinforcements_tc > 30
                ;AI Units Battle Objective
                ai_gta_add_objective 0 ASSAULT_CROSSING 999
                ;AI Alliance Battle Objective
                ai_gta_plan_set 0 ATTACK_ALL
                ;AI Units Battle Objective 2
                ai_gta_add_objective 1 ASSAULT_CROSSING 999
                ;AI Alliance Battle Objective 2
                ai_gta_plan_set 1 ATTACK_ALL
            end_if
    
    
        end_monitor
    
    
        ; *********************************************************************************************
        ;     Assault Settlement
        ; *********************************************************************************************
    
    
        monitor_conditions I_CompareCounter command_and_control = 50
            and I_BattleStarted
            and I_BattleIsSiegeBattle
            and not I_BattlePlayerArmyIsAttacker
    
    
            if I_CompareCounter AI_reinforcements = 0
                ;AI Alliance Battle Objective
                ai_gta_plan_set 1 ATTACK_SETTLEMENT
            end_if
    
    
            ; *********************************************************************************************
            ;     Assault Settlement - Reinforcements
            ; *********************************************************************************************
    
    
            if I_CompareCounter AI_reinforcements = 1
                and I_CompareCounter AI_reinforcements_tc > 30
                ;AI Alliance Battle Objective
                ai_gta_plan_set 1 ATTACK_SETTLEMENT
                ;AI Alliance Battle Objective 2
                ai_gta_plan_set 0 ATTACK_SETTLEMENT
            end_if
    
    
        end_monitor
    
    
        ; *********************************************************************************************
        ;     Sally Out
        ; *********************************************************************************************
    
    
        monitor_conditions I_CompareCounter command_and_control = 60
            and I_BattleStarted
            and I_BattleIsSallyOutBattle
            and not I_BattlePlayerArmyIsAttacker
    
    
            ;AI Units Battle Objective
            ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
            ;AI Alliance Battle Objective
            ai_gta_plan_set 1 ATTACK_ALL
    
    
            if I_CompareCounter AI_reinforcements = 1
                and I_CompareCounter AI_reinforcements_tc > 30
                ;AI Units Battle Objective
                ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
                ;AI Alliance Battle Objective
                ai_gta_plan_set 1 ATTACK_ALL
                ;AI Units Battle Objective 2
                ai_gta_add_objective 0 ATTACK_ENEMY_BATTLEGROUP 999
                ;AI Alliance Battle Objective 2
                ai_gta_plan_set 0 ATTACK_ALL
            end_if
    
    
        end_monitor
    
    
        ; *********************************************************************************************
        ;     Custom Formations - Can be based on unit    composition - Disabled
        ; *********************************************************************************************
    
    
        ;    monitor_conditions I_CompareCounter command_and_control = 70
        ;        and I_BattleStarted
        ;        and I_ConflictType Normal
    
    
        ;        if I_BattleEnemyArmyNumberOfAttribute rome_gen > 0
        ;            unit_group_order_change_group_formation Enemy ordered_triple_line_1
        ;        end_if
    
    
        ;        if I_BattlePlayerArmyNumberOfAttribute rome_gen > 0
        ;            unit_group_order_change_group_formation Allies ordered_triple_line_1
        ;        end_if
    
    
        ;    end_monitor
    
    
        ; *********************************************************************************************
        ;    AI unit    Monitors
        ; *********************************************************************************************
    
    
        monitor_conditions I_CompareCounter command_and_control = 80
            and I_BattleStarted
            and not I_BattleIsSiegeBattle
            and I_PercentageUnitKilled Eu1 > 5
    
    
            inc_counter AI_GRP 1
    
    
            ;AI Units Battle Objective
            ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
            ;AI Alliance Battle Objective
            ai_gta_plan_set 1 ATTACK_ALL
    
    
        end_monitor
    
    
        ; *********************************************************************************************
        ;    AI Reactions Toward Attacks (Missile/Artillery/Charges)
        ; *********************************************************************************************
    
    
        monitor_conditions I_CompareCounter command_and_control = 90
            and I_BattleStarted
            and I_PercentageOfArmyKilled 1 0 > 3
            and I_BattlePlayerArmyIsAttacker
            and not I_BattleIsSiegeBattle
    
    
            inc_counter AI_GRP 1
    
    
            ;AI Units Battle Objective
            ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
            ;AI Alliance Battle Objective
            ai_gta_plan_set 1 ATTACK_ALL
    
    
        end_monitor
    
    
        ; *********************************************************************************************
        ;     Counters for export
        ; *********************************************************************************************
    
    
        ;    !! declare and reset counters in 'Battle Starting' section !!
    
    
        monitor_conditions I_CompareCounter command_and_control = 100
            and I_BattleStarted
    
    
            ; --- testing for number of units with 'rehire_makedones' attribute in AI army - ie Phalangitai ---
            if I_BattleEnemyArmyNumberOfAttribute rehire_makedones > 0        ; at least one unit    with this attribute was present in the enemy army
                set_counter capture_pike 1
            end_if
    
    
            ; --- testing for number of units with 'rehire_hoplite' attribute in AI army - ie Hoplitai, Etruscans, Liby-Phoenician Infantry or Babylonian Spearmen ---
            if I_BattleEnemyArmyNumberOfAttribute rehire_hoplite > 0        ; at least one unit    with this attribute was present in the enemy army
                set_counter capture_hoplite 1
            end_if
    
    
            ; --- testing for battle size
            if I_BattleEnemyArmyNumberOfUnits > 7
                and I_BattleEnemyArmyNumberOfUnits < 11
                set_counter medium_battle 1            ; this was a medium sized battle
            end_if
            if I_BattleEnemyArmyNumberOfUnits > 10
                set_counter large_battle 1            ; this was a large sized battle
            end_if
    
    
            ; add more tests
        end_monitor
    
    
        ; *** DO NOT ADD BATTLE SCRIPT CODE BELOW THIS LINE!! ***
    
    
        while I_InBattle        ; end of battle script
        end_while
    Last edited by z3n; April 21, 2016 at 01:17 PM. Reason: updated with the campaign script
    The AI Workshop Creator
    Europa Barbaroum II AI/Game Mechanics Developer
    The Northern Crusades Lead Developer
    Classical Age Total War Retired Lead Developer
    Rome: Total Realism Animation Developer
    RTW Workshop Assistance MTW2 AI Tutorial & Assistance
    Broken Crescent Submod (M2TW)/IB VGR Submod (BI)/Animation (RTW/BI/ALX)/TATW PCP Submod (M2TW)/TATW DaC Submod (M2TW)/DeI Submod (TWR2)/SS6.4 Northern European UI Mod (M2TW)

  3. #3
    Gigantus's Avatar I am not special - I am a limited edition.
    Patrician took an arrow to the knee spy of the council

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    53,125
    Blog Entries
    35

    Default Re: MTW2 Battle Scripting

    Great stuff, still going through it. Two things at first glance (will take some time to wrap my head around the finer points of the detailed code):

    - the declare_timer deployment_timer line must be before the restart_timer deployment_timer line, else you will receive a log error. Can't reset something that hasn't been declared yet.
    - a campaign script has a wait_monitors line before the end_script line to facilitate repeated processing of monitors - else it would run only once.

    I quite like the principle of an 'on demand' script section created by the while 'wrapping' at the beginning and end. Makes things easier on the processor. Should come handy for other large\multiple monitor script parts that have only a very specific application.
    Last edited by Gigantus; February 05, 2016 at 09:45 PM.










  4. #4
    z3n's Avatar State of Mind
    took an arrow to the knee

    Join Date
    Aug 2011
    Posts
    4,640

    Default Re: MTW2 Battle Scripting

    Yeah, good point, I was distracted during the writing and wanted to explain the function while I remembered to.

    This is the section I later moved the function to.
    Code:
    monitor_conditions I_TimerElapsed deployment_timer > 101
    and I_InBattle
    and not I_BattleStarted
    
    
    restart_timer deployment_timer
    set_counter AI_GRP 0
    set_counter AI_reinforcements 0
    
    
    end_monitor

    And thank you.
    The AI Workshop Creator
    Europa Barbaroum II AI/Game Mechanics Developer
    The Northern Crusades Lead Developer
    Classical Age Total War Retired Lead Developer
    Rome: Total Realism Animation Developer
    RTW Workshop Assistance MTW2 AI Tutorial & Assistance
    Broken Crescent Submod (M2TW)/IB VGR Submod (BI)/Animation (RTW/BI/ALX)/TATW PCP Submod (M2TW)/TATW DaC Submod (M2TW)/DeI Submod (TWR2)/SS6.4 Northern European UI Mod (M2TW)

  5. #5

    Default Re: MTW2 Battle Scripting

    Is there a way to tell the AI to turn off skirmish mode for some units. For example in Vanilla M2 Norse Archers have fairly good melee skills, but that dose no good for the AI because they still try to skirmish allowing lesser units to slaughter them where if they stand and fight they could well defeat their opponent. You can disable skirmish for specific missile units but I was looking for something more 'conditional.' Also, since the AI dose not 'know' such they will place them out front to fight alone, which defeats the purpose altogether.
    Maybe if x% or if a specific group are engaged or perhaps a melee balance monitor so if their 'melee' units are out matched they could consider some missile units for melee. Maybe set up a PercentageUnitKilled to a timer so if they are in melee for x amount of time they will turn off skirmish mode?

    I don't really know anything about battle scripting, how much control you can or even should exert over the AI's decision making.

  6. #6
    Gigantus's Avatar I am not special - I am a limited edition.
    Patrician took an arrow to the knee spy of the council

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    53,125
    Blog Entries
    35

    Default Re: MTW2 Battle Scripting

    Uh - don't use that font color, please.











  7. #7
    z3n's Avatar State of Mind
    took an arrow to the knee

    Join Date
    Aug 2011
    Posts
    4,640

    Default Re: MTW2 Battle Scripting

    @Gigantus I'm using the blackout theme so I can't see a difference, I'll try and avoid it.

    I've never really tried this and while it should be possible some way or another any way I envision requires one monitor per unit (so probably 40) and one monitor for switching skirmish mode on/off.

    What you'd do is add a monitor for percentage of unit killed like you said then throw in an if conditon for UnitType.

    Look for it in docudemons if you can't see it here(my direct copy and paste might result in an above silver colour^)

    Identifier: UnitType
    Trigger requirements: resource_description
    Parameters: unit type ('type' from export_descr_units.txt)
    Sample use: UnitType roman archer auxillia
    Description: Tests if a unit is of a particular type
    Battle or Strat: Either
    Class: UNIT_TYPE



    So something like

    Code:
    monitor_conditions I_UnitStatus Eu1, fighting 
    (you could add the percentage of killed unit here as well if you want)
    
    if UnitType norse_archers
    set_counter arc1_melee 1
    end_if
    
    end_monitor
    Although thinking about it further you may be able to get the rest into one monitor and just add

    Code:
    if I_CompareCounter arc1_melee = 0
        unit_set_skirmish_mode MAu1 on
    end_if
    
    if I_CompareCounter arc1_melee > 0
        unit_set_skirmish_mode MAu1 off
    end_if
    Of course you'll have to add the set_counter arc1_melee 0 etc etc, to a place in the script for clean up, this section would work.

    Code:
    if I_CompareCounter Release_Labels = 0
    set_counter FaW_and_S 0
    set_counter End_Labels 0
    set_counter deploy_check 0
    end_if

    You might encounter some form of trouble in some way or another as not all scripting is easy to get right on the first time. Speaking from my own experience.
    Last edited by z3n; February 06, 2016 at 12:27 AM. Reason: thought of a better condition
    The AI Workshop Creator
    Europa Barbaroum II AI/Game Mechanics Developer
    The Northern Crusades Lead Developer
    Classical Age Total War Retired Lead Developer
    Rome: Total Realism Animation Developer
    RTW Workshop Assistance MTW2 AI Tutorial & Assistance
    Broken Crescent Submod (M2TW)/IB VGR Submod (BI)/Animation (RTW/BI/ALX)/TATW PCP Submod (M2TW)/TATW DaC Submod (M2TW)/DeI Submod (TWR2)/SS6.4 Northern European UI Mod (M2TW)

  8. #8

    Default Re: MTW2 Battle Scripting

    Is it possible to use "attributes" in a battle script to use instead of UnitType so you would not have to do this for multiple unit types, you would just have to give said units that trait?

    Finally, is it possible to get the game to run a battle script for "custom battle"

  9. #9
    z3n's Avatar State of Mind
    took an arrow to the knee

    Join Date
    Aug 2011
    Posts
    4,640

    Default Re: MTW2 Battle Scripting

    Unfortunately the attributes part is limited to armies as far as I can tell, rather than unit labels.

    The closest alternative I could think of was this condition but it is limited in the sense that a few mods remove this ability and I wasn't sure if your mod does that. In any case you're no doubt experienced enough to know what's what in regards to that.

    BattleEnemyUnitSpecialAbilitySupported = flaming_ammo

    Also note that docudemons incorrectly pasted all of the "Enemy" conditions. So you have to fix the "batt" and "nemy"

    BattnemyUnitSpecialAbilitySupported

    By changing it to this

    BattleEnemyUnitSpecialAbilitySupported

    A relatively simple fix (and note this of course applies to single BattNemy of which there are many) but really confusing if you're testing the command directly from the docudemons for the first few times. It was to me at least.
    Last edited by z3n; February 06, 2016 at 03:17 PM.
    The AI Workshop Creator
    Europa Barbaroum II AI/Game Mechanics Developer
    The Northern Crusades Lead Developer
    Classical Age Total War Retired Lead Developer
    Rome: Total Realism Animation Developer
    RTW Workshop Assistance MTW2 AI Tutorial & Assistance
    Broken Crescent Submod (M2TW)/IB VGR Submod (BI)/Animation (RTW/BI/ALX)/TATW PCP Submod (M2TW)/TATW DaC Submod (M2TW)/DeI Submod (TWR2)/SS6.4 Northern European UI Mod (M2TW)

  10. #10
    Gigantus's Avatar I am not special - I am a limited edition.
    Patrician took an arrow to the knee spy of the council

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    53,125
    Blog Entries
    35

    Default Re: MTW2 Battle Scripting

    I have been puttering around with the script and I am bothered by the high amount of log entries (one every 35 milliseconds) the 'timer elapsed' condition creates.
    The way I read it the two monitors could safely be terminated once they have done their job. I am however not sure if that would make them unavailable the next time the battle script runs (odds are that is the case).
    Otherwise wouldn't it be more efficient to combine the first three monitors:
    Code:
        monitor_conditions I_TimerElapsed deployment_timer > 0
            if I_InBattle
                and I_TimerElapsed deployment_timer > 101
                and not I_BattleStarted
    
                restart_timer deployment_timer
                set_counter AI_GRP 0
                set_counter AI_reinforcements 0
            end_if
    
            if I_TimerElapsed deployment_timer < 101
                and I_InBattle
    
                prepare_for_battle
                set_counter AI_HTC 0
                set_counter deploy_check 1
            end_if
    
            if I_CompareCounter deploy_check = 1    ; will always fire if timer is less then 101
                and I_BattleStarted
    
                set_counter start_battle 1
                ; terminate_monitor                    ; only possible if monitor can be re-used
            end_if
        end_monitor
    Edit: come to think of it - is the timer actually required?

    Code:
        monitor_conditions I_InBattle                ; we are in a battle (not in the campaign)
            prepare_for_battle                        : clear all labels, locations
            set_counter AI_HTC 0
            set_counter deploy_check 1                ; create a deploy check - not really needed in this set up
    
            if not I_BattleStarted                    ; the battle has not started yet
                set_counter AI_GRP 0
                set_counter AI_reinforcements 0
            end_if
    
            if I_BattleStarted                            ; the battle has started
                and I_CompareCounter deploy_check = 1    ; the deploy check is set - not really needed in this set up
                set_counter start_battle 1                ; flag the battle start
            end_if
    
        end_monitor
    Last edited by Gigantus; February 07, 2016 at 12:16 AM.










  11. #11
    z3n's Avatar State of Mind
    took an arrow to the knee

    Join Date
    Aug 2011
    Posts
    4,640

    Default Re: MTW2 Battle Scripting

    @CavalryCmdr I did not mention that custom battle scripts are possible through the advisor activation of a script



    @Gigantus Termination of monitors means a battle script you want to loop in every battle will only work once when activating a script via the advisor until your RAM is cleared when you close the game and reload it.


    The timer is required for the prepare for battle cleanup. Otherwise heavy instability develops when fighting any battle with a different troop composition (number), due to the way labels work. Note while I say required what I really mean is that there needs to be a way to clean up the battle scripts functions due to the goal of looping a battle script throughout the campaign rather than just executing once in a single historical battle.
    The AI Workshop Creator
    Europa Barbaroum II AI/Game Mechanics Developer
    The Northern Crusades Lead Developer
    Classical Age Total War Retired Lead Developer
    Rome: Total Realism Animation Developer
    RTW Workshop Assistance MTW2 AI Tutorial & Assistance
    Broken Crescent Submod (M2TW)/IB VGR Submod (BI)/Animation (RTW/BI/ALX)/TATW PCP Submod (M2TW)/TATW DaC Submod (M2TW)/DeI Submod (TWR2)/SS6.4 Northern European UI Mod (M2TW)

  12. #12
    Gigantus's Avatar I am not special - I am a limited edition.
    Patrician took an arrow to the knee spy of the council

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    53,125
    Blog Entries
    35

    Default Re: MTW2 Battle Scripting

    Doesn't the timer simply slow down the executing frequency of the condition monitor? In my second code batch the 'prepare_for_battle' should execute roughly 3 times per second, seeing that it resets labels it's very likely way too fast\frequent to let other script parts perform actions based on those labels?

    If so then I reckon this set up might the most economic (re some talk we had at EBII)
    Code:
        monitor_conditions I_TimerElapsed deployment_timer > 2000
            and I_InBattle                              ; we are in a battle (not in the campaign)
            prepare_for_battle                        : clear all labels, locations
            restart_timer deployment_timer              ; reset timer
            set_counter AI_HTC 0
            set_counter deploy_check 1                ; create a deploy check
        end_monitor
    
        monitor_conditions I_TimerElapsed deployment_timer < 2000
            if not I_BattleStarted                    ; the battle has not started yet
                set_counter AI_GRP 0
                set_counter AI_reinforcements 0
            end_if
    
            if I_BattleStarted                            ; the battle has started
                and I_CompareCounter deploy_check = 1    ; the deploy check is set
                set_counter start_battle 1                ; flag the battle start
            end_if
        end_monitor
    Last edited by Gigantus; February 07, 2016 at 06:04 AM.










  13. #13
    z3n's Avatar State of Mind
    took an arrow to the knee

    Join Date
    Aug 2011
    Posts
    4,640

    Default Re: MTW2 Battle Scripting

    It was actually less about the frequency and taking into account a player suddenly exiting the battle right after starting and then causing a crash in future ones.

    It's true any unit group orders for example would be cleared unfortunately, for example todays brief couple of tests (only about two hours and now I have to go out unfortunately) was the feasibility of this -

    Code:
    monitor_conditions I_InBattle
    and I_ConflictType Normal
    
    
    if I_BattleEnemyArmyNumberOfAttribute rome_gen > 0
    unit_group_order_change_group_formation Enemy ordered_triple_line_1
    end_if
    
    
    if I_BattlePlayerArmyNumberOfAttribute rome_gen > 0
    unit_group_order_change_group_formation Allies ordered_triple_line_1
    end_if
    
    
    end_monitor
    The result was this but it was only partially successful.

    15:10:48.409 [game.script.exec] [trace] exec <if> at line 755 in mods/EBII/data/scripts/show_me/background_script.txt
    15:10:48.409 [game.script.exec] [trace] exec <unit_group_order_change_group_formation> at line 755 in mods/EBII/data/scripts/show_me/background_script.txt
    15:10:48.409 [game.script.exec] [trace] exec <if> at line 759 in mods/EBII/data/scripts/show_me/background_script.txt


    More later, as I really must go out.
    The AI Workshop Creator
    Europa Barbaroum II AI/Game Mechanics Developer
    The Northern Crusades Lead Developer
    Classical Age Total War Retired Lead Developer
    Rome: Total Realism Animation Developer
    RTW Workshop Assistance MTW2 AI Tutorial & Assistance
    Broken Crescent Submod (M2TW)/IB VGR Submod (BI)/Animation (RTW/BI/ALX)/TATW PCP Submod (M2TW)/TATW DaC Submod (M2TW)/DeI Submod (TWR2)/SS6.4 Northern European UI Mod (M2TW)

  14. #14

    Default Re: MTW2 Battle Scripting

    Quote Originally Posted by z3n
    @CavalryCmdr I did not mention that custom battle scripts are possible through the advisor activation of a script
    Ok, 'for the dummy' version, please, how would I set your skynet BAI script to run in custom battles?

  15. #15
    z3n's Avatar State of Mind
    took an arrow to the knee

    Join Date
    Aug 2011
    Posts
    4,640

    Default Re: MTW2 Battle Scripting

    Actually it's extremely simple/easy.

    You just need to change two files in your mod or any mod

    1) export_descr_advice paste this into the top

    Code:
    ;------------------------------------------
    AdviceThread BackgroundScriptThread
        GameArea Battle
    
    
        Item Background_Script_Text_01
            Uninhibitable
            Verbosity  0
            Priority  6
            Threshold  1
            MaxRepeats  0
            RepeatInterval  1
            Attitude Normal
            Presentation Default
            Title Background_Script_Title
    		On_display scripts\show_me\background_script.txt
            Text Background_Script_Text1
    And paste this into the bottom

    Code:
    ;------------------------------------------
    Trigger background_script_trigger_1
       WhenToTest BattleDeploymentPhaseCommenced
    
    
        Condition I_EventCounter DifficultyLevel < 1
    
    
    		  AdviceThread BackgroundScriptThread  1
    2) export_advice in the text folder needs this added to the top or bottom (your choice)

    Code:
    {Background_Script_Title}Launching Scripts
    {Background_Script_Text1}Skynet v1.1\n\nPlease remember activate the scripts before you start the battle. \n\nIf you have any feedback please head over to the Europa Barbaroum II forums on twcenter or the Org.
    3a) Simply extract the scripts folder into your mod
    or 3b) Manually the background script into scripts/show_me (create the directory if it doesn't exist)

    Either option works fine, it makes no difference which one you pick, so long as the background_script exists in a scripts/show_me folder.


    Once all that is done, all you need to do is load up a custom battle, then left click on the advisor and the script will run. You can left click again to dismiss it (with the script still activated in the background).
    The AI Workshop Creator
    Europa Barbaroum II AI/Game Mechanics Developer
    The Northern Crusades Lead Developer
    Classical Age Total War Retired Lead Developer
    Rome: Total Realism Animation Developer
    RTW Workshop Assistance MTW2 AI Tutorial & Assistance
    Broken Crescent Submod (M2TW)/IB VGR Submod (BI)/Animation (RTW/BI/ALX)/TATW PCP Submod (M2TW)/TATW DaC Submod (M2TW)/DeI Submod (TWR2)/SS6.4 Northern European UI Mod (M2TW)

  16. #16

    Default Re: MTW2 Battle Scripting

    maybe it is already beenwrited here but i saw that in lusted battle ai the spearmen went into schiltrom,when there was cavalry close too it,how can you script this,that spearmen go into schiltrom when they are close too cavalry,becausce this is the only way too stop cavalry chrage,maybe it's outside script,and in the config_ai_battle file?

  17. #17
    z3n's Avatar State of Mind
    took an arrow to the knee

    Join Date
    Aug 2011
    Posts
    4,640

    Default Re: MTW2 Battle Scripting

    The quickest way to fix cavalry charges is lower the melee hit rate in the battle config file.

    While scripting it is probably possible using the unitradius condition and activating the special ability (command should be ignored if they don't have it) I believe you just don't want cavalry to be OP (me either). I could write a script for it if you don't want to lower the melee hit rate, although no promises as to whether it will function exactly as intended until after I test it.
    The AI Workshop Creator
    Europa Barbaroum II AI/Game Mechanics Developer
    The Northern Crusades Lead Developer
    Classical Age Total War Retired Lead Developer
    Rome: Total Realism Animation Developer
    RTW Workshop Assistance MTW2 AI Tutorial & Assistance
    Broken Crescent Submod (M2TW)/IB VGR Submod (BI)/Animation (RTW/BI/ALX)/TATW PCP Submod (M2TW)/TATW DaC Submod (M2TW)/DeI Submod (TWR2)/SS6.4 Northern European UI Mod (M2TW)

  18. #18

    Default Re: MTW2 Battle Scripting

    would be nice too have a script about it,thanks for the information.

  19. #19
    z3n's Avatar State of Mind
    took an arrow to the knee

    Join Date
    Aug 2011
    Posts
    4,640

    Default Re: MTW2 Battle Scripting

    First you'll have to create and assign unit labels, and also clean up your script with a prepare_for_battle command.
    Also note that there's a new update coming to battle scripting with an alternative fully working campaign script format. It was pretty difficult to write but it's nearly complete and fully working far as we can tell. There was actually a problem with putting a script straight into a campaign script, due to MTW2's scripting engine and how it processes battle commands on a strat map. Which can cause crashes upon loading a save, of course the export_descr_advice script way didn't have this problem. In any case that is fully fixed in the newly written campaign script version, it's just being fine tuned with changes like resolving the unnecessary overflow of lines in the script while using trace logs.

    Here's the code, sorry for being late and not being able to fully test this but I really got sidetracked with the above.

    Code:
    (your unit labels/prepare_for_battle commands, counters etc go here - check my script above if you don't know what I'm talking about)
    
    monitor_conditions I_UnitStatus (unit label goes here without brackets leave the comma in), idling
    
    if I_BattleEnemyArmyPercentageOfAttribute knight > 25.0
    unit_order_change_formation (unit label goes here without brackets) schiltrom
    end_if
    
    (and here is an alternative if, see below for more info)
    
    if I_BattleEnemyArmyNumberOfAttribute hes_on_a_horse > 0
    unit_order_change_formation (unit label goes here without brackets) schiltrom
    end_if
    
    end_monitor
    Repeat 19-39 times depending on how many units you labeled originally.
    Note that you can create a custom attribute, as they're just data objects as far as I understand it. So you can easily attach it to all the units in the EDU (export_descr_unit) you want to be considered as horsemen. For example you can add 'hes_on_a_horse' to all the lancers/knights in your EDU as an attribute then check for that in the script.



    You have to remember to read the above tutorial for information about how internal labels are assigned as well.

    Percentage/number of units work in their own ways, percentage follows the idea where if there is a signifigant force of cavalry, form a schiltrom when idle/not moving/not charging etc. While number is reliant solely on number and logic tokens (a fancy way of saying greater/lesser signs and or an equal sign).
    The AI Workshop Creator
    Europa Barbaroum II AI/Game Mechanics Developer
    The Northern Crusades Lead Developer
    Classical Age Total War Retired Lead Developer
    Rome: Total Realism Animation Developer
    RTW Workshop Assistance MTW2 AI Tutorial & Assistance
    Broken Crescent Submod (M2TW)/IB VGR Submod (BI)/Animation (RTW/BI/ALX)/TATW PCP Submod (M2TW)/TATW DaC Submod (M2TW)/DeI Submod (TWR2)/SS6.4 Northern European UI Mod (M2TW)

  20. #20

    Default Re: MTW2 Battle Scripting

    wow mine head is already going dizzy lol,thanks for this information gonna try it some time.never known that unit label schould be in the export_descr_unit file,now i understand the sometimes errors report from unknown labels in the log.it would be great if i can not charge in a total unrepeared unit!

Page 1 of 4 1234 LastLast

Posting Permissions

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