Page 6 of 6 FirstFirst 123456
Results 101 to 119 of 119

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

  1. #101
    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: How-to: Add a background script to your mod

    They are but only once or perhaps only one faction because you didn't include the following at the very of the script.

    Code:
    while I_TurnNumber < 99999
      suspend_unscripted_advice true
    end_while
    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

  2. #102

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

    Thanks now it's works

  3. #103
    Greno Zee's Avatar Foederatus
    Join Date
    Jun 2007
    Location
    Antwerpen, Belgium
    Posts
    42

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

    Hi guys!
    Sorry if you consider this a dig but this thread seems to be the most comprehensive coverage of the background script execution problematic.
    Therefore I wanna share my own finds here - even though it's been years since anyone worried about this.

    GAMERELOADED EVENT
    Indeed Bardo's final method is probably as far as we get towards automatic execution of background scripts.
    But I've done some aditional testing and discovered a little bit more. First, an explanation of why the trigger on GameReloaded event works the way it does. Bardo explains on the ORG:
    Quote Originally Posted by Bardo
    The method is based on these ideas about advices:
    -"AdviceThread Lotr_Script_Thread 0": this is the way you call the advice. The last number represents the way the advice-counter is incremented:
    1: it increases the advice-counter by 1, then the engine compares the advice-counter to the threshold of the advice (similar to traits/ancillaries), and if equal the advisor appears.
    0:it increases the advice-counter by 1, then the engine compares the advice-counter to the threshold of the advice. If equal, the advisor appears AND then it decreases the advice-counter by 1 again.

    Result:
    1-the first time you start a campaign, when you select a settlement/army, the advice-counter is increased to 1, nothing happens.
    2-the 2nd time, the counter reaches the treshold 2, and the advisor remembers you to launch the script (pressing show me button).
    3-no matter you press show_me or not, the advisor will not appear again until you reload a game.
    NOTE: Since we have not defined "MaxRepeats", it seems that the max value of the advice-counter is equal to the Threshold.

    4-when you reload a game, the trigger Reload_Script_Trigger is executed, it calls the advice, and it decreases the counter by one (2-1=1 in total)
    5-since now, the first time you select a settlement/army, the counter will reach the threshold 2 again, and the advisor will pop-up.
    My testing shows the following and I'm confident this is the real way things work:

    • AdviceThread Lotr_Script_Thread 1 - there's no confusion here it adds 1 to the counter and opens the advise up, if Threshold is reached
    • AdviceThread Lotr_Script_Thread 0 - This resets the counter first to 0 and then increases by 1.

    Now the GameReloaded event. Many people suspect it doesn't work, Bardo claims it does, since his method works (and it really does). Well, both camps are right.
    Mys testing shows this trigger gets fired, no doubt about it:
    Code:
    ;------------------------------------------ LOTR-TW trigger
    Trigger Reload_Script_Trigger
        WhenToTest GameReloaded
    
        AdviceThread Lotr_Script_Thread  0
    it does effect the counter towards the Threshold. But the Advisor never shows up and my guess here is that the moment this trigger gets fired the engine doesn't have the UI ready yet to show the advisor.

    These finds brought me to an idea. Bardo uses the GameReloaded event in the background script to terminate the script when a game is reloaded (again, this really works):
    Code:
    monitor_event GameReloaded TrueCondition
        terminate_script
    end_monitor
    Well, how about this?
    Code:
    declare_counter C_GameReloaded
    
    monitor_event GameReloaded TrueCondition
        set_counter C_GameReloaded 1
    end_monitor
    
    monitor_conditions I_CompareCounter C_GameReloaded = 1
        wait 5
        console_command trigger_advice Lotr_Script_Thread
        advance_advice_thread Lotr_Script_Thread no_dismiss
        set_counter C_GameReloaded 0
        terminate_script
    end_monitor
    it doesn't work - hopefully yet . The logic would seem right but I'm really new to RTW scripting so I might be missing some obvious flaw in this concept...
    I'll certainly keep on testing this

    ADDITIONAL SMALL FINDS
    When you reload a game, occasionally, showing the advisor with the current season and date(advance_advice_thread Season_Year_TurnXX_Thread), it shows only the Startup advisor (Lotr_Script_Thread). Yet, the script is started - when you end the turn, you get the season and year when your turn begins.
    Using "suspend_unscripted_advice true" at the start of the script does seem to prevent that.

    Next, the following in Bardo's script somehow messed things up:
    Code:
    wait 1
    select_ui_element advisor_dismiss_button
    simulate_mouse_click lclick_up
    I have removed it and experienced no problems at all.
    So this is my version of the background script:
    Code:
    script
    
    suspend_unscripted_advice true  
    declare_show_me
    ...
    Hope this helps and we're not done yet with this .
    Last edited by Greno Zee; December 15, 2010 at 06:06 AM.

  4. #104

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

    Hey, I'm glad people still continues reasearching on this. I feel we still need a complete guide about the advice file, but after many test, all I got was some theories about how it works, nothing really confirmed.

    Good point about this:
    Code:
    AdviceThread Lotr_Script_Thread 0 - This resets the counter first to 0 and then increases by 1.
    Your explanation seems to confirm my experiments with threshold=1. But then, if threshold is 2, this advice is never launched?

    This code is not needed, it simply closes the advisor when the script is executed:
    Code:
    wait 1
    select_ui_element advisor_dismiss_button
    simulate_mouse_click lclick_up
    About the line:
    Code:
    suspend_unscripted_advice true
    I do not use it because our mod launches unscripted advices and that line would avoid them.

    In fact, all my reaserch about launching scripts was focused to avoid the use of that command suspend_unscripted_advice. Many scripters seems to use HouseOfHam method, that is simpler and gets similar results. But there is one little advantage of my method, that it is very important to me:

    - When you are playing a campaign with scripts activated, and you reload a savegame, the script is reactivated automatically.
    (It is not completely automatic because: If you load a savegame when you just entered the game, you need to press on advisor portrait, the same with both methods).

    About this...
    Code:
    declare_counter C_GameReloaded
    
    monitor_event GameReloaded TrueCondition
        set_counter C_GameReloaded 1
    end_monitor
    
    monitor_conditions I_CompareCounter C_GameReloaded = 1
        wait 5
        console_command trigger_advice Lotr_Script_Thread
        advance_advice_thread Lotr_Script_Thread no_dismiss
        set_counter C_GameReloaded 0
        terminate_script
    end_monitor
    I'd say it is exactly the same than this:
    Code:
    monitor_event GameReloaded TrueCondition
        wait 5
        console_command trigger_advice Lotr_Script_Thread
        advance_advice_thread Lotr_Script_Thread no_dismiss
        terminate_script
    end_monitor
    I tested something similar, with different waiting times, and I had no luck.
    As you say, I'm sure GameReloaded does work, but I have been unable to use it directly to launch the advices.
    I wish you more luck.
    Last edited by Bardo; December 15, 2010 at 12:25 PM.

  5. #105
    Greno Zee's Avatar Foederatus
    Join Date
    Jun 2007
    Location
    Antwerpen, Belgium
    Posts
    42

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

    Hey Bardo, great you're still interested!

    AdviceThread Lotr_Script_Thread 0
    I found out how it works exactly by setting the Threshold to higher numbers. I put to CharacterSelected trigger
    AdviceThread Lotr_Script_Thread 0 and to SettlementSelected trigger AdviceThread Lotr_Script_Thread 1. Whenever I selected any character, I needed Threshold - 1 selected settlements to get the Advisor show up

    Now I'm very interested in your comment that when you don't use
    suspend_unscripted_advice true, the script stays running after loading a campaign. I've got a very simple script, where there is one event monitor declared. Whenever I reload the game, it stops executing the monitor. So I wondered, is there anything else needed to keep it running after reloading?

    According to the discussion in this very thread wait command in event monitors doesn't work:
    Code:
    monitor_event GameReloaded TrueCondition
        wait 5 ; won't work
        console_command trigger_advice Lotr_Script_Thread
        advance_advice_thread Lotr_Script_Thread no_dismiss
        terminate_script
    end_monitor
    That's why I split it as suggested in the discussion here...

  6. #106
    Greno Zee's Avatar Foederatus
    Join Date
    Jun 2007
    Location
    Antwerpen, Belgium
    Posts
    42

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

    Hm, please, let me correct myself.
    You never said "suspend_unscripted_advice true" would have anything to do with scripts staying in memory after reload. No idea why i interpreted your message this way .
    In any case:
    In none of my tests I've been able to confirm that the background script stays active after you reload a game. I'd be very happy if anyone can prove me wrong. But if I'm not, it means:

    • The following event monitor has got no use:
      Code:
      monitor_event GameReloaded TrueCondition
          terminate_script
      end_monitor
    • The trigger counts do keep their values after reload, so this trigger is indeed required to reset the counter and fire the script up again after the reload:
      Code:
      Trigger Reload_Script_Trigger
          WhenToTest GameReloaded
      
          AdviceThread Lotr_Script_Thread  0
      There is no doubt this trigger does fire, it only seems not to be able to access the user interface and can't be used directly to fire the script, only to reset the count.

    On top of that, I've been able to confirm one of the scariest behaviors I've ever seen in scripting: the scripting engine survives the application shutdown! Even if I close the game using the menus, I've been able to confirm that sometimes some AdviceThread counters keep their values between RTW sessions.
    Very, very frightening!

  7. #107

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

    You are right about "wait" command not working inside monitors, I forgot. Altough I remember to test it with GameReloaded, just in case.

    Don't be scary , the advice counters are saved at this file:
    \preferences\advice
    If you remove it, the file is regenerated with counters to 0.

    Once, I had the idea to use this feature to save the state of script counters, but the advice counters are affected by every campaign and every game you play, so I do not think it would be useful.

    I do not think scripts can keep active after you reload a savegame, I would say they stop working when you load a different game. But sometimes when you load a savegame (always when you reload an autosave) and there is already a script running, the new script does not take effect until the next turn (as you have also verified).
    Well, I'm almost sure that the event GameReloaded is detected by the script previously running (before you reload), probably it is the latest event it detects. And I have verified that I can use it with terminate_script to allow the new script (launched after you reload) to be activated just when you press end turn.
    It is hard to explain. I mean, if you remove this part
    Code:
    monitor_event GameReloaded TrueCondition
        terminate_script
    end_monitor
    the new script will not work until the start of your next turn, and it will miss all the events from the first AI turn.

    As you said, this is not a problem if you are using "suspend_unscripted_advice true".
    I think the problem if you use "suspend_unscripted_advice true" is it prevents the advisor from being showed automatically, and you need to click on the advisor portrait to activate the script. Although I never used that method and I would need to verify the cause.

    With my method, if the advice is declared as "on_display" and the script is declared as "declare_show_me", the advisor is opened automatically and so the scripts are executed automatically as soon as the player press any button.
    In our mod, if you are playing a campaign and you decide to reload a savegame, you do not need to do anything to reactivate the scripts. As soon as you press any button (for example end turn):
    the advisor will be launched thanks to "Gamereload" event, it will be opened automatically thanks to "declare_show_me", and the scripts will be executed automatically thanks to "on_display".

    However, it does not work the first time you load a savegame when you just entered the game. The first time, you need to click the advisor portrait. And this is the only non-automatic issue that I never solved.
    Then it will be automatic again with every reload, at least until another script declared as "declare_show_me" is executed.


    I do not know if you understood something (sorry my english), but I think mine was an important discovery, and I didn't get anyone interested to help me researching that feature: "declare_show_me" + "on_display".
    It took me many time to develop an alternative method without "suspend_unscripted_advice true", but people here considered it just a variant of HouseOfHam's method. I think I advanced one step, and we still need another step to automatize it completely.
    Last edited by Bardo; December 16, 2010 at 05:06 PM.

  8. #108
    Greno Zee's Avatar Foederatus
    Join Date
    Jun 2007
    Location
    Antwerpen, Belgium
    Posts
    42

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

    Thanks for the explanation! I think I perfectly understand all you say.
    And it all makes sense and perfectly fits the results of my own testing.

    Now the good news:
    I've been playing around a bit, reloading games from the main menu, from the game, starting new campaigns, reloading again and the only time I needed to touch the Advisor to launch the script was when I exited the game and started a new campaign. Not after loading anymore .

    But before I tell you, there's one thing I need to ask you. In none of my attempts I was able to lanch the script after loading with the End Turn button. How do you manage that? Whatever I tried, the Advisor started to appear but before it could launch the script, another faction took over and the Advisor moved away.

    And here goes: How did I manage that when I start the game and then load my save, I don't need to click on the advisor to launch the script? Actually, by a workaround, not a real solution.
    I'm sure you provide your users with a shortcut to launch your mod, right? Well, put the -strat:... option in there. It starts a new campaign directly and then your users can either load their game, go to the main menu, whatever. I know many people will find this clumsy but it works for me .

  9. #109

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

    And here goes: How did I manage that when I start the game and then load my save, I don't need to click on the advisor to launch the script? Actually, by a workaround, not a real solution.
    I'm sure you provide your users with a shortcut to launch your mod, right? Well, put the -strat:... option in there. It starts a new campaign directly and then your users can either load their game, go to the main menu, whatever. I know many people will find this clumsy but it works for me
    Good job! it works for me too. We can create this shortcut named "play campaign" or something similar and people who use it would not need to be worried about activation of scripts.

    I've been playing around a bit, reloading games from the main menu, from the game, starting new campaigns, reloading again and the only time I needed to touch the Advisor to launch the script was when I exited the game and started a new campaign.
    I guess there is a mistake in your sentence, and you wanted to say it fails when you start a new campaign without exiting the game. Doesn't it?

    Else, I have good news for you, because that issue was solved long time ago. Both systems described in this topic should launch the script automatically when you start a new campaign.

    These lines in the "Campaign Script" (placed in the campaign folder) makes the trick in my case:
    script

    declare_show_me

    ;...

    wait 1
    console_command trigger_advice Lotr_Script_Thread
    advance_advice_thread Lotr_Script_Thread no_dismiss


    end_script
    I don't remember now, but I think I needed 2 triggers to increase the advice counter and to prepare it for the gamereloaded event.

    But before I tell you, there's one thing I need to ask you. In none of my attempts I was able to lanch the script after loading with the End Turn button. How do you manage that? Whatever I tried, the Advisor started to appear but before it could launch the script, another faction took over and the Advisor moved away.
    I have just tested in my new pc and you are right, the advisor does not have time to appear before the AI starts to move.
    But I promiss you it worked in my old pc. I even verified if the scripts were active all along the AI turn, and the scripts didn't miss any AI faction turn.

    It might depend on the speed of the pc. I already noticed my only script that used the "wait" command with a timer (a question to the player to control the fellowship of the ring) stoped working when I changed to a faster pc.
    Then, I guess the "end turn" button is not a reliable way to activate the background script... it is a pitty.

  10. #110
    Greno Zee's Avatar Foederatus
    Join Date
    Jun 2007
    Location
    Antwerpen, Belgium
    Posts
    42

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

    Quote Originally Posted by Bardo View Post
    Good job! it works for me too. We can create this shortcut named "play campaign" or something similar and people who use it would not need to be worried about activation of scripts.
    Actually, not even that. Force your users to always open RTW this way if they want to play your mod. If you do, even when they launch and want to load a previous save, the advisor button will not come up flashing anymore and the script launches smoothly without any user interaction.
    Quote Originally Posted by Bardo View Post
    I guess there is a mistake in your sentence, and you wanted to say it fails when you start a new campaign without exiting the game. Doesn't it?
    Sorry, wrong terminology. I meant game as a game in progress - exiting the game to main menu, without exiting RTW (the applications). But we understand each other .
    Quote Originally Posted by Bardo View Post
    Else, I have good news for you, because that issue was solved long time ago. Both systems described in this topic should launch the script automatically when you start a new campaign.
    I know, I'm using this trick and it works . But when you play a game, then quit to main menu and then start a new campaign, the Advisor comes up flashing and the user has to click it to launch the script. Just the same what you had when you start the application and load a game that's no autosave - which gets cured by using the -strat:... parameter.
    Quote Originally Posted by Bardo View Post
    Then, I guess the "end turn" button is not a reliable way to activate the background script... it is a pitty.
    Looks like that. Lucky enough, I can hardly imagine anyone loading a game and ending a turn without checking the status of their empire at all, so I wouldn't worry about this much .
    Quote Originally Posted by Bardo
    Don't be scary , the advice counters are saved at this file:
    \preferences\advice
    Thanks for pointing this out - there's still a lot I don't know about the internal of RTW .

  11. #111
    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

    AFAIK, \preferences\advice only stored values for threads marked as Supressible, the ones where you get a little checkbox you can hit not to see them again.
    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. #112

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

    Well, after reading part of the debate, I feel a bit stupid asking the following, but anyway, I'll do it. Here it goes:
    I have followed the whole explanation, and the xtpy_script is working (I'm using 4 turns per year). However, I had to put everything into the background script .txt file. Is there a way of keep everything on separate files? Do I need some kind of trigger? Any help on that matter will be great

    PS: I have read the Beginner's Scripting guide and still, I couldn't get the answer. Someone should release a scripting guide for dummies.
    There are none so enslaved as those who falsely believe they are free

  13. #113
    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

    What do you mean by "everything"? Is something not working? 4tpy script is normally incorporated into the background script, so what you've done shouldn't be causing any problems.
    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

  14. #114

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

    Quote Originally Posted by HouseOfHam View Post
    What do you mean by "everything"? Is something not working? 4tpy script is normally incorporated into the background script, so what you've done shouldn't be causing any problems.
    Ok, so that's all. Just another thing: do I have to include the whole code? I mean, at the beginning of the xtpy_script.txt file I get the following lines:

    Code:
    script
    
    declare_show_me				; Used to automatically open the advisor text bubble when advance_advice_thread is called
    
    suspend_during_battle on
    suspend_unscripted_advice true
    
    ;console_command toggle_perfect_spy
    Do I have to include all that into the monitor's part of the background script?

    PS: Sorry for posting here, I thought this was the "How-to: Setup your mod to have more than 2 turns per year" thread
    There are none so enslaved as those who falsely believe they are free

  15. #115
    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

    Nope, just the stuff that sets year, season, and checks for turn numbers. If you took background_script.txt from this tutorial, it already has everything else.
    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

  16. #116

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

    Thanks! This is the last one: shall I include other pieces of code before the 4tpy script or after it? I mean, does it change anything the position of the code in the background script file?
    There are none so enslaved as those who falsely believe they are free

  17. #117
    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

    The 4tpy code pauses at while loops on every turn, so any monitors that need to be active from the beginning would need to be declared before it. If necessary, you could also embed code between turns.
    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

  18. #118

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

    Can anyone help me with this code?
    Code:
    ---------------------------------------------------------------------------------------------------------------------------
    -- DOPSHOGUN
    --
    
    
    local current_dopshogun = ""
    
    
    local function OnFactionTurnedShogun(context)
        local current_dopshogun = context.string;
        		scripting.game_interface:create_force(--[FACTION]--
    												current_dopshogun, 
    											--[SPECIFIC ARMY LIST]--
    												"Cav_Spear_Great_Guard,Cav_Spear_Yari_Cavalry,Cav_Spear_Yari_Cavalry", 
    											--[COORDINATES]--	
    												-44.0, -124.0, 
    											--[ID]--
    												"Great Guard", 
    											--[USE_COMMAND_QUEUE]--
    												true)
    				
    		scripting.game_interface:create_force(--[FACTION]--
    												current_dopshogun, 
    											--[SPECIFIC ARMY LIST]--
    												"Heavy_Ship_Nihon_Maru,Light_Ship_Bow_Kobaya,Light_Ship_Bow_Kobaya",
    											--[COORDINATES]--	
    												-64.0, -130.5, 
    											--[ID]--
    												"Epic Ship", 
    											--[USE_COMMAND_QUEUE]--
    												true)
    		
    		
    
    
    end
    How can I make this deliver when the human faction owns a particular region?

  19. #119

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

    Evening all,

    I was able to successfully install and operate the Rome Total Realism mod, which looks great. It was my impression that a 4tpy script was integral to it, however it does not appear to be so. I have had little luck in locating a 4tpy script that currently works for my mac app store version of RTW, and have not had any luck creating my own script, despite following the directions earlier in this thread. I was wondering if anyone might be able to point me in the right direction or offer some advice, as most expertise appears to either be focused on the pc version, or on the newer RTWII.

    Thanks in advance.

Page 6 of 6 FirstFirst 123456

Posting Permissions

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