Results 1 to 9 of 9

Thread: [Mini Tutorial] The new revolts script

  1. #1

    Default [Mini Tutorial] The new revolts script

    As requested, I've started a new thread as a mini-tutorial on scripting in EBII. Once you get the hang of it, scripting is pretty straightforward, and the game is forgiving enough to tell you when you've done something wrong.

    Here's a sample of the new "revolts" script, featuring three types of region: a regular one (Histria kai Liburnia), a Troublesome Region (Asturia-Kantabria) and a small island region (Korsim):

    Code:
        monitor_event PreFactionTurnStart FactionType slave
            ; Histria kai Liburnia
            if I_EventCounter RisingSpawn003 > 24    ; cooldown has ended
                generate_random_counter sett_003_rising 1 50
                if I_EventCounter sett_003_rising < 2   ; 2% chance
                    spawn_army
                        faction slave, sub_faction f_getai
                        character	random_name, named character, age 30, x 143, y 178, portrait barb2
                        traits  SlaveGetaiModel 1 , CommandExperience 2, GoodLeader 1, HaleAndHearty 2, TurnsAlive 2
                        unit		italic infantry histro venetic		exp 4 armour 0 weapon_lvl 0
                        unit		illyrian infantry thureophoroi	exp 1 armour 0 weapon_lvl 0
                        unit		illyrian infantry thureophoroi	exp 0 armour 0 weapon_lvl 0
                        unit		illyrian infantry peltastai	exp 0 armour 0 weapon_lvl 0
                        unit		illyrian infantry peltastai	exp 0 armour 0 weapon_lvl 0
                    end
                    set_event_counter RisingSpawn003 0 ; resetting cooldown
                end_if
                if I_EventCounter sett_003_rising = 20 ; 2% chance
                    spawn_army
                        faction slave, sub_faction f_getai
                        character	random_name, named character, age 30, x 139, y 184, portrait barb3
                        traits  SlaveGetaiModel 1 , CommandExperience 2, GoodLeader 1, HaleAndHearty 2, TurnsAlive 2
                        unit		italic infantry histro venetic		exp 4 armour 0 weapon_lvl 0
                        unit		illyrian infantry thureophoroi	exp 1 armour 0 weapon_lvl 0
                        unit		illyrian infantry thureophoroi	exp 0 armour 0 weapon_lvl 0
                        unit		illyrian infantry peltastai	exp 0 armour 0 weapon_lvl 0
                        unit		illyrian infantry peltastai	exp 0 armour 0 weapon_lvl 0
                    end
                    set_event_counter RisingSpawn003 0 ; resetting cooldown
                end_if
                if I_EventCounter sett_003_rising > 49 ; 2% chance
                    spawn_army
                        faction slave, sub_faction f_getai
                        character	random_name, named character, age 30, x 135, y 186, portrait barb4
                        traits  SlaveGetaiModel 1 , CommandExperience 3, GoodDefender 1, GoodLeader 1, HaleAndHearty 2, TurnsAlive 2
                        unit		illyrian cavalry hippeis		exp 4 armour 0 weapon_lvl 0
                        unit		italic infantry histro venetic	exp 1 armour 0 weapon_lvl 0
                        unit		illyrian infantry thureophoroi 	exp 0 armour 0 weapon_lvl 0
                        unit		illyrian infantry thureophoroi	exp 0 armour 0 weapon_lvl 0
                        unit		illyrian infantry thureophoroi	exp 0 armour 0 weapon_lvl 0
                        unit		illyrian infantry peltastai	exp 1 armour 0 weapon_lvl 0
                        unit		illyrian infantry peltastai	exp 0 armour 0 weapon_lvl 0
                        unit		hellenistic infantry sphendonitai		exp 0 armour 0 weapon_lvl 0
                    end
                    if I_SettlementOwner sett_003 != slave
                        add_settlement_turmoil sett_003 2              ; unrest in settlement
                    end_if
                    set_event_counter RisingSpawn003 0 ; resetting cooldown
                end_if
            end_if
            ; Asturia-Kantabria
            if I_EventCounter RisingSpawn016 > 11    ; cooldown has ended
                generate_random_counter sett_016_rising 1 40
                if I_EventCounter sett_016_rising < 2   ; 2.5% chance
                    spawn_army
                        faction slave, sub_faction f_arevaci
                        character	random_name, named character, age 30, x 49, y 183, portrait iberian2
                        traits  SlaveBoiiModel 1 , CommandExperience 2, GoodLeader 1, HaleAndHearty 2, TurnsAlive 2
                        unit		celtiberian cavalry rider		exp 4 armour 0 weapon_lvl 0
                        unit		celtiberian infantry dunaminaca swordsmen		exp 1 armour 0 weapon_lvl 0
                        unit		celtiberian infantry dunaminaca spearmen	exp 0 armour 0 weapon_lvl 0
                        unit		celtiberian infantry dunaminaca spearmen	exp 0 armour 0 weapon_lvl 0
                        unit		iberian infantry skirmisher	exp 0 armour 0 weapon_lvl 0
                    end
                    set_event_counter RisingSpawn016 0 ; resetting cooldown
                end_if
                if I_EventCounter sett_016_rising = 20 ; 2.5% chance
                    spawn_army
                        faction slave, sub_faction f_arevaci
                        character	random_name, named character, age 30, x 40, y 177, portrait iberian3
                        traits  SlaveBoiiModel 1 , CommandExperience 2, GoodLeader 1, HaleAndHearty 2, TurnsAlive 2
                        unit		celtiberian cavalry rider		exp 4 armour 0 weapon_lvl 0
                        unit		celtiberian infantry dunaminaca swordsmen		exp 1 armour 0 weapon_lvl 0
                        unit		celtiberian infantry dunaminaca spearmen	exp 0 armour 0 weapon_lvl 0
                        unit		celtiberian infantry dunaminaca spearmen	exp 0 armour 0 weapon_lvl 0
                        unit		iberian infantry skirmisher	exp 0 armour 0 weapon_lvl 0
                    end
                    set_event_counter RisingSpawn016 0 ; resetting cooldown
                end_if
                if I_EventCounter sett_016_rising > 39 ; 2.5% chance
                    spawn_army
                        faction slave, sub_faction f_arevaci
                        character	random_name, named character, age 30, x 44, y 177, portrait iberian4
                        traits  SlaveBoiiModel 1 , CommandExperience 3, GoodDefender 1, GoodLeader 1, HaleAndHearty 2, TurnsAlive 2
                        unit		iberian cavalry cantabrian		exp 4 armour 0 weapon_lvl 0
                        unit		celtiberian infantry dunaminaca swordsmen		exp 1 armour 0 weapon_lvl 0
                        unit		celtiberian infantry dunaminaca spearmen	exp 0 armour 0 weapon_lvl 0
                        unit		celtiberian infantry dunaminaca spearmen	exp 0 armour 0 weapon_lvl 0
                        unit		iberian infantry spearman	exp 0 armour 0 weapon_lvl 0
                        unit		iberian infantry spearman	exp 0 armour 0 weapon_lvl 0
                        unit		iberian infantry skirmisher	exp 0 armour 0 weapon_lvl 0
                        unit		iberian infantry shepherd slinger		exp 0 armour 0 weapon_lvl 0
                    end
                    if I_SettlementOwner sett_016 != slave
                        add_settlement_turmoil sett_016 4              ; unrest in settlement
                    end_if
                    set_event_counter RisingSpawn016 0 ; resetting cooldown
                end_if
            end_if
            ; Korsim
            if I_EventCounter RisingSpawn048 > 24    ; cooldown has ended
                generate_random_counter sett_048_rising 1 50
                if I_EventCounter sett_048_rising < 2   ; 2% chance
                    spawn_army
                        faction slave, sub_faction f_rome
                        character	random_name, named character, age 30, x 111, y 169
                        traits  SlaveRomanModel 1 , CommandExperience 2, GoodLeader 1, HaleAndHearty 2, TurnsAlive 2
                        unit		italic infantry etruscan		exp 4 armour 0 weapon_lvl 0
                        unit		ligurian infantry spearmen	exp 1 armour 0 weapon_lvl 0
                        unit		ligurian infantry spearmen	exp 0 armour 0 weapon_lvl 0
                        unit		roman infantry leves	exp 0 armour 0 weapon_lvl 0
                        unit		hellenistic infantry sphendonitai	exp 0 armour 0 weapon_lvl 0
                    end
                    set_event_counter RisingSpawn048 0 ; resetting cooldown
                end_if
                if I_EventCounter sett_048_rising > 49 ; 2% chance
                    spawn_army
                        faction slave, sub_faction f_rome
                        character	random_name, named character, age 30, x 113, y 167
                        traits  SlaveRomanModel 1 , CommandExperience 3, GoodDefender 1, GoodLeader 1, HaleAndHearty 2, TurnsAlive 2
                        unit		italic infantry etruscan		exp 4 armour 0 weapon_lvl 0
                        unit		ligurian infantry spearmen	exp 1 armour 0 weapon_lvl 0
                        unit		ligurian infantry spearmen	exp 0 armour 0 weapon_lvl 0
                        unit		roman infantry leves	exp 0 armour 0 weapon_lvl 0
                        unit		hellenistic infantry sphendonitai	exp 0 armour 0 weapon_lvl 0
                    end
                    if I_SettlementOwner sett_048 != slave
                        add_settlement_turmoil sett_048 2              ; unrest in settlement
                    end_if
                    set_event_counter RisingSpawn048 0 ; resetting cooldown
                end_if
            end_if
            ; Cooldown increments
            inc_event_counter RisingSpawn003 1         ; increasing cooldown counter every turn
            inc_event_counter RisingSpawn016 1
            inc_event_counter RisingSpawn048 1
        end_monitor
    First some basics.

    Always use Notepad++ for any scripting adjustments you make, and do your drafting in a separate tab. Do not edit the campaign_script directly as a live document; it will crash, corrupting itself in the process. Every file over 5MB or so tends to do that - and the EBII campaign_script is over 13MB. Do not start lines with tabs, you have to replace them with spaces (one tab = four spaces), and beware tabs must be used in "unit" lines or they won't be read properly. It pays to check over your formatting by showing all characters from time to time, before you transpose your work into the script. As much as possible, use copying+pasting of things you know work, and take details like unit and trait names from their sources to avoid data entry errors. If you copy from the code chunk above, it should copy the spaces and tabs. It will also copy the intending I've used, which makes it much easier to read - whenever you put in an IF statement, you indent four spaces on the line afterwards.

    Every chunk of script is centred around a monitor - it might be monitor_events or monitor_conditions. The EBII script is comprised entirely of the former, because they're easier to use. A monitor opened by monitor_events must be closed by end_monitor. The conditions after the monitor type control the sequencing/triggering of whatever is sandwiched between the start and end. In this instance, it's the very beginning of the slave turn, so the Rebel CAI has the opportunity to do something with the revolt spawns after they appear - that means there's some variability in what happens before the player gets a chance to respond. They might stay put and devastate, or they might move and do something. They can't hire mercs, because Rebel FMs are barred from doing so by their culture (the descr_mercenaries restricts it only to the cultures used by the playable factions).

    The two critical parameters governing this script are the timer (RisingSpawnxxx) and randomiser (sett_nnn_rising).

    The timer increments by one point every single turn - that's the block at the bottom of the script, and there needs to be a line for each settlement (I've only included the three relevant ones in the sample, there are 199 in the full script), so that they are all fully independent of each other. When it reaches a given threshold (25 for most settlements - ie 25 turns have passed without it being reset), it then allows the randomiser to trigger.

    That "rolls dice" every turn after the 25th since the last reset, with a value between the parameters given (1-50 for most factions). If it rolls a 1, 20 or 50, a spawn is triggered, and the timer is reset to 0 (meaning it can't happen again for at least 25 turns). Two of those spawns are small (5 units), and appear away from the settlement. The third is bigger (8 units), appears close by, and also triggers unrest if it's not a Rebel-held province. The composition of the spawns is based either on natives in the region (especially if it has highland/border zones) or that of raiders from neighbouring ones.

    Troublesome Regions have a lower cooldown and higher spawn chance. There are 18 of them, places noted historically as being febrile.

    Islands are too small to allow the script to run at the normal rate, they'd fill up with Rebels if the AI failed to deal with them, so they only have two smaller spawns, and cumulatively have a lower chance of incidence as a result.

    And that's about it. Any questions?

  2. #2

    Default Re: [Mini Tutorial] The new revolts script

    What language is this? Is it written specifically for the rtw-mtw2 engine?

  3. #3

    Default Re: [Mini Tutorial] The new revolts script

    Quote Originally Posted by NosPortatArma View Post
    What language is this? Is it written specifically for the rtw-mtw2 engine?
    I think it's proprietary; while very basic, I haven't seen anything like it elsewhere.

  4. #4

    Default Re: [Mini Tutorial] The new revolts script

    Thank you so much for this!!!!!!!!!

    Is there a way to randomize the type of units between an individual spawn? Like, say having your sample stack generate 3 Illyrian thureophoroi and/or hoplites?

  5. #5

    Default Re: [Mini Tutorial] The new revolts script

    Quote Originally Posted by Krampus View Post
    Thank you so much for this!!!!!!!!!

    Is there a way to randomize the type of units between an individual spawn? Like, say having your sample stack generate 3 Illyrian thureophoroi and/or hoplites?
    Only by adding another randomiser, and an entirely new spawn for every set of eventualities you want to represent. You can't randomise within a spawn, if that's what you're thinking.

    In other words, lots of replication. What's your appetite for copying and pasting?
    Last edited by QuintusSertorius; April 18, 2019 at 08:42 AM.

  6. #6
    Campidoctor
    Join Date
    Jan 2005
    Location
    AEnima City, USA
    Posts
    1,646

    Default Re: [Mini Tutorial] The new revolts script

    Quote Originally Posted by QuintusSertorius View Post
    What's your appetite for copying and pasting?
    Al Pacino delivers the following line: "iiiiii'm STAAARRRVVVIINNNG".

  7. #7

    Default Re: [Mini Tutorial] The new revolts script

    Quote Originally Posted by Dooz View Post
    Al Pacino delivers the following line: "iiiiii'm STAAARRRVVVIINNNG".
    There is a slightly easier method, rather than adding another randomiser, using the structure that's already there, though it's still lots of copypasta. Let's say you want three compositions per spawn. Triple the range of the randomiser (so from 1 50 to 1 150). Then copy each IF loop with the spawn in it twice, change the number it triggers on (choose an = within the range of 1 to 150), then alter the composition to taste.

  8. #8

    Default Re: [Mini Tutorial] The new revolts script

    Quote Originally Posted by QuintusSertorius View Post
    There is a slightly easier method, rather than adding another randomiser, using the structure that's already there, though it's still lots of copypasta. Let's say you want three compositions per spawn. Triple the range of the randomiser (so from 1 50 to 1 150). Then copy each IF loop with the spawn in it twice, change the number it triggers on (choose an = within the range of 1 to 150), then alter the composition to taste.
    Sweet :3

    I swear, editing text files for these mods has been my gateway into learning programming...

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

    Join Date
    Aug 2011
    Posts
    4,640

    Default Re: [Mini Tutorial] The new revolts script

    Quote Originally Posted by NosPortatArma View Post
    What language is this? Is it written specifically for the rtw-mtw2 engine?
    Yes, it's written just for RTW / M2TW engine. Don't ask me why they (CA) decided do such a thing...
    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)

Posting Permissions

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