Page 1 of 6 123456 LastLast
Results 1 to 20 of 119

Thread: How-to: Add a background script to your mod

  1. #1
    HouseOfHam's Avatar Primicerius
    Join Date
    Apr 2007
    Location
    Minnesota, USA
    Posts
    3,030

    Default How-to: Add a background script to your mod

    First, a bit of terminology:

    campaign script - A script called at the end of the descr_strat.txt file. This script only runs once, when a new campaign is first started. Saving/loading the game is disabled while this type of script runs, so it's a good idea to keep this type of script short, only using it for basic initialization and to kick off a background script. This is the type of script used for the Sons of Mars tutorial campaign in vanilla RTW.

    background script - This type of script is started via an advice thread and, just like the name suggests, runs in the background. The 2 biggest advantages offered by background scripts are: 1) Being able to save/load the game while the script is running, and 2) Being able to restart the script after loading a saved game. This type of script is often also referred to as 'show me' scripts, due to the old method of starting such script, which required clicking the advisor 'Show me how' button. This type of script is used to add features like 4-turns-per-year and opens the way to a multitude of other possibilities, including scripted missions, spawning armies, and much more. A background script keeps running until you exit the game (or shut it down manually - more on that in the example below).

    on-demand script - This type of script is used to run a small, self-contained piece of code. Once the code has been run, the script terminates. For example, some mods include a script that you can run before making a diplomatic offer that will force the AI to accept it. This type of script is also started via an advice thread and is usually triggered by pressing one of the less-frequently used buttons in the UI. For example, the '?' button in the Help scroll.

    Adding a background script

    This will guide you through all the steps of adding a background script.

    You must complete at least the instructions in sections I & III before it will work. Section II is optional, but is usually good to include to reduce the amount of clicking the player has to do. Section IV is just additional information to help you get started with scripting.

    Section I: Setting up an advice thread

    1. Add a new thread to export_descr_advice.txt:

    Code:
    ;------------------------------------------
    AdviceThread BackgroundScriptThread
        GameArea Campaign
    
        Item BackgroundScriptItem1
            Uninhibitable
            Verbosity  0
            Threshold  1
            MaxRepeats  0
            RepeatInterval  1
            Attitude Normal
            Presentation Default
            Title BackgroundScriptTitle1
            On_display scripts\show_me\background_script.txt
            Text BackgroundScriptText1
    The On_display line creates an association between this advice thread and a script specified on it. The script will run automatically as soon as the adviser text box opens. If adviser is set to voice-only, the script will run automatically when the advice thread is triggered/advanced.

    2. At the end of the export_descr_advice.txt file, add the following triggers for the above advice thread.

    Code:
    Trigger background_script_trigger_1
        WhenToTest ButtonPressed
    
        Condition ButtonPressed faction_button
    
        AdviceThread BackgroundScriptThread  1
    
    ;------------------------------------------
    Trigger background_script_trigger_2
        WhenToTest ButtonPressed
    
        Condition ButtonPressed construction_button
    
        AdviceThread BackgroundScriptThread  1
    
    ;------------------------------------------
    Trigger background_script_trigger_3
        WhenToTest ButtonPressed
    
        Condition ButtonPressed recruitment_button
    
        AdviceThread BackgroundScriptThread  1
    
    ;------------------------------------------
    Trigger background_script_trigger_4
        WhenToTest SettlementSelected
    
        AdviceThread BackgroundScriptThread  1
    These triggers will be used to restart the script after loading a saved game. When you load a saved game, the first time any of these are triggered, the advisor portrait will come up. Click on it once to restart the script.

    3. Add the following lines at the end of the text\export_advice.txt file:
    Code:
    {BackgroundScriptTitle1}Background Script
    {BackgroundScriptText1}Script started.
    Section II: Running the background script automatically when a new campaign starts

    1. Add the following at the very end of descr_strat.txt:

    Code:
    script
    campaign_script.txt
    This uses a campaign script to fire off the background script.

    2. In the same folder with the descr_strat.txt file for your mod, create a new file called campaign_script.txt (our campaign script) and put these lines into it:

    Code:
    script
    
    wait 1
    advance_advice_thread BackgroundScriptThread
    wait 1
    select_ui_element advisor_portrait_button
    simulate_mouse_click lclick_up
    
    end_script
    Section III: Creating the script - What every script should have

    1. In the scripts\show_me folder, create a new file called background_script.txt <-- This is the file referenced by the On_display line in the advice thread in Section I. Traditionally, everyone puts their scripts into scripts\show_me, but you can put it anywhere you like and call it anything you want, as long as you update the On_display line to point to it.

    2. What to put into the script file:

    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
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; This is where to put your own code
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    ; For example, this will give you 1 gold at the beginning of every turn
    monitor_event FactionTurnStart FactionIsLocal
      console_command add_money 1
    end_monitor
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; End of your code
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    ; Spin forever - Do not let the script terminate or any monitors you have set up will immediately get thrown away.
    ; In M2TW scripts, this loop is replaced by the wait_monitors command. Unfortunately, this command is not available in RTW.
    while I_TurnNumber < 99999
      suspend_unscripted_advice true
    end_while
    
    end_script
    Section IV: Learning Scripting - Where to go from here

    1. Other resources

    Recommended reading:


    Referrence materials:


    Where to ask for advice:


    2. A few notes to help you with your scripting:

    - The following commands do not work inside a monitor_event block: wait, campaign_wait, battle_wait, while, and nested monitor_event/monitor_conditions blocks. If you try to use them, your script will freeze.

    - Most scripting commands and conditions use objects exported by events as an implied parameter and thus only work in the context of a monitor_event block. The type of object expected by the command/condition must match the type of one of the objects exported by the monitored event, or they won't work. To give you some examples...

    This works, because FactionTurnStart exports the faction object, needed for the FactionIsLocal condition:

    Code:
    monitor_event FactionTurnStart FactionIsLocal
        console_command add_money 1
    end_monitor
    This does not work, because FactionTurnStart does not export a character object:
    Code:
    monitor_event FactionTurnStart CharacterIsLocal
        console_command add_money 1
    end_monitor
    - An exception to the above are Independent commands (commands that start with "I_") and console commands, because parameters for these commands are either explicitly named objects (i.e. specific characters/settlements/etc.), or they do not require parameters.

    - Always, always, always have -show_err in your shortcut's target line!!!

    - Errors in console_command lines never produce any error messages and never cause CTDs. They're just quietly ignored.

    - Other errors, depending on how severe they are, can cause a CTD or a pop-up dialog box with an error message when shutting down the game.

    - Some commands can freeze the game completely, so it won't respond at all, even to Alt-F4. I found that out first-hand when I tried to add the following code (don't try this at home!):
    Code:
    monitor_event CharacterSelected CharacterIsLocal
        call_object_shortcut hud_select_prev_item_cycle
    end_monitor
    So, don't do it!

    - Clicking on an army that's inside a settlement does not generate a CharacterSelected event

    - It's only possible to use scripting to move field armies/characters. AFAIK, it does not work on armies/characters that are inside a settlement.

    - To be able to take full advantage of all the possibilities scripting offers, you should become familiar with a few other areas of modding. In particular, having a good understanding of these will make you a much more effective scripter: descr_strat.txt, advice threads, traits & ancillaries, units (EDU/DMB) and buildings (EDB).

    - Unlike M2TW, counter values are NOT saved when a game is saved. This means that you'll have to use other means to keep track of important information that you'll need when the script is restarted. The most common ways are using traits (especially hidden traits), ancillaries, and buildings (EDB).

    - In M2TW, you don't have to create a separate background script because the campaign script restarts automatically when you load a saved game.

    - Advice thread counter is incremented when you click on the advisor portrait to open the text bubble.

    - The AbandonShowMe event is generated when you dismiss the advisor.

    - The I_WonBattle condition works when used with a "normal" faction, but does not with the special slave/rebel faction.

    ps: Feel free to discuss here or at .org (http://forums.totalwar.org/vb/showthread.php?t=104133)
    Last edited by HouseOfHam; December 15, 2010 at 02:35 PM.
    RTR website/SVN admin

    - Settlement coordinate locator -for RTW/M2TW
    - EDB Validator v1.2.8 (Oct 16, 2012) - for RTW/M2TW
    - RTW scripting tutorials
    - n-turns per year script generator

  2. #2

    Default Re: How-to: Add a background script to your mod

    At long last! That will be very useful for scripting newbies, thx HouseOfHam. (And it also contains the new method, nice.)

  3. #3

    Default Re: How-to: Add a background script to your mod

    Is this final and complete with saves and everything? Sorry I dont understand all that mumbo jumbo you script people write and I remember lots of talk that flew straight over my head over at the org. I like the prospect of not having to press the advisor though - kinda changes it from a script to background magic.

  4. #4

    Default Re: How-to: Add a background script to your mod

    Yes, the "On_display scripts\show_me\my_script.txt" part indicates this is the improved version of it, that only requires a single click on the advisor to launch the script.

    If you use the "speech only" mode then scripts do get launch automatically, just by clicking on a settlement or a character, if the player has set the advice level to anything other than "no advice".

  5. #5

    Default Re: How-to: Add a background script to your mod

    This is seriously cool.

  6. #6

    Default Re: How-to: Add a background script to your mod

    i don't understand what you want me to put in the show_script file can you make it more clearer please

  7. #7
    HouseOfHam's Avatar Primicerius
    Join Date
    Apr 2007
    Location
    Minnesota, USA
    Posts
    3,030

    Default Re: How-to: Add a background script to your mod

    This tutorial was written just to help people who wanted to learn scripting with adding their first script. What you put into it is totally up to you. If you don't know what to put into it, you probably don't need one.
    RTR website/SVN admin

    - Settlement coordinate locator -for RTW/M2TW
    - EDB Validator v1.2.8 (Oct 16, 2012) - for RTW/M2TW
    - RTW scripting tutorials
    - n-turns per year script generator

  8. #8

    Default Re: How-to: Add a background script to your mod

    @HouseOfHam: first thank you for this great tutorial, I find it very useful both for new scripters and also for experts, since it describes perfectly the best method available to launch the scripts.

    And it seems your method is even better than I expected, and perhaps better than you thought ... because it seems it is possible to relaunch the scripts automatically after reloading, without the trick of voice-only adviser.

    I was trying to add the line "declare_show_me" to my scripts, as you suggest, (it is the only thing that I had not tested from your method), and for some reason, now when I reload a game, as soon as I select a settlement/character or I press any button, the advisor appears and the scripts are automatically launched without the needed to click on the advisor portrait. Same than when you select voice-only advice, but I have checked that it is set to text+voice.

    I must say I'm not using exactly the same method than you, I use the event GameReloaded and an extra advice thread to relaunch the scripts, in stead of the use of "suspend_unscripted_advice true".
    And it seems that using your discovery of "on_display" and also the "declare_show_me", it is possible to make the scripts COMPLETLY AUTOMATIC .

    I think it does not work for you due to the use of "suspend_unscripted_advice true", because it is the only difference between our methods.
    I have discovered it just now, and I need more testing, but it would be great if you can help me to test it. You could test to remove the command "suspend_unscripted_advice true" to check if this would allow to the advisor to appear automatically without clicking the portrait, like it happens to me.

    Other thing I want to test is the effect of "declare_show_me": We now the advices triggered from the script (declared show_me) are automatically opened, maybe it has the same effect over the advice that triggers the script itself, but only when suspend_unscripted_advice is false. Do you understand? It could be the reason why it all is possible.

    Sorry my english, I'll try to explain it better when I have made more tests.
    Last edited by Bardo; July 03, 2008 at 08:06 PM.

  9. #9

    Default Re: How-to: Add a background script to your mod

    Confirmed that it works! Scripts close to be automatic!
    Note that I'm using AlexanderTw, but I do not think it will be different in other versions.

    I have checked that when you use an AdviceThread (export_descr_advice.txt) to launch a script, if the script includes the commnad "declare_show_me", the advice is shown automatically, you do not need to click on the portrait of the advisor.
    I have also found that it stops working if you launch another script declared show_me.
    For example, I use the help button of the diplomatic scroll to launch a show_me script to force_diplomacy, and I have checked that this advice is automatically showed (without clicking the advisor portrait). But as soon as I use this script, the background script is no longer triggered automatically after the reloading of a game, then you need to click the portrait again.

    The only other backward that i have found is that you have to exit and restart the game before starting a new campaign. If you exit from a campaign game and then you start another campaign, the scripts are not properly launched and you are not allowed to save the game (like in tutorial mode).
    Maybe it could be solved in the future. (EDIT: In fact, this is already fixed)

    I have not found any problem when you reload a savegame without exiting the game, in this case the scripts are activated properly once and again.
    Except when you load autosaves, in this case the script is automatically launched but the advisor does not disappear automatically until you press end turn.

    Well, with HouseOfHam permission (this is his tutorial, and my method is based on his discoveries), I'm going to copy here my files, so people can help us to develop the best way to launch the scripts:

    Export_descr_advice.txt
    ;===============================================================
    ;== ADVICE THREAD DATA STARTS HERE ==
    ;===============================================================

    ;------------------------------------------ LOTR-TW
    AdviceThread Lotr_Script_Thread
    GameArea Campaign

    Item Lotr_Script_Text_01
    Uninhibitable
    Verbosity 0
    Threshold 2
    Attitude Excited
    Presentation Default
    Title Lotr_Script_Text_01_Title
    On_display scripts\show_me\background_script.txt
    Text Lotr_Script_Text_01_Text1

    ;===============================================================
    ;== TRIGGER DATA STARTS HERE ==
    ;===============================================================

    ;------------------------------------------ LOTR-TW trigger
    Trigger Reload_Script_Trigger1
    WhenToTest SettlementSelected

    AdviceThread Lotr_Script_Thread 1

    ;------------------------------------------ LOTR-TW trigger
    Trigger Reload_Script_Trigger2
    WhenToTest CharacterSelected

    AdviceThread Lotr_Script_Thread 1

    ;------------------------------------------ LOTR-TW trigger

    Trigger Reload_Script_Trigger3
    WhenToTest ButtonPressed

    AdviceThread Lotr_Script_Thread 1

    ;------------------------------------------ LOTR-TW trigger
    Trigger Reload_Script_Trigger
    WhenToTest GameReloaded

    AdviceThread Lotr_Script_Thread 0

    Campaign Script (placed in the campaign folder)
    script

    declare_show_me

    ;...

    wait 1
    console_command trigger_advice Lotr_Script_Thread
    advance_advice_thread Lotr_Script_Thread no_dismiss


    end_script

    Background Script (placed into \scripts\show_me)
    script

    wait 1
    select_ui_element advisor_dismiss_button
    simulate_mouse_click lclick_up

    ; This is the important one, needed so the text of the advice can be opened automatically;
    declare_show_me

    ;This is needed when you reload games without exiting the game, it disables the script of the previous game, and it allows the new script to be launched inmediately. Without this monitor, the script is not activated until end of turn;
    monitor_event GameReloaded TrueCondition
    terminate_script
    end_monitor


    while I_TurnNumber < 1000

    ;... We use a turn per year script
    console_command date 0
    console_command season summer
    while I_TurnNumber = 0
    end_while
    ;...
    console_command date 1000
    console_command season summer
    while I_TurnNumber = 1000
    end_while

    ;I need to include the script into a while loop to make it possible to reload a game without exiting the game;
    end_while

    end_script
    Last edited by Bardo; December 15, 2010 at 12:28 PM.

  10. #10

    Default Re: How-to: Add a background script to your mod

    Nicely done Bardo! Thumbsup for the combined efforts. Unless you find some unrevealed-as-of-yet flaw, this is a major breakthrough in scripting!

  11. #11
    HouseOfHam's Avatar Primicerius
    Join Date
    Apr 2007
    Location
    Minnesota, USA
    Posts
    3,030

    Default Re: How-to: Add a background script to your mod

    Can't seem to get it to work with BI. Perhaps, it's something new in Alexander. Still, great news.

    Does it work automatically for you when you first load a saved game by clicking on 'Continue Campaign'?

    ps: not sure why you need a while loop around the 1-turn-per-year script... can you explain that in a little more detail?
    Last edited by HouseOfHam; July 04, 2008 at 02:08 AM.
    RTR website/SVN admin

    - Settlement coordinate locator -for RTW/M2TW
    - EDB Validator v1.2.8 (Oct 16, 2012) - for RTW/M2TW
    - RTW scripting tutorials
    - n-turns per year script generator

  12. #12

    Default Re: How-to: Add a background script to your mod

    I think that Orb once commented that he had done something like that, but only for Alexander. Although I would love to be wrong

  13. #13

    Default Re: How-to: Add a background script to your mod

    Quote Originally Posted by HouseOfHam View Post
    Can't seem to get it to work with BI. Perhaps, it's something new in Alexander. Still, great news.

    Does it work automatically for you when you first load a saved game by clicking on 'Continue Campaign'?
    For some reason, if the latest saved game is an autosave and you use 'Continue Campaign', the advisor appear, but the message is not opened automatically, you need to click the portrait. This is the only case where I have seen it failing, and I don't understand why, since it works when you use 'continue campaign' with an standard savegame, and also when you use 'load campaign' to load an autosave.
    Still, I think it is a minor hole in the system.

    Quote Originally Posted by HouseOfHam View Post
    ps: not sure why you need a while loop around the 1-turn-per-year script... can you explain that in a little more detail?
    When I remove this while loop, then if I'm playing a campaign with the scripts active and I load another game, the loaded game appears in the date 1000, and then when I press end turn the game ends, since 1000 is the latest turn of our campaign. It only happens if the date of the loaded game were lower than the previous game, and I'll try to explain the reason (inmo) with an example:

    Previous game: turn 10
    Loaded game: turn 5

    When you load the new game, the previous turns-per-year script is still active in the 'while I_TurnNumber = 10' loop of the turn 10. When the other game is loaded, the turn suddently changes to 5, and the script advance all the 'while I_TurnNumber' loops until the end, and it finally shows turn 1000.
    No matter if I launch the script for the new game or not, the campaign ends as soon as I press end turn.

    Using the loop 'while I_TurnNumber < 1000', the new loaded game appears always in the right date and I do not have this problem.
    Maybe this loop is the reason I need the code:

    monitor_event GameReloaded TrueCondition
    terminate_script
    end_monitor
    to stop the previous script, I don't know, but I'm sure it works because it has been used for months in our lotr-tw mod.
    And I have just released a patch with the new improvements, we will see if people find any other flaws.


    About ATW, you can make a simple test to verify if this method can work with BI, just make a script with the line "declare_show_me" inside, and use one advice thread (from export_descr_advice) to trigger it using "on_display". If the message is automatically opened and you do not need to click on the advisor portrait to read it, then it should be possible to get it working on BI.
    There must be no other scripts running, nor any command with 'suspend_unscripted_advice true', so the test can be definitive.

  14. #14
    HouseOfHam's Avatar Primicerius
    Join Date
    Apr 2007
    Location
    Minnesota, USA
    Posts
    3,030

    Default Re: How-to: Add a background script to your mod

    Hmm... I'd think the monitor by itself would be sufficient... but there is probably a delay after loading a saved game, before the event is generated and the monitor catches is. One thing you could try is change the 1tpy script logic like this:

    Code:
    console_command date 0
    console_command season summer
    while I_TurnNumber < 1
    end_while
    ;...
    console_command date 1000
    console_command season summer
    while I_TurnNumber < 1001
    end_while
    This should prevent the previous script from advancing in the situation you described, so you won't need the while loop around it.
    RTR website/SVN admin

    - Settlement coordinate locator -for RTW/M2TW
    - EDB Validator v1.2.8 (Oct 16, 2012) - for RTW/M2TW
    - RTW scripting tutorials
    - n-turns per year script generator

  15. #15

    Default Re: How-to: Add a background script to your mod

    Good suggestion, but in this case, if the date of the saved game (for example 5) is lower than the date of the previous game (for example 10), the date of the new game will appear wrong (in the example 10 in stead of 5).
    However, I guess the date will be corrected as soon as you reactivate the script again. I'll try it to see if this way the scripts stop getting hang until the end of turn when you load another game.

  16. #16
    Indefinitely Banned
    Join Date
    Jun 2008
    Location
    England
    Posts
    1,058

    Default Re: How-to: Add a background script to your mod

    dosen't matter
    Last edited by Starvin Marvin; August 06, 2008 at 09:04 AM.

  17. #17
    Fireward77's Avatar Civis
    Join Date
    Dec 2007
    Location
    United States
    Posts
    149

    Default Re: How-to: Add a background script to your mod

    I'm new to scripting, (not modding) and I Have created a script but when I try to use it on the imperial campaign, the first turn the advisor pops up when I click on a character for example, and I click on her portrait, it says the text I put in but no show me how button and it works for the first command of the script, then doesn't do anything else.

    heres my script and I have RTW 1.5 with Darthmod 8.0 (also added by me a few units) installed. If I have a problem with my script, please show me whats wrong and how to fix it.


    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
    ; Handle saved game reloads
    monitor_event GameReloaded TrueCondition

    ;end_monitor
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; This is where to put your own code
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    console_command control greek_cities
    console_command capture_settlement "Phraaspa"
    console_command capture_settlement "Sparta"
    console_command kill_character "Flavius Julius"
    console_command kill_character "Hekhemmut"
    console_command kill_character "Khnumhoptep"
    console_command kill_character "Antiochus"
    console_command kill_character "Aristarchus"
    console_command kill_character "Demetrius"
    console_command kill_character "Hanno"
    console_command kill_character "Kiya"
    console_command kill_character "Burrhus"
    console_command kill_character "Theages"
    console_command kill_character "Theodekles"
    console_command kill_character "Theophanes"
    console_command kill_character "Annibas"
    console_command kill_character "Brennus"
    console_command kill_character "Gisgo"
    console_command kill_character "Eporedorix"
    console_command kill_character "Vindex"
    console_command kill_character "Arminius"
    console_command kill_character "Ariogaisus"
    console_command kill_character "Hariulfus"
    console_command kill_character "Barrivendos"
    console_command kill_character "Belenus"
    console_command kill_character "Cynfawr"
    console_command kill_character "Artaxias"
    console_command kill_character "Rusa"
    console_command kill_character "Zyraxes"
    console_command kill_character "Vezina"
    console_command kill_character "Kleomenes of Sparta"
    console_command kill_character "Dionysios of Sparta"
    console_command kill_character "Antigonos of Sparta"
    console_command kill_character "Eumenes of Sparta"
    console_command kill_character "Memnon of Sparta"
    console_command kill_character "Muttines"
    console_command kill_character "Syphax"
    console_command kill_character "Zipoetes"
    console_command kill_character "Partatua"
    console_command kill_character "Viriathus"
    console_command kill_character "Caraunios"
    console_command kill_character "Matugenus"
    console_command kill_character "Lucius Julius"
    console_command kill_character "Quintus Julius"
    console_command kill_character "Vibius Julius"
    console_command kill_character "Sextus Antio"
    console_command kill_character "Decius Curtius"
    console_command kill_character "Oppius Clausus"
    console_command kill_character "Aulus Brutus"
    console_command kill_character "Marcus Attius"
    console_command kill_character "Luca Antonius"
    console_command kill_character "Caius Flaminius"
    console_command kill_character "Vibius Brutus"
    console_command kill_character "Cornelius Scipio"
    console_command kill_character "Julianus Scipio"
    console_command kill_character "Quintus Scipio"
    console_command kill_character "Quintus Caecus"
    console_command kill_character "Aulus Ovidius"
    console_command kill_character "Aulus Volesus"
    console_command kill_character "Gaius Scipio"
    console_command kill_character "Flavius Nepos"
    console_command kill_character "Servius Maxentius"
    console_command kill_character "Antigonos"
    console_command kill_character "Gyras"
    console_command kill_character "Arsaces"
    console_command kill_character "Ardumanish"
    console_command kill_character "Mithradates"
    console_command kill_character "Pharnaces"
    console_command kill_character "Herakles"
    console_command kill_character "Tiberius Brutus"
    console_command kill_character "Amulus Brutus"
    console_command kill_character "Decius Maxentius"
    console_command kill_character "Marcus Maxentius"
    spawn_army
    faction parthia
    character Xerxes, named character, age 30, , x 209, y 61
    unit east infantry soldiers 100 exp 5 armour 0 weapon_lvl 0
    unit east infantry soldiers 100 exp 4 armour 0 weapon_lvl 0
    unit east infantry soldiers 100 exp 5 armour 0 weapon_lvl 0
    unit east infantry soldiers 100 exp 4 armour 0 weapon_lvl 0
    unit merc arab cavalry soldiers 100 exp 3 armour 0 weapon_lvl 0
    unit east heavy cataphract soldiers 50 exp 7 armour 0 weapon_lvl 0
    unit east persian cavalry soldiers 50 exp 7 armour 0 weapon_lvl 0
    unit east camel cataphract soldiers 50 exp 7 armour 0 weapon_lvl 0
    unit east heavy cataphract soldiers 20 exp 7 armour 0 weapon_lvl 0
    unit east persian cavalry soldiers 20 exp 7 armour 0 weapon_lvl 0
    unit east camel cataphract soldiers 20 exp 7 armour 0 weapon_lvl 0
    unit parthia huvaka soldiers 20 exp 7 armour 0 weapon_lvl 0
    unit east hillmen soldiers 100 exp 0 armour 0 weapon_lvl 0
    unit east archer soldiers 100 exp 7 armour 0 weapon_lvl 0
    unit east archer soldiers 100 exp 7 armour 0 weapon_lvl 0
    unit east archer soldiers 100 exp 7 armour 0 weapon_lvl 0
    unit east elephant soldiers 38 exp 7 armour 0 weapon_lvl 0
    end
    spawn_army
    faction pontus
    character Rhadamsades, named character, age 30, , x 112, y 65
    unit east hillmen soldiers 150 exp 5 armour 0 weapon_lvl 0
    unit east generals cavalry early soldiers 20 exp 5 armour 1 weapon_lvl 0
    unit east infantry soldiers 100 exp 4 armour 0 weapon_lvl 0
    unit east archer soldiers 100 exp 4 armour 0 weapon_lvl 0
    unit merc eastern infantry soldiers 100 exp 3 armour 0 weapon_lvl 0
    unit east cappodocian cavalry soldiers 100 exp 3 armour 0 weapon_lvl 0
    unit east cappodocian cavalry soldiers 100 exp 3 armour 0 weapon_lvl 0
    unit east scythed chariot soldiers 100 exp 3 armour 0 weapon_lvl 0
    unit east scythed chariot soldiers 100 exp 3 armour 0 weapon_lvl 0
    unit east chariot archer soldiers 100 exp 3 armour 0 weapon_lvl 0
    unit east chariot archer soldiers 100 exp 3 armour 0 weapon_lvl 0
    end
    spawn_army
    faction greek_cities
    character Leonidas of_Sparta, named character, age 30, , x 134, y 54
    unit greek general's guard cavalry4 soldiers 100 exp 9 armour 3 weapon_lvl 3
    unit greek hoplite spartan soldiers 50 exp 9 armour 3 weapon_lvl 3
    unit greek hoplite spartan soldiers 50 exp 9 armour 3 weapon_lvl 3
    unit greek hoplite spartan soldiers 50 exp 9 armour 3 weapon_lvl 3
    unit greek hoplite spartan soldiers 50 exp 9 armour 3 weapon_lvl 3
    unit merc thracian soldiers 50 exp 9 armour 3 weapon_lvl 3
    unit merc thracian soldiers 50 exp 9 armour 3 weapon_lvl 3
    unit merc sarmatian cavalry soldiers 50 exp 9 armour 3 weapon_lvl 3
    unit merc sarmatian cavalry soldiers 50 exp 9 armour 3 weapon_lvl 3
    unit merc greek hoplites soldiers 50 exp 9 armour 3 weapon_lvl 3
    unit merc greek hoplites soldiers 50 exp 9 armour 3 weapon_lvl 3
    unit merc barbarian infantry soldiers 50 exp 9 armour 3 weapon_lvl 3
    end
    console_command invulnerable_general "Leonidas of_Sparta"
    terminate_script
    end_monitor
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; End of your code
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ; Spin forever - Do not let the script terminate or any monitors you have set up will immediately get thrown away.
    while I_TurnNumber < 99999
    suspend_unscripted_advice true
    end_while
    end_script

    any help will be appreciated.

  18. #18

    Default Re: How-to: Add a background script to your mod

    It looks as though you have put your code in a monitor event.

    Code:
    monitor_event GameReloaded TrueCondition
    As far as I understand this means that your code will only be activated if you load a saved game.

    Take out this monitor and the terminate_script - end_monitor at the end and retry.

  19. #19

    Default Re: How-to: Add a background script to your mod

    I believe this monitor doesn't work anyway...

  20. #20
    Fireward77's Avatar Civis
    Join Date
    Dec 2007
    Location
    United States
    Posts
    149

    Default Re: How-to: Add a background script to your mod

    I Changed It But It Worked Only The First Time, Ill Post My New Script

    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

    ; Handle saved game reloads
    monitor_event GameReloaded TrueCondition

    ;end_monitor

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; This is where to put your own code
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    console_command control greek_cities

    console_command capture_settlement "Phraaspa"

    console_command capture_settlement "Sparta"

    console_command kill_character "Flavius Julius"

    console_command kill_character "Hekhemmut"

    console_command kill_character "Khnumhoptep"

    console_command kill_character "Antiochus"

    console_command kill_character "Aristarchus"

    console_command kill_character "Demetrius"

    console_command kill_character "Hanno"

    console_command kill_character "Kiya"

    console_command kill_character "Burrhus"

    console_command kill_character "Theages"

    console_command kill_character "Theodekles"

    console_command kill_character "Theophanes"

    console_command kill_character "Annibas"

    console_command kill_character "Brennus"

    console_command kill_character "Gisgo"

    console_command kill_character "Eporedorix"

    console_command kill_character "Vindex"

    console_command kill_character "Arminius"

    console_command kill_character "Ariogaisus"

    console_command kill_character "Hariulfus"

    console_command kill_character "Barrivendos"

    console_command kill_character "Belenus"

    console_command kill_character "Cynfawr"

    console_command kill_character "Artaxias"

    console_command kill_character "Rusa"

    console_command kill_character "Zyraxes"

    console_command kill_character "Vezina"

    console_command kill_character "Kleomenes of Sparta"

    console_command kill_character "Dionysios of Sparta"

    console_command kill_character "Antigonos of Sparta"

    console_command kill_character "Eumenes of Sparta"

    console_command kill_character "Memnon of Sparta"

    console_command kill_character "Muttines"

    console_command kill_character "Syphax"

    console_command kill_character "Zipoetes"

    console_command kill_character "Partatua"

    console_command kill_character "Viriathus"

    console_command kill_character "Caraunios"

    console_command kill_character "Matugenus"

    console_command kill_character "Lucius Julius"

    console_command kill_character "Quintus Julius"

    console_command kill_character "Vibius Julius"

    console_command kill_character "Sextus Antio"

    console_command kill_character "Decius Curtius"

    console_command kill_character "Oppius Clausus"

    console_command kill_character "Aulus Brutus"

    console_command kill_character "Marcus Attius"

    console_command kill_character "Luca Antonius"

    console_command kill_character "Caius Flaminius"

    console_command kill_character "Cornelius Scipio"

    console_command kill_character "Julianus Scipio"

    console_command kill_character "Quintus Scipio"

    console_command kill_character "Quintus Caecus"

    console_command kill_character "Aulus Ovidius"

    console_command kill_character "Aulus Volesus"

    console_command kill_character "Flavius Nepos"

    console_command kill_character "Servius Maxentius"

    console_command kill_character "Antigonos"

    console_command kill_character "Gyras"

    console_command kill_character "Arsaces"

    console_command kill_character "Ardumanish"

    console_command kill_character "Mithradates"

    console_command kill_character "Pharnaces"

    console_command kill_character "Tiberius Brutus"

    console_command kill_character "Amulus Brutus"

    console_command kill_character "Decius Maxentius"

    console_command kill_character "Marcus Maxentius"

    spawn_army
    faction parthia
    character Xerxes, named character, age 30, , x 209, y 61
    unit east infantry soldiers 100 exp 5 armour 0 weapon_lvl 0
    unit east infantry soldiers 100 exp 4 armour 0 weapon_lvl 0
    unit east infantry soldiers 100 exp 5 armour 0 weapon_lvl 0
    unit east infantry soldiers 100 exp 4 armour 0 weapon_lvl 0
    unit merc arab cavalry soldiers 100 exp 3 armour 0 weapon_lvl 0
    unit east heavy cataphract soldiers 50 exp 7 armour 0 weapon_lvl 0
    unit east persian cavalry soldiers 50 exp 7 armour 0 weapon_lvl 0
    unit east camel cataphract soldiers 50 exp 7 armour 0 weapon_lvl 0
    unit east heavy cataphract soldiers 20 exp 7 armour 0 weapon_lvl 0
    unit east persian cavalry soldiers 20 exp 7 armour 0 weapon_lvl 0
    unit east camel cataphract soldiers 20 exp 7 armour 0 weapon_lvl 0
    unit parthia huvaka soldiers 20 exp 7 armour 0 weapon_lvl 0
    unit east hillmen soldiers 100 exp 0 armour 0 weapon_lvl 0
    unit east archer soldiers 100 exp 7 armour 0 weapon_lvl 0
    unit east archer soldiers 100 exp 7 armour 0 weapon_lvl 0
    unit east archer soldiers 100 exp 7 armour 0 weapon_lvl 0
    unit east elephant soldiers 38 exp 7 armour 0 weapon_lvl 0
    end

    spawn_army
    faction pontus
    character Rhadamsades, named character, age 30, , x 112, y 65
    unit east hillmen soldiers 150 exp 5 armour 0 weapon_lvl 0
    unit east generals cavalry early soldiers 20 exp 5 armour 1 weapon_lvl 0
    unit east infantry soldiers 100 exp 4 armour 0 weapon_lvl 0
    unit east archer soldiers 100 exp 4 armour 0 weapon_lvl 0
    unit merc eastern infantry soldiers 100 exp 3 armour 0 weapon_lvl 0
    unit east cappodocian cavalry soldiers 100 exp 3 armour 0 weapon_lvl 0
    unit east cappodocian cavalry soldiers 100 exp 3 armour 0 weapon_lvl 0
    unit east scythed chariot soldiers 100 exp 3 armour 0 weapon_lvl 0
    unit east scythed chariot soldiers 100 exp 3 armour 0 weapon_lvl 0
    unit east chariot archer soldiers 100 exp 3 armour 0 weapon_lvl 0
    unit east chariot archer soldiers 100 exp 3 armour 0 weapon_lvl 0
    end

    spawn_army
    faction greek_cities
    character Leonidas of_Sparta, named character, age 30, , x 200, y 60
    unit greek general's guard cavalry4 soldiers 100 exp 9 armour 3 weapon_lvl 3
    unit greek hoplite spartan soldiers 50 exp 9 armour 3 weapon_lvl 3
    unit greek hoplite spartan soldiers 50 exp 9 armour 3 weapon_lvl 3
    unit greek hoplite spartan soldiers 50 exp 9 armour 3 weapon_lvl 3
    unit greek hoplite spartan soldiers 50 exp 9 armour 3 weapon_lvl 3
    unit merc thracian soldiers 50 exp 9 armour 3 weapon_lvl 3
    unit merc thracian soldiers 50 exp 9 armour 3 weapon_lvl 3
    unit merc sarmatian cavalry soldiers 50 exp 9 armour 3 weapon_lvl 3
    unit merc sarmatian cavalry soldiers 50 exp 9 armour 3 weapon_lvl 3
    unit merc greek hoplites soldiers 50 exp 9 armour 3 weapon_lvl 3
    unit merc greek hoplites soldiers 50 exp 9 armour 3 weapon_lvl 3
    unit merc barbarian infantry soldiers 50 exp 9 armour 3 weapon_lvl 3
    end

    console_command move_character "Leonidas of_Sparta" x 209 y 61

    console_command invulnerable_general "Leonidas of_Sparta"

    console_command diplomatic_stance seleucid parthia Atwar

    console_command diplomatic_stance seleucid armenia Atwar

    console_command diplomatic_stance seleucid pontus Atwar

    console_command diplomatic_stance greek_cities parthia Atwar

    console_command diplomatic_stance parthia armenia Allied

    console_command diplomatic_stance parthia pontus Allied

    console_command diplomatic_stance armenia pontus Allied

    console_command diplomatic_stance greek_cities armenia Atwar

    console_command diplomatic_stance greek_cities armenia Atwar

    console_command diplomatic_stance greek_cities seleucid Allied


    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; End of your code
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    ; Spin forever - Do not let the script terminate or any monitors you have set up will immediately get thrown away.
    while I_TurnNumber < 99999
    suspend_unscripted_advice true
    end_monitor

    end_while

    end_script

Page 1 of 6 123456 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
  •