-
Can I use a script to end the turn?
Can I use simulate_mouse_click to end the turn? Is there a better way of doing it?
I'm trying to create a script that does this:
1. Starts as faction 1.
2. Switches to faction 2, so that the AI plays the turn for faction 1.
3. Switches to faction 1 and ends the turn.
4. Loop back to 1, until the counter reaches x.
Here's the code I've got so far:
-
Re: Can I use a script to end the turn?
Maybe something like this?
select_ui_element end_turn
simulate_mouse_click lclick_down
simulate_mouse_click lclick_up
-
Re: Can I use a script to end the turn?
Okay, that does work, I just can't figure out how to loop it.
-
Re: Can I use a script to end the turn?
Here's the code I'm using now:
There are two tasks that I still need to complete:
1. Figure out how to loop this script, so that it keeps advancing turns under AI control until it reaches a certain turn number.
2. Create triggers to switch control temporarily to another faction whenever a dialog box pops up (eg a treaty negotiation, or battle, or adoption box).
Can anyone help with #1? Please? I'm guessing it has something to do with monitors and whiles, but I just don't get it.
-
Re: Can I use a script to end the turn?
I'm not sure that your objective is possible at all.
Do you want the AI to play all factions for some turns?
I know there is a method to make the AI play the game (I think the option -ai in the desktop shortcut), but I wonder if you can retrieve the control of the game after some turns.
For example, I would try a background script (started directly at the beginning of the campaign) with the console_command control romans_julii option after some turns.
As one possibility:
Code:
script
declare_counter loop
monitor_event FactionTurnStart FactionType romans_julii
and I_TurnNumber = 2
console_command control romans_julii
terminate_monitor
end_monitor
while I_CompareCounter loop = 0
end_while
end_script
It is only a draft, but perhaps you can calibrate if the solution is possible.
After that, if really you can play julii, you must save the game and load the saved campaign with a normal shortcut to RTW (without -ai option). In such case the background script won't work.
-
Re: Can I use a script to end the turn?
Ops, posting at the same time.
Could you explain the main objective of the script?
I don't understand if you are trying to play different factions along the game, or only taking decisions for the AI in some moments. :dizzy2:
-
Re: Can I use a script to end the turn?
I think what you want might be something similar to ER's year jump script - its only little download you might as well have a look at it: https://forums.totalwar.org/vb/showthread.php?t=65109
That was using an emerging faction from BI though, I'm not sure if it will work if you haven't got a redundant faction to switch control to :inquisitive:
EDIT: lots of posting at same time! You can not get control back after using -ai on the shortcut unfortunately.
-
Re: Can I use a script to end the turn?
Quote:
Originally Posted by Makanyane
I think what you want might be something similar to ER's year jump script - its only little download you might as well have a look at it:
https://forums.totalwar.org/vb/showthread.php?t=65109
That was using an emerging faction from BI though, I'm not sure if it will work if you haven't got a redundant faction to switch control to :inquisitive:
EDIT: lots of posting at same time! You can not get control back after using -ai on the shortcut unfortunately.
I was looking for this, but I didn't remember the name of the mod. :embarassed:
And you solved my doubts.
The only problem of year_jump is that it works giving the human player the control of a faction that is not present in the initial game. It is possible to make one faction in RTW "spawned_by_event" without that event, and use it as the "ghost faction". The other limitation is that the number of turns is fixed. I don't know if this fits with the objective of mrtwisties.
-
Re: Can I use a script to end the turn?
Wow, thanks heaps for the responses, guys. It's very encouraging.
What I'd like to be able to do is make a script that'll hand control to the AI for x turns, after which I start playing again. I want to make it work for EB, but I'm testing on RTW 1.5 at the moment because it's faster (and because my EB installation is a bit corrupted).
You can see more about what I'm trying to do here: https://forums.totalwar.org/vb/showthread.php?t=95753
Epistolary Richard's mod, as has been said, works by switching control to an unemerged emergent faction until turn x. Since EB already has 21 factions (none of which are emergent), my understanding is that this just wouldn't work.
If you run this code, you'll advance to the next turn:
Quote:
console_command control egypt
console_command add_money 1000
campaign_wait 60
console_command control romans_julii
There are two problems with it so far:
1. It doesn't run again the next turn, so you have to run it again manually. I'd like it to run automatically at the start of every Julii turn until, say, 200 BCE. I've had a couple of goes at using looped monitors linked to FactionTurnStart FactionIsLocal or FactionType romans_julii, but I just can't get them to work. Here's one example of my crappy code:
2. Whenever the Julii or Egyptians have to make a decision while you're in command of them, you need to be the one making the decision. I was thinking of setting up a bunch of monitors so that, whenever there's a decision to be made, the script will switch control to someone else and then straight back, so that the decision is made for you.
I hope that makes it a bit clearer what I'm trying to do and what I've done. I'm totally hoping that there's just a simple mistake I've made. I'm very new to this.
-
Re: Can I use a script to end the turn?
This one doesn't work at all:
Quote:
declare_counter loop
monitor_event FactionTurnStart FactionType romans_julii
and I_TurnNumber < 5
console_command control romans_julii
campaign_wait 5
console_command add_money 1000
campaign_wait 5
console_command control egypt
campaign_wait 5
console_command add_money 1000
campaign_wait 5
campaign_wait 60
console_command control romans_julii
terminate_monitor
end_monitor
while I_CompareCounter loop = 0
end_while
-
Re: Can I use a script to end the turn?
Maybe if I write out the logical structure of what I'm trying to do, it'll be easier for people to understand me.
Assume you start off in control of faction a, the first faction in the turn sequence. You want to be in control of faction x in turn 200, and you want the AI to play for every faction in the meantime.
Here's the logical structure I want:
Quote:
*** Is the current turn number 200 or greater?
If YES, then:
Quote:
Switch control to faction x, and stop running this script
If NO, then:
Quote:
1. Switch control to the last faction in the turn sequence ("faction z")
2. Wait until the AI has played the turns of all the other factions
3. Switch control to the first faction in the turn sequence ("faction a")
4. Wait until the AI has played the turn for faction z
Go to ***
Is that clearer?
-
Re: Can I use a script to end the turn?
Some points to your attempts.
- If you want a monitor is repeated, don't use terminate_monitor. With this command the monitor is finished completely once it is true for the first time.
- The command console_command control is not as simple as it seems. It only works with some factions and depends on the relative position of them in descr_strat, at least in my experience.
I have this structure in my scripts:
Code:
monitor_event FactionTurnStart FactionType carthage
and I_TurnNumber = 0
console_command control carthage
console_command capture_settlement Saguntum
console_command control romans_julii
terminate_monitor
end_monitor
This piece of script only works when carthage and romans_julii are placed one after the other in descr_strat (romans are playable). In the same campaign, if I try to give control to greek_cities, the command doesn't work.
Moreover, I don't allow the player to do anything during the change of control. It is only to allow the script to use the capture_settlement command with an AI controlled faction.
- After this kind of control change, the human player cannot manage the recruitment and building for one turn. It is a side effect of this command.
Because of that problems, I don't think that a single script will work for all the playable factions at the same time. From your idea of making the script for EB, perhaps the only way to do it is to sacrifice one faction, making it spawned by script, and use it in the same way as ER did in year_jump mod.
Regarding the question of human decisions in diplomacy etc, I think it is not possible, as the rollers don't appear in the AI turns (I cannot see the interest in AI sending messages to itself :laugh4: ). This means you have no event to monitor (afaik).
-
Re: Can I use a script to end the turn?
Roughly speaking, this is the code for 1 - 4:
Quote:
console_command control greek_cities
campaign_wait 60
console_command control romans_julii
campaign_wait 60
It works, more or less. The AI does play turns for all the factions, and it does advance to the next turn. There are problems with the code (eg dialog boxes; using campaign_wait rather than a more sophisticated trigger) but I'd like to focus on getting the overall logical structure working first.
-
Re: Can I use a script to end the turn?
@ Makanyane
Did you use intensivelly the -ai option?
Do you know if it saves automatically the turns?
Do you know if it is compatible with background scripts?
One option could be use this option until a given turn, using the background script to stop it at some date, and use the autosaved file to start a new normal campaign.:juggle2:
-
Re: Can I use a script to end the turn?
Sorry Monkwarrior, we posted at the same time. I like your idea about the -ai switch, it'd be an elegant solution if it worked.
I'm still bashing away at my concept at the moment. But I can't even get this to work:
Quote:
declare_counter loop
monitor_event FactionTurnStart FactionType romans_julii
and I_TurnNumber < 5
add_money 40000
end_monitor
while I_CompareCounter loop = 0
end_while
Thanks for all your help.
-
Re: Can I use a script to end the turn?
on that last example think you're missing
set_counter loop 0
under the declare_counter
not sure if it defaults to that otherwise.
@Monkwarrior, I haven't tried -ai from background script, I might have a look at that. I did get it to save with that on shortcut at one stage but, reloading the save without the shortcut command still set it off on its own again, so I rather gave up on looking at it.
If you are doing anything that switches command to AI I think you may need to look at how rest of script works, I assume that it messes up anything reliant on LocalFaction triggers. I've got Year Jump script triggerable while background script is in use, so I've put a counters in to determine what local faction is on first turn, and use those counters throughout instead of LocalFaction
EDIT: old discussion on -ai for info
https://forums.totalwar.org/vb/showt...ghlight=run_ai
-
Re: Can I use a script to end the turn?
Makanyane - in my own chaste way, I love you. Here's the partially working script:
Quote:
script
declare_counter loop
set_counter loop 0
monitor_event FactionTurnStart FactionType romans_julii
and I_TurnNumber < 5
console_command control greek_cities
campaign_wait 10
console_command add_money 40000
console_command control romans_julii
end_monitor
while I_CompareCounter loop = 0
end_while
end_script
This fast-forwarded me to 268 BCE. All I had to do was click a few boxes along the way. When I got to 268 BCE, the AI had taken Segesta and built a whole bunch of units for the Julii. Meanwhile, the Greeks had built up a fortune of some hundreds of thousands of denarii.
So all I have to do is figure out how to avoid having to click through the scrolls, and I'll be able to use this to fast forward to any turn.
-
Re: Can I use a script to end the turn?
I tested the script again, using it to fast forward 50 turns to 245 BCE. If you decide to do the same, make sure you turn off "follow AI characters", which I didn't do the first time. Turns out the AI likes to put spies and diplomats everywhere, which means you end up following one helluva lot of AI characters. Running RTW.exe in windowed mode was definitely a good idea, though.
The Romans and the Greeks got into an extended naval war, which I witnessed first-hand from both sides. It was actually kind of fun to see, and verified that both factions are highly active when they're under AI control. I guess forgetting to take away +40,000 denarii for the Greeks every turn probably contributed to them getting ornery, huh?
I had also forgotten that those dog units existed in vanilla RTW. Turns out the AI likes to move around whole armies of them. Not sure how I feel about that. Pretty sure the answer is "mirthful", though - the dogs of the Julii more or less chased the Gauls out of northern Italy. Dogmatix would have been ashamed. But then the Gauls came back with a whole mass of soldiers, and they all had a bunch o' fight near the Po.
By the end of the 50 turns:
* The Julii owned northern Italy
* The Brutii owned Epirus and Dalmatia
* The Scipii owned Sicily, Sardinia, Corsica and bits of Tunisia
* The Gauls owned bits of Spain, for which I don't blame them, I understand it's got lovely countryside
* The Seleucids were swallowed by Parthia and the Ptolemies (I mean, *cough*, Egypt)
* Pontus were on their way to becoming a superpower
* The Sweboz and the Getai were both massive
But despite all the fun, it was 50 turns that I had to sit there for, clicking on the occasional scroll. Here are the ones that paused or delayed the turn sequence. I need to find a way to automagically resolve these, so I can do something else with my life while the script is fast-forwarding:
* Diplomacy scrolls
* Naval battle predeployment
* Land battle predeployment
* Assistance requested from SPQR
* Senate missions (create massive lag during the turn sequence)
I can't find events for any of these in the docudemon. Do they exist? And can anyone suggest code for automagically resolving these happenings (preferably with the AI deciding what to do)?
-
Re: Can I use a script to end the turn?
Thanks for the -ai link, M. I'm testing that as well.
-
Re: Can I use a script to end the turn?
Hmmm... my capacity to edit my posts seems to appear and disappear at random.
Anyhoo, first attempts with the -ai command are a bit buggy. I can put myself in control of a faction, I can end turn, I can keep playing with that faction for a bit... I can even save the game I'm playing with the faction. But I can't load the game again. Any attempt to do so CTDs.
I'm trying again with a different faction - the Julii, instead of the Gauls. I figure the Gauls aren't unlocked in my RTW game, so that might be why loading a Gallic game CTDs.
-
Re: Can I use a script to end the turn?
The -ai thing totally works. I just took over a Julii campaign in 168 BCE. Then I saved it. Then I closed RTW. Then I loaded it and played for a bit.
Totally. Works.
-
Re: Can I use a script to end the turn?
afaik the -ai switch will not work properly ...
at least I've ran a zillion games with the -ai switch and there is always "something" that makes me believe there is some diff. (dont ask me what, I just wouldnt risk it, the -ai switch clearly hasnt been intended to jump a campaign ... my advise, dont use it as such)
also about the "simulate_mouse_click lclick_down/up" ... afaik you do not need both, dont know where people got the 2nd command from but I'm not using it and have the same results ...
G
-
Re: Can I use a script to end the turn?
You're right. When I implemented the -ai switch in EB, I couldn't get the EB background script to work, even when I turned the ai switch off and reloaded the game.
-
Re: Can I use a script to end the turn?
just wondering, what are you trying to do?
make some sort of randomised start?
if so, there are easier ways imo, wich again leave slightly more of the control in your hands ...
like I've partially set up my game, take traits and ancillaries, I've made a few hidden traits, where one is used only in descr_strat, it is given to starting families wich than at characterturnstart get a random collection of traits
like so;
Code:
;------------------------------------------
Trigger game_startup2
WhenToTest CharacterTurnStart
Condition IsGeneral
and Trait RS_StartGame >= 1
Affects RS_StopGame 1 Chance 100
Affects RS_Management 1 Chance 30
Affects RS_Influence 1 Chance 30
Affects RS_Law 1 Chance 30
Affects RS_Trading 1 Chance 30
Affects RS_TaxCollection 1 Chance 30
Affects RS_TrainingAgents 1 Chance 30
Affects RS_TrainingUnits 1 Chance 30
the stopgame trait prevents it giving traits again as its the startgame trait's antitrait, together with some random augmentation of the traits the generals get in descr_strat
wich together wich some other settings creates a mild feel of a diff game each "turn 0" (gamestart), scripts can even do the same with entire factions
G
-
Re: Can I use a script to end the turn?
Hi RedSpot, I explained what I'm trying to do a bit more clearly in posts 9 and 11. It's not just about a randomised start - it's about starting the game at a whole new point in history, when the factions are a little more developed.
Since the -ai switch seems a bit buggy, I'm having another crack at my original script. What I'd really like to do now is to set up code to have the AI deal with battles and diplomacy.
Here's my script at the moment:
Quote:
script
declare_counter loop
set_counter loop 0
monitor_event FactionTurnStart FactionType romans_julii
and I_TurnNumber < 5
console_command control greek_cities
campaign_wait 10
console_command add_money 40000
console_command control romans_julii
end_monitor
;monitor_event PreBattlePanelOpen
;console_command puppify_my_love
;end_monitor
;monitor_event NavalAutoResolvePanelOpen
;console_command puppify_my_love
;end_monitor
;monitor_event DiplomacyMission
;console_command puppify_my_love
;end_monitor
;monitor_event ScrollOpened
;console_command puppify_my_love
;end_monitor
while I_CompareCounter loop = 0
end_while
end_script
If I take out the comments on my new monitor_events, RTW 1.5 CTDs as it loads (presumably when it tries to load this script). But these events are in the docudemon - can anyone tell me what I'm doing wrong?
-
Re: Can I use a script to end the turn?
The script is pretty much working. I ripped off some of the code from the EB team - it automatically resolves land and sea battles and exits from diplomacy screens. I still need to:
1. Figure out a way to automatically dismiss the battle results scroll after a land or sea battle.
2. Figure out a way to automatically dismiss all the other scrolls that pop up (blah blah senate mission, etc). They don't pause the turn sequence, but they do create lag.
Here's the code, I'd be very grateful if anyone could help:
Quote:
script
;
declare_counter loop
set_counter loop 0
;
declare_counter clickAutoResolve
set_counter clickAutoResolve 0
;
declare_counter clickAutoResolveNaval
set_counter clickAutoResolveNaval 0
;
declare_counter declineDiplomaticOffer
set_counter declineDiplomaticOffer 0
;
monitor_event FactionTurnStart FactionType romans_julii
console_command control greek_cities
console_command add_money 40000
end_monitor
;
monitor_event FactionTurnStart FactionType greek_cities
console_command control romans_julii
console_command add_money 40000
inc_counter loop 1
end_monitor
;
monitor_event PreBattlePanelOpen TrueCondition
set_counter clickAutoResolve 1
end_monitor
;
monitor_conditions I_CompareCounter clickAutoResolve = 1
set_counter clickAutoResolve 0
select_ui_element prebattle_auto_resolve_button
simulate_mouse_click lclick_down
simulate_mouse_click lclick_up
end_monitor
;
monitor_event NavalAutoResolvePanelOpen TrueCondition
set_counter clickAutoResolveNaval 1
end_monitor
;
monitor_conditions I_CompareCounter clickAutoResolveNaval = 1
set_counter clickAutoResolveNaval 0
select_ui_element prebattle_auto_resolve_button
simulate_mouse_click lclick_down
simulate_mouse_click lclick_up
end_monitor
;
monitor_event DiplomacyPanelOpen TrueCondition
set_counter declineDiplomaticOffer 1
end_monitor
;
monitor_conditions I_CompareCounter declineDiplomaticOffer = 1
select_ui_element confirm_quit_scroll
simulate_mouse_click lclick_down
simulate_mouse_click lclick_up
end_monitor
;
while I_CompareCounter loop < 5
end_while
;
console_command control egypt
;
end_script
-
Re: Can I use a script to end the turn?
The script is pretty much working. I ripped off some of the code from the EB team - it automatically resolves land and sea battles and exits from diplomacy screens. I still need to:
1. Figure out a way to automatically dismiss the battle results scroll after a land or sea battle.
2. Figure out a way to automatically dismiss all the other scrolls that pop up (blah blah senate mission, etc). They don't pause the turn sequence, but they do create lag.
Here's the code, I'd be very grateful if anyone could help:
Quote:
script
;
declare_counter loop
set_counter loop 0
;
declare_counter clickAutoResolve
set_counter clickAutoResolve 0
;
declare_counter clickAutoResolveNaval
set_counter clickAutoResolveNaval 0
;
declare_counter declineDiplomaticOffer
set_counter declineDiplomaticOffer 0
;
monitor_event FactionTurnStart FactionType romans_julii
console_command control greek_cities
console_command add_money 40000
end_monitor
;
monitor_event FactionTurnStart FactionType greek_cities
console_command control romans_julii
console_command add_money 40000
inc_counter loop 1
end_monitor
;
monitor_event PreBattlePanelOpen TrueCondition
set_counter clickAutoResolve 1
end_monitor
;
monitor_conditions I_CompareCounter clickAutoResolve = 1
set_counter clickAutoResolve 0
select_ui_element prebattle_auto_resolve_button
simulate_mouse_click lclick_down
simulate_mouse_click lclick_up
end_monitor
;
monitor_event NavalAutoResolvePanelOpen TrueCondition
set_counter clickAutoResolveNaval 1
end_monitor
;
monitor_conditions I_CompareCounter clickAutoResolveNaval = 1
set_counter clickAutoResolveNaval 0
select_ui_element prebattle_auto_resolve_button
simulate_mouse_click lclick_down
simulate_mouse_click lclick_up
end_monitor
;
monitor_event DiplomacyPanelOpen TrueCondition
set_counter declineDiplomaticOffer 1
end_monitor
;
monitor_conditions I_CompareCounter declineDiplomaticOffer = 1
select_ui_element confirm_quit_scroll
simulate_mouse_click lclick_down
simulate_mouse_click lclick_up
end_monitor
;
while I_CompareCounter loop < 5
end_while
;
console_command control egypt
;
end_script
-
Re: Can I use a script to end the turn?
It occurs to me that I could use the same counter for both land and sea battles, and just create two separate triggers for activating that counter. I might do that, if only for the sake of efficiency.
But getting rid of the battle results screen is the key concern. Do you think I could just nerf the entire UI while the script is running?
-
Re: Can I use a script to end the turn?
Here's the more efficient version. It also has an automatic scroll-closer implemented, but I still haven't figured out a way of automatically closing the battle results. Gah!
Quote:
script
;
declare_counter loop
declare_counter clickAutoResolve
declare_counter DismissScroll
declare_counter declineDiplomaticOffer
set_counter loop 0
set_counter clickAutoResolve 0
set_counter DismissScroll 0
set_counter declineDiplomaticOffer 0
;
monitor_event FactionTurnStart FactionType romans_julii
console_command clear_messages
console_command control greek_cities
console_command add_money 40000
end_monitor
;
monitor_event FactionTurnStart FactionType greek_cities
console_command clear_messages
console_command control romans_julii
console_command add_money 40000
inc_counter loop 1
end_monitor
;
monitor_event PreBattlePanelOpen TrueCondition
set_counter clickAutoResolve 1
end_monitor
;
monitor_event NavalAutoResolvePanelOpen TrueCondition
set_counter clickAutoResolve 1
end_monitor
;
monitor_conditions I_CompareCounter clickAutoResolve = 1
set_counter clickAutoResolve 0
select_ui_element prebattle_auto_resolve_button
simulate_mouse_click lclick_down
simulate_mouse_click lclick_up
end_monitor
;
monitor_event ScrollOpened ConditionTrue
set_counter DismissScroll 1
end_monitor
;
monitor_conditions I_CompareCounter DismissScroll = 1
set_counter DismissScroll 0
select_ui_element confirm_quit_scroll
simulate_mouse_click lclick_down
simulate_mouse_click lclick_up
end_monitor
;
monitor_event DiplomacyPanelOpen TrueCondition
set_counter declineDiplomaticOffer 1
end_monitor
;
monitor_conditions I_CompareCounter declineDiplomaticOffer = 1
select_ui_element confirm_quit_scroll
simulate_mouse_click lclick_down
simulate_mouse_click lclick_up
end_monitor
;
while I_CompareCounter loop < 5
end_while
;
console_command control egypt
console_command clear messages
;
end_script
-
Re: Can I use a script to end the turn?
Sorry, I can't help you.:embarassed:
Even I don't understand why the game changes the turn simply by changing the faction controlled. :dizzy2:
I wonder if the factions involved in this system of changes make any movement and when.