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

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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...

  2. #2
    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!

  3. #3

    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.

  4. #4
    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 .

  5. #5

    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.

  6. #6
    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 .

  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

    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

  8. #8

    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

  9. #9
    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

  10. #10

    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

  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

    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

  12. #12

    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

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

  14. #14

    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?

  15. #15

    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
  •