Results 1 to 12 of 12

Thread: Beginner's Scripting Guide

  1. #1

    Default Beginner's Scripting Guide

    Hello all . With this post , i hope to get a lot more players/modders interested in scripting . Most people get lost in scipting immediatly , and then say that it's way to hard . I used to do this too , until i kept trying again , and now i really like scripting ..

    It's all about the way you approach it . Some tutorials for scripting just ask to copy-paste a certain script in the appropriate folders and teach you almost nothing . Others start off good , but become to complicated at the end .

    I'll try to come off as gentle as possible with this tutorial . We'll take it step-by-step , and i'll try to make it easy to understand ..

    But at first , we need a background script . I won't give any further comments about this , since HouseOfHam already has an excellent post about it . Check it out here :

    http://www.twcenter.net/forums/showthread.php?t=169689

    Step 1 : How to make a script

    Step 2 : Basic conditions and commands

    Step 3 : Making more complicated scripts

    Step 4 : Some other stuff

    Step 5 : What if's and counters ?



    Last edited by Killerbee; May 23, 2009 at 09:33 AM.

  2. #2

    Default Re: Beginner's Scripting Guide

    Step 1 : How to make a script

    Spoiler Alert, click show to read: 


    Once you have a background script , open the file in your data/scripts/show_me folder called background_script (so the folder in wich you made your background script) . If you took it from HoH's tutorial (HoH = HouseOfHam) , then it should look like this :

    Spoiler Alert, click show to read: 
    Code:
    script
    
    ; Anything following a semicolon is a comment.
    
    ; Remove the adviser portrait from screen.
    select_ui_element advisor_dismiss_button
    simulate_mouse_click lclick_up
    
    ; Wait for it to go away.
    while I_AdvisorVisible
    end_while
    
    suspend_unscripted_advice true
    
    ; Open the adviser message bubble automatically whenever advance_advice_thread is called.
    ; I recommend using this method instead of the select_ui_element + simulate_mouse_click approach.
    ; Do NOT mix both methods, though, or the advisor will show and then immediately close before
    ; you get a chance to read the text.
    declare_show_me
    
    ; Very useful for debugging - uncomment to use
    ;console_command toggle_perfect_spy
    
    ;;;
    ;;; --- Forced shutdown ---
    ;;;
    ;;; Press 'Esc' on the campaign map, then click on the '?' button in the
    ;;; menu scroll to terminate the script.
    ;;;
    ;;; When would this be useful? -- When you are already in a game and
    ;;; exit back to the main menu to restart the campaign, or reload a saved
    ;;; game, RTW does not automatically terminate the script, so you have
    ;;; to do it yourself. If you leave the old script running, you'll have all
    ;;; sorts of weird problems with the script in the new game.
    ;;;
    monitor_event ScrollAdviceRequested ScrollAdviceRequested end_game_scroll
        terminate_script
    end_monitor
    
    ; Handle saved game reloads
    monitor_event GameReloaded TrueCondition
      terminate_script
    end_monitor
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; Start script
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    while I_TurnNumber < 99999
      suspend_unscripted_advice true
    end_while
    end_script


    Alright , let's get started with scripting .. If your mod uses some small scripts , you can put all scripts in the 'background_script' folder . If you try to get a heavy scripted mod however (like LOTR-TW) , it might be better to make multiple files , to sort everyting out . For instance , Bardo (the LOTR-TW scripter) made for his 'palantir script' 3 new entries in 3 different folders . the palantir script is based on the 'Palantir' in the LOTR-trilogy , and shows the world for 10 seconds .. I'll show you where he pu all entries , so you could understand :

    Spoiler Alert, click show to read: 


    In the background_script.txt file :
    Spoiler Alert, click show to read: 
    Code:
    ;**********************************************
    ;PALANTIR trigger:
    ;**********************************************
    
    monitor_event CharacterTurnStart CharacterIsLocal
       and not FactionType romans_julii
       and Attribute Electability = 10
       and RandomPercent < 10
    advance_advice_thread UsePalantir_Thread
    end_monitor
    monitor_event FactionTurnEnd I_FactionNearTile slave 0 248,211
       console_command move_character SpecialGuy, 249,212
    end_monitor


    Take a look at the underlined line . It targets to another line , that's inside the 'export_descr_advice'.txt file . Now , if we take a look at that file , and search for 'Palantir' , we see the following :

    Inside the export_descr_advice.txt' file :
    Spoiler Alert, click show to read: 
    Code:
    ;------------------------------------------ LOTR-TW
    AdviceThread UsePalantir_Thread
        GameArea Campaign
    
        Item UsePalantir_Text_01
        Uninhibitable
        Verbosity  0
        Threshold  1
            MaxRepeats  0
            RepeatInterval  1
            Attitude Excited
        Presentation Default
        Title UsePalantir_Text_01_Title
        Script scripts\show_me\palantir.txt
        Text UsePalantir_Text_01_Text1


    And here again , take a look at the underlined line . it targets us to the data/scripts/show_me/palantir file . And if we take a look there ... :

    In the palantir.txt file :
    Spoiler Alert, click show to read: 
    Code:
    script
    
       zoom_strat_camera 1
       inhibit_camera_input true
       console_command toggle_fow
       console_command toggle_perfect_spy
       wait 20
       console_command toggle_perfect_spy
       console_command toggle_fow
       inhibit_camera_input false
    
       console_command move_character SpecialGuy, 248,211
    
    select_ui_element advisor_dismiss_button
    simulate_mouse_click lclick_down
    simulate_mouse_click lclick_up
    
    end_script


    ... we see the actual script , or what happens when all previous "triggers" are activated


    So , this was just to show you , that when you make lots of scripts , you better organize it . here , we saw a 'loop' , that goes from the background_script.txt file , to the 'export_descr_advice.txt' file , and ends in the 'palantir.txt' file .

    Alright , now , lets take a look at how most (or the basic) scripts are made :

    Code:
    script
    
    monitor_event 'conditions'
    
    'commands given to the game'
    end_monitor
    
    end_script
    Some experienced modders may say that that's not totally true , but as i mentioned , we'll start of as easy and gentle as possible .. now , you can put this in your backround script , but it must be between the 'loop' :

    Spoiler Alert, click show to read: 
    Code:
    while I_TurnNumber < 99999
      suspend_unscripted_advice true
    end_while
    end_script


    and the previous stuff :

    Spoiler Alert, click show to read: 
    Code:
    script
    
    ; Anything following a semicolon is a comment.
    
    ; Remove the adviser portrait from screen.
    select_ui_element advisor_dismiss_button
    simulate_mouse_click lclick_up
    
    ; Wait for it to go away.
    while I_AdvisorVisible
    end_while
    
    suspend_unscripted_advice true
    
    ; Open the adviser message bubble automatically whenever advance_advice_thread is called.
    ; I recommend using this method instead of the select_ui_element + simulate_mouse_click approach.
    ; Do NOT mix both methods, though, or the advisor will show and then immediately close before
    ; you get a chance to read the text.
    declare_show_me
    
    ; Very useful for debugging - uncomment to use
    ;console_command toggle_perfect_spy
    
    ;;;
    ;;; --- Forced shutdown ---
    ;;;
    ;;; Press 'Esc' on the campaign map, then click on the '?' button in the
    ;;; menu scroll to terminate the script.
    ;;;
    ;;; When would this be useful? -- When you are already in a game and
    ;;; exit back to the main menu to restart the campaign, or reload a saved
    ;;; game, RTW does not automatically terminate the script, so you have
    ;;; to do it yourself. If you leave the old script running, you'll have all
    ;;; sorts of weird problems with the script in the new game.
    ;;;
    monitor_event ScrollAdviceRequested ScrollAdviceRequested end_game_scroll
        terminate_script
    end_monitor
    
    ; Handle saved game reloads
    monitor_event GameReloaded TrueCondition
      terminate_script
    end_monitor


    So in the end , it looks like this :

    Spoiler Alert, click show to read: 
    Code:
    script
    
    ; Anything following a semicolon is a comment.
    
    ; Remove the adviser portrait from screen.
    select_ui_element advisor_dismiss_button
    simulate_mouse_click lclick_up
    
    ; Wait for it to go away.
    while I_AdvisorVisible
    end_while
    
    suspend_unscripted_advice true
    
    ; Open the adviser message bubble automatically whenever advance_advice_thread is called.
    ; I recommend using this method instead of the select_ui_element + simulate_mouse_click approach.
    ; Do NOT mix both methods, though, or the advisor will show and then immediately close before
    ; you get a chance to read the text.
    declare_show_me
    
    ; Very useful for debugging - uncomment to use
    ;console_command toggle_perfect_spy
    
    ;;;
    ;;; --- Forced shutdown ---
    ;;;
    ;;; Press 'Esc' on the campaign map, then click on the '?' button in the
    ;;; menu scroll to terminate the script.
    ;;;
    ;;; When would this be useful? -- When you are already in a game and
    ;;; exit back to the main menu to restart the campaign, or reload a saved
    ;;; game, RTW does not automatically terminate the script, so you have
    ;;; to do it yourself. If you leave the old script running, you'll have all
    ;;; sorts of weird problems with the script in the new game.
    ;;;
    monitor_event ScrollAdviceRequested ScrollAdviceRequested end_game_scroll
        terminate_script
    end_monitor
    
    ; Handle saved game reloads
    monitor_event GameReloaded TrueCondition
      terminate_script
    end_monitor
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; Your script
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    ;script Note that the 'script' lines , are already listed in this file . if you take a look at the top of the file , you'll see the word 'script there , meaning that it's already listed in this script . Scripts must have only 1 'script' , and 'end_script' "word" .
    
    monitor_event 'conditions'
    
    'commands given to the game'
    end_monitor
    
    ;end_script Same as above
    
    while I_TurnNumber < 99999
      suspend_unscripted_advice true
    end_while
    end_script


    Alright , now we've put up the base , we'll start with some basic commands and stuff
    Last edited by Killerbee; May 09, 2009 at 07:03 AM.

  3. #3

    Default Re: Beginner's Scripting Guide

    Step 2 : Basic conditions and commands

    Spoiler Alert, click show to read: 
    Alright , we'll start of with the probably most basic condition : The 'turn start' condition . This condition will be activated whenever it's your turn again . So when you press 'end turn' , it shows all other factions , and then it's your turn again . The "correct description" for this condition is :

    Code:
     FactionTurnStart FactionIsLocal
    Unfortunately , we can't type what we want , so for instance :

    Code:
    monitor_event If i'm at the start of my turn
    
    end_monitor
    Now , if we put this in our little 'basic script' , we'll get the following :

    Code:
    monitor_event FactionTurnStart FactionIsLocal
    
     'commands given to the game'
     end_monitor
    Alas , we need the correct description , so double check spelling , so that you don't make silly typing errors like this:

    'FactionTurnTsart FactionIsLocal'

    Now , the script will activate as soon as it's your turn . only 1 problem : We don't have any commands listed .

    So for now , we'll use a basic command : Giving money to a faction ..
    Code:
    console_command add_money 'faction' 'amount'
    Now , this won't work , as we need to specify the faction that gets the money , and the amount of cash it gets .. So we get this :

    Code:
    console_command add_money greek_cities 1000
    Thus , this will add 1000 money to the greeks .. but when ? That is why we use conditions . Previously , you set up a basic condition , that activates at each start of your turn .. So , if we mix both conditions and commands , we get this :

    Code:
    monitor_event FactionTurnStart FactionIsLocal
    
    console_command add_money greek_cities 1000
    
    end_monitor
    This will add 1000 denarii to the greeks , no matetr wich faction you're playin as .

    Congratz , you put up a basic script ! You can test it out now if you want .

    If you don't know what the 'console_command' is , i'll explain it . Most "cheaters" will already now it ! So cheaters actually have an advantage in scripting ..

    The 'console panel' , is a "program" that you can activate during your campaign , by pressing '~' (without quotes) , '²' , or something else . When you opened it , you can type some 'commands' in it , like :

    add_money greek_cities 1000

    So , then the greek_cities get 1000 denarii .. Already saw it ? In our script , we "opened" the console panel whenever it's your turn , and gave a command to it , just like above . (add_money greek_cities 1000)
    Last edited by Killerbee; May 09, 2009 at 07:03 AM.

  4. #4

    Default Re: Beginner's Scripting Guide

    Step 3 : Making more complicated scripts

    Spoiler Alert, click show to read: 
    Part 1 :

    Alright , you made a script , but with the previous commands and conditions , you won't be able to get some nice results . That's why we'll dig a little deeper .

    First of all , I'll show you a new condition . Also a pretty basic one , and it also involves 'Factions' . This is how you should put it in your script :

    Code:
    I_FactionType greek_cities
    As you could probably see , this condition looks if you're the stated faction , in this case , if you're playing as the greeks



    Part 2 :
    However , you can't just use it like our previous condition .. So you can't use it this way :
    Code:
    monitor_event I_LocalFaction greek_cities
    However , there are 2 other ways to do it :

    Either you use this :
    Code:
    monitor_event FactionTurnStart FactionIsLocal
     and I_LocalFaction greek_cities
    
    -your commands-
    
    end_monitor
    or this :

    Code:
    if I_LocalFaction greek_cities
    
    -yourcommands-
    
    end_if
    i suggest you use the first options , as you probably don't know what an 'if' is , although you can probably guess it So , if we use our new script :

    Code:
    monitor_event FactionTurnStart FactionIsLocal
     and I_LocalFaction greek_cities
    
    console_command add_money greek_cities 1000
    
    end_monitor
    Instead of our previous script , this won't occur each time it's your turn . You also need to be playing as the greeks . So , you need to be playing as the greeks , and it needs to be your turn , in order to activate the command .

    Now , we also need a new command . We'll take a very popular , and probably the most used one : The spawn_army command ..

    this is how it should be listed in your script :

    Code:
    spawn_army
       faction 'faction' ; (so for instance , greek_cities)
       character "character name" ,'type of character' (for instance , general , named_character , ...) ,age ,coörds
       'list of units' , for instance : 
       unit greek general's guard cavalry early, 'amount of soldiers' 'exp' 'armour' 'weapon_lvl'
       end
    Now , this won't work ofcourse .. We need to get some working names , coörds , factions , etc .. So , if we do everyting correctly , it should look like this :

    Code:
    spawn_army
       faction greek_cities ; So this will spawn an army for the greek faction
       character Polydoros, general, age 25, x 123, y 65
       unit greek general's guard cavalry early, 30 exp 5 armour 2 weapon_lvl 3
       end
    This will spawn a general for the greeks called Polydoros , who'll be of age 25 , and he'll be spawned on the listed coördinates . As for the units , there'll be a greek early general , with 30 units , 5 experience bonus , 2 armour bonus , and 3 wep_lvl bonus .

    But i won't go any deeper here , as there are already lots of tutorials about this command :

    HouseOfHam's tutorial :
    Tutorial

    Now , if we use this command in a script , combined with our new conditions , it should look like this :

    Code:
    monitor_event FactionTurnStart FactionsIslocal
     and I_LocalFaction greek_cities
    Code:
    spawn_army
       faction greek_cities ; So this will spawn an army for the greek faction
       character Polydoros, general, age 25, x 123, y 65
        unit greek general's guard cavalry early, 30 exp 5 armour 2 weapon_lvl 3
        end
    end_monitor
    Alright , we now have a more complicated script than our previous one .


    There are much more conditions and commands , and they are listed in the docudemons .. Download them here :

    http://www.totalwar.org/Downloads/Rt...ad/BI_docs.zip

    Just unzip it wherever you want . there should be 4 text files in them .. Just check the appropriate folder to find conitions or commands , or whatever you like .
    Last edited by Squid; December 16, 2010 at 11:28 AM.

  5. #5

    Default Re: Beginner's Scripting Guide

    Step 4 : Some other stuff

    There are some other basic thingies you can use in scripts .. For instance , the 'not' word .. this can be used in conditions , to trigger when something isn't activated , but for instance :

    Code:
    monitor_event FactionTurnStart FactionIsLocal
       and not I_LocalFaction romans_julii
    So , if you're playing as the Julii , this script will not trigger ! If you're playing as another faction , however , it should trigger perfectly This can be used for some scripts (e.g.scripts who add units to weaker factions faction , so they die less quickly) .. For instance :

    Code:
    monitor_event FactionTurnStart FactionIsLocal
      and not I_LocalFaction romans_julii
      and not I_LocalFaction romans_brutii
      and not I_LocalFaction romans_scipii
      and not I_LocalFaction romans_senate
      and not I_LocalFaction egypt
      and RandomPercent < 10 ; This declares a random percent , so that the script only activated 1/10 of ;the time
    
    spawn_army 'blah blah'
       character 'blah blah'
       units 'blah blah'
       end
    end_monitor
    

    This script will neither activate for all roman factions , nor for the egyptians , as these are the strongest factions in vanilla ..

    Last edited by Killerbee; May 09, 2009 at 04:19 PM.

  6. #6

    Default Re: Beginner's Scripting Guide

    Step 5 : What if's and counters ?

    Spoiler Alert, click show to read: 
    In one of my previous examples , i showed you something new .. The usage of 'if' , instead of 'monitor_event' .. Some conditions require an 'if' instead of 'monitor event' , like this one :

    Code:
    if I_SettlementOwner Sparta = greek_cities
    
    - yourcommands  -
    
    end_if
    with this example , i showed you how to use the 'if' , and i showed you a new condition .. This condition can be used if you want a certain faction to own a settlement , in order to activate the script .. This is a very usefull condition , and is one of my most-used ones (although i'm not so long into scripting )

    This condition can also be used in combination with 'counters' .. What are counters , you say ? Take a look here

    this combination can give you some nice results :

    Code:
    if I_SettlementOwner Sparta = greek_cities
    set_counter SettlementOwner_Sparta 1
    
    end_if
    
    If I_CompareCounter SettlementOwner_Sparta = 1
    
    console_command add_money romans_julii -1000
    
    end_if
    1 Note about this script is that i used a negative digit to add money .. So what will it do ? CTD ? nope , it'll just decrease the amount of denarii the romans_julii get , by 1000

    -More will be added later -

    Last edited by Killerbee; May 23, 2009 at 09:34 AM.

  7. #7

    Default Re: Beginner's Scripting Guide

    Some info about counters :

    Spoiler Alert, click show to read: 
    Counters are quite handy in scripting .. they'll keep count of something , for instance the amount of settlements you own .. Counters can - combined with some basic conditions and commands - come over quite professional and great , and they aren't hard to use .. There are multiple conditions needed in order to succesfully get a counter .. these are :

    Code:
     set_counter 'target' 1
    set_counter .. You'll need this whenever you want to start a counter .. It's pretty obvious that this "sets" or "initiates" a counter , and in this case , the counter in-game will be one .. Here's a sample use of a set_counter , in combination with previously learned stuff :

    Code:
    script
    
    if I_SettlementOwner Rome = romans_julii
    set_counter SettlementOwner_Rome 1
    
    end_script
    Now , the counter will be set if you are in control of Rome as the Julii .. Note that there's an underscore between the '..Owner' and the 'Rome' , otherwise , the game will actually take 'Rome' as a digit ! Anything followed by a space , is read as a number by the game ..

    Now , another counter condition :

    Code:
     inc_counter SettlementOwner_Rome 1
    this will increase our previous counter with 1 . Since it was already 1 , it'll now be two (1+1 = 2 )

    A sample use :

    Code:
    script
    
    if I_SettlementOwner Rome = romans_julii
    set_counter SettlementOwner_Rome 1
    
    end_if
    
    if I_SettlementOwner Arretium = romans_julii
    inc_counter SettlementOwner_Rome 1
    
    end_if
    end_script
    Ok , now that we used that one , let's go to another important counter thing : The Compare Counter . this condition will actually check the current counter , and gives the game a series of commands , whenever the counter is okay .. You don't get it ? Check out how to use it :

    Code:
    script
     
     if I_SettlementOwner Rome = romans_julii
     set_counter SettlementOwner_Rome 1
    
    end_if
    
    if I_SettlementOwner Arretium = romans_julii
    inc_counter SettlementOwner_Rome 1
    
    end_if
    
    if I_CompareCounter SettlementOwner_Rome = 2
    
       console_command add_money romans_julii 1250
    
    end_if
    end_script
    So , when you have both settlements , the counter will be "2" . And the 'CompareCounter' looked if the counter was set on 2 .. Wich is the case , so the command will be used in-game .. the 'CompareCounter can also be used in combination with the monitor_event , and other conditions :

    Code:
    script
      
      if I_SettlementOwner Rome = romans_julii
      set_counter SettlementOwner_Rome 1
     
     end_if
     
     if I_SettlementOwner Arretium = romans_julii
     inc_counter SettlementOwner_Rome 1
     
     end_if
    
    monitor_event FactionTurnStart FactionIsLocal
       and not I_LocalFaction romans_senate
       and I_CompareCounter SettlementOwner_Rome = 2
    
       console_command add_money romans_julii 1250
    
    end_monitor
     end_script
    No need to explain any further , i think ..


    Important note about counters : Counterscan get messed up when you reload a game (so when you save , and reload it) I will try to post a solution as soon as possible ..

    Garisson scripts ?

    Spoiler Alert, click show to read: 
    How to make a "garisson script ? if we take a look at the docudemons , we don't see a

    Code:
     If I_SettlementOwnerSettlementUnderSiege 'faction' 'settlement'
    ; or other things that could trigger a garisson script ? Well , we can , although there can be some in-accuracies . The condition we'll use for this is :

    Code:
    I_CharacterTypeNearTile romans_julii named_character, 10 48,30
    This condition will be activated , as soon as a named character of the romans_julii faction is at 10 tiles from the listed coords (48,30) .. Explanation of the docudemon :

    Is a particular character type of a faction near a particular tile?
    So how could we get from this , to a settlement garisson script ? Well , we can change some values .. first of all , set up a base .. This is how it should look like :

    (To get settlement coörds , get HoH's excellent settlement locator) For now , we'll use a garisson script for the Brits (and the Region of Belgica = Samarobriva in-game) Coörds are : x 61 , y 118

    Spoiler Alert, click show to read: 
    Code:
    script
    
    If I_CharacterTypeNearTile germans named_character, 1 61,118
    
        console_command kill_character "Aneirin" ; to avoid cloning CTD
    
    spawn_army
       faction britons 
       character Aneirin, general, age 25, x 61, y 118
       unit barb british general briton, 30 exp 5 armour 2 weapon_lvl 3
       unit barb chariot heavy briton, 45 exp 5 armour 2 weapon_lvl 3
       unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
       unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
       unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
       unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
       unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
       unit barb warguard briton, 60 exp 5 armour 2 weapon_lvl 3
       unit barb warguard briton, 60 exp 5 armour 2 weapon_lvl 3
       unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
       unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
       unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
       unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
       unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
       unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
       unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
       end
    end_if
    
    while I_TurnNumber < 50000
        suspend_unscripted_advice true
    end_while
    
    end_script


    Explanation ? This script will activate and thus spawn a (big and strong) army , under command of a young (=age 25) general called Aneirin , whenever a german named_character is at 1 tile of the settlement .. If they siege , they are automatically at 1 tile of the city

    Some flaws : - The german army must contain a named_character (a family member) , in order to spawn the army ..
    - This script will only spawn if a german army/character is near .. So how could we improve this ?
    Simply copy-paste the script for a few times , and change the faction to the most common one .. I don't think brits will encounter Seleucids in Belgica .. So , the most frequent ones are (except for germans) imo : gauls , romans (julii) , spain , dacia , scythia ..
    - It's also possible that characters siege a city in a "diagonal" (for instance , top right-corner of a city) postion . it is possible that this requires that you list 2 tiles from your settlement coörds (= 1 tile to the right , and 1 tile up). Must need some testing though ..

    So , this would be a loong script .. the end-result :

    Spoiler Alert, click show to read: 
    Code:
    script
    
    If I_CharacterTypeNearTile germans named_character, 1 61,118
    
    console_command kill_character "Aneirin" ; to avoid cloning CTD
    
    spawn_army
       faction britons 
       character Aneirin, general, age 25, x 61, y 118
       unit barb british general briton, 30 exp 5 armour 2 weapon_lvl 3
       unit barb chariot heavy briton, 45 exp 5 armour 2 weapon_lvl 3
       unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
       unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
       unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
       unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
       unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
       unit barb warguard briton, 60 exp 5 armour 2 weapon_lvl 3
       unit barb warguard briton, 60 exp 5 armour 2 weapon_lvl 3
       unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
       unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
       unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
       unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
       unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
       unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
       unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
       end
    end_if
    
    If I_CharacterTypeNearTile gauls named_character, 1 61,118
     
    console_command kill_character "Aneirin" ; to avoid cloning CTD
    
     spawn_army
        faction britons 
        character Aneirin, general, age 25, x 61, y 118
        unit barb british general briton, 30 exp 5 armour 2 weapon_lvl 3
        unit barb chariot heavy briton, 45 exp 5 armour 2 weapon_lvl 3
        unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
        unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
        unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
        unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
        unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
        unit barb warguard briton, 60 exp 5 armour 2 weapon_lvl 3
        unit barb warguard briton, 60 exp 5 armour 2 weapon_lvl 3
        unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
        unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
        unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
        unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
        unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
        unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
        unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
        end
     end_if
    
    If I_CharacterTypeNearTile romans_julii named_character, 1 61,118
    
    console_command kill_character "Aneirin" ; to avoid cloning CTD
    
      spawn_army
         faction britons 
         character Aneirin, general, age 25, x 61, y 118
         unit barb british general briton, 30 exp 5 armour 2 weapon_lvl 3
         unit barb chariot heavy briton, 45 exp 5 armour 2 weapon_lvl 3
         unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
         unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
         unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
         unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
         unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
         unit barb warguard briton, 60 exp 5 armour 2 weapon_lvl 3
         unit barb warguard briton, 60 exp 5 armour 2 weapon_lvl 3
         unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
         unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
         unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
         unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
         unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
         unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
         unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
         end
      end_if
    
    If I_CharacterTypeNearTile spain named_character, 1 61,118
    
     console_command kill_character "Aneirin" ; to avoid cloning CTD
     
       spawn_army
          faction britons 
          character Aneirin, general, age 25, x 61, y 118
          unit barb british general briton, 30 exp 5 armour 2 weapon_lvl 3
          unit barb chariot heavy briton, 45 exp 5 armour 2 weapon_lvl 3
          unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
          unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
          unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
          unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
          unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
          unit barb warguard briton, 60 exp 5 armour 2 weapon_lvl 3
          unit barb warguard briton, 60 exp 5 armour 2 weapon_lvl 3
          unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
          unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
          unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
          unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
          unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
          unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
          unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
          end
       end_if
     
    If I_CharacterTypeNearTile dacia named_character, 1 61,118
     
      console_command kill_character "Aneirin" ; to avoid cloning CTD
      
        spawn_army
           faction britons 
           character Aneirin, general, age 25, x 61, y 118
           unit barb british general briton, 30 exp 5 armour 2 weapon_lvl 3
           unit barb chariot heavy briton, 45 exp 5 armour 2 weapon_lvl 3
           unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
           unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
           unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
           unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
           unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
           unit barb warguard briton, 60 exp 5 armour 2 weapon_lvl 3
           unit barb warguard briton, 60 exp 5 armour 2 weapon_lvl 3
           unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
           unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
           unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
           unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
           unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
           unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
           unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
           end
        end_if
      
    If I_CharacterTypeNearTile scythia named_character, 1 61,118
      
       console_command kill_character "Aneirin" ; to avoid cloning CTD
       
         spawn_army
            faction britons 
            character Aneirin, general, age 25, x 61, y 118
            unit barb british general briton, 30 exp 5 armour 2 weapon_lvl 3
            unit barb chariot heavy briton, 45 exp 5 armour 2 weapon_lvl 3
            unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
            unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
            unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
            unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
            unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
            unit barb warguard briton, 60 exp 5 armour 2 weapon_lvl 3
            unit barb warguard briton, 60 exp 5 armour 2 weapon_lvl 3
            unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
            unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
            unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
            unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
            unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
            unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
            unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
            end
         end_if
       
    while I_TurnNumber < 50000
        suspend_unscripted_advice true
    end_while
    
    end_script


    You can experiment with this .. If you want to have the garisson script to appear just once , you must add some extra steps :

    Spoiler Alert, click show to read: 
    Code:
    If I_CharacterTypeNearTile scythia named_character, 1 61,118
    set_counter garisson_script 1
    
    end_if
    
    If I_CharacterTypeNearTile germans named_character, 1 61,118
    set_counter garisson_script 1
    
    end_if ; and so on for all factions
    
    monitor_event FactionTurnStart FactionIsLocal
       and I_SettlementOwner Samarobriva = britons
       and i_CompareCounter garisson_script = 1
    
         spawn_army
            faction britons 
            character Aneirin, general, age 25, x 61, y 118
            unit barb british general briton, 30 exp 5 armour 2 weapon_lvl 3
            unit barb chariot heavy briton, 45 exp 5 armour 2 weapon_lvl 3
            unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
            unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
            unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
            unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
            unit warband woad briton, 60 exp 5 armour 2 weapon_lvl 3
            unit barb warguard briton, 60 exp 5 armour 2 weapon_lvl 3
            unit barb warguard briton, 60 exp 5 armour 2 weapon_lvl 3
            unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
            unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
            unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
            unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
            unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
            unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
            unit warband sword briton, 60 exp 5 armour 2 weapon_lvl 3
            end
         terminate_monitor
         end_monitor


    Saw the bold line at the end ? The 'terminate_monitor' ? This will 'terminate' a command , so after it activated , it won't activate again .. Can be usefull if you don't want to have to large armies , so that your economy goes down , or you simply get over-powered ..

    EDIT : Important note : Do not reload too much , or otherwise the scripts could get messed up !

    I suggest the garisson script for factions tha get eliminated quickly , like the Seleucids , Gauls , Armenia , ...
    Last edited by Killerbee; June 21, 2009 at 01:42 PM.

  8. #8

    Default Re: Beginner's Scripting Guide

    Update 16|05|'09 :

    Changed the counters bit a little
    Changed the garisson script a bit
    Added some important notes about re-loading the game ..

    With thanks to makanyane :
    Spoiler Alert, click show to read: 
    There's a couple of things that could be added that might help even further;
    on the garrison stuff if as well as
    If I_CharacterTypeNearTile germans named_character, 1 61,118
    you also use a duplicate monitor with:
    If I_CharacterTypeNearTile germans general, 1 61,118
    it'll cover the case where army is there but not led by family member.
    - also I've not actually really tested if its right or not, but I was told that you needed to check for characters within 2 and not 1 of settlement or it wouldn't include armies besieging from diagonal directions (would be interesting to double check if that's true or not)

    On the counters bit, I think you need to use
    declare_counter counter_name
    before you use the counter ( that also sets the default value of 0 for the counter)

    the real pain with RTW as against M2 is that it doesn't record the value of the counters when you save game and reload... I've been having fun with that lately.... It can be sort of fixed by making sure important events are recorded by creating a building or adding trait to a settlement/character that can be checked next time you load. Similarly the 'terminate_monitor' bit only works for each time the script is loaded, if you rely on that too heavily to stop things happening twice, a user that saves, quits and reloads a lot will get a vastly different experience as the terminated monitors will crop up again on each re-load...
    Last edited by Killerbee; May 16, 2009 at 03:26 PM.

  9. #9

    Default Re: Beginner's Scripting Guide

    Maybe i need more ..

  10. #10

    Default Re: Beginner's Scripting Guide

    Great guide!
    Last edited by CPT Worsham; September 03, 2010 at 02:38 PM.
    "What's the matter, kid? Don't ya like clowns?
    Don't we make ya laugh? Aren't we freakin' funny?" - CPT Spaulding in Devil's Rejects

  11. #11

    Default Re: Beginner's Scripting Guide

    Very nice guide, will help me create a nice script. However, I had a question though:

    The file that we could download, containing the command line codes. Most of them doesn't seem to be working. I am new to modding/scripting RTW and I have no idea why it won't work. Just get a message that the command is not recognized.

  12. #12
    Squid's Avatar Opifex
    Patrician Artifex Technical Staff

    Join Date
    Feb 2007
    Location
    Frozen waste lands of the north
    Posts
    17,760
    Blog Entries
    3

    Default Re: Beginner's Scripting Guide

    There are many console commands that can't actually be run in the console and can only be run through a script.
    Under the patronage of Roman_Man#3, Patron of Ishan
    Click for my tools and tutorials
    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe." -----Albert Einstein

Posting Permissions

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