-
An Intermediate Guide to Scripting
AN INTERMEDIATE GUIDE TO SCRIPTING
BACKGROUND SCRIPTS
By Epistolary Richard & Myrddraal
___________________________
In A Beginner Guide to Scripting we identified two different types of scripts: campaign scripts and show_me scripts, and went further to divide show_me scripts into event scripts and background scripts.
The Beginner Guide taught us the basics of using the event script – which is a script that runs only for a moment, making a change to the game world. These must be manually activated when their trigger event occurs.
This guide takes us a little deeper into the world of the background script – this is a script that is running constantly in the background of the game. It must be activated at the start of the game, and then manually reactivated each time the game is reloaded.
The Benefits of a Background script
There are two major limitations to the use of event scripts. The first is that it requires the player to click on the show_me button each and every time you want to make a change to the game environment.
The second, more importantly, is that the event script trigger can only ever be something that will happen in the player’s own turn. If it occurs outside of the player’s turn then the player will never get the chance to click on the show_me button as the advisor will appear and disappear during the AI turn.
This is why modders use background scripts as the main driver for their scripting features as they require the player only to make a single click each time the game is reloaded to run all their features and it gives them complete flexibility as to when and how their features are implemented.
In fact, the very first scripts that Myrddraal released – the Multiple Turns per Year script and the Hot Seat Beta script – were both background scripts.
In truth, every mod with significant scripting features will end up making use of all of the different types of script – background, event and campaign – as they all compliment each other.
What is a Background script?
As all show_me scripts, the background script is activated through the advisor. It must have all the components of a show_me script as listed in the Beginner Guide, namely trigger, advice thread and script.
The fundamental difference between an event script and a background script is that a background script is supposed to keep running and not terminate until the game is quit.
This is accomplished with the addition of a simple piece of code to the script – a While loop:
Code:
script
declare_counter loop
set_counter loop 0
; Insert your background script here
while I_CompareCounter loop = 0
end_while
end_script
Once activated, this script will never terminate as when it reaches the end_while it will loop back to the I_CompareCounter.
Now we have the script working all the time, however, we have to incorporate the triggers we want to use into the script itself, instead of the export_descr_advice file. To do that, we need to use new syntax:
Monitors, If statements and While loops
The monitor event/monitor conditions/if/while commands are very much like the triggers for advice threads.
Basically they are for checking conditions.
If statements
Like for example if you have a counter called no
Code:
script
declare_counter no
set_counter no 1
If I_CompareCounter no 1
Insert code here
end_if
end_script
What this will do is at the stage at which it reaches the If line, it will check counter no, if counter no is 1 then it will run the code, if not it will skip to the end_if.
While loops
A while loop will repeat itself whilst its conditions are true.
Code:
script
declare_counter no
set_counter no 0
While I_CompareCounter no = 0
Insert code here
end_while
end_script
When the script runs through, everytime it reaches and end_while, it will check the conditions, and if they are still true, it will jump back to the while statement. Basically looping that bit of code. In this example, the script will keep running forever, because the condition is that no is zero, and there is no code to stop this.
While monitors can be extreemly usefull for pausing the script until something happens.
Code:
While I_TurnNumber = 0
end_while
This will pause the script until the player ends the first turn (turn 0)
It can also be very helpfull if you do not want a script to end before a monitor is triggered. (see below)
Monitors
Condition monitors
Code:
script
declare_counter loop
set_counter loop 1
declare_counter no
set_counter no 0
monitor_conditions I_CompareCounter no = 1
Insert code here
terminate_monitor
end_monitor
campaign_wait 10
set_counter no 1
while I_CompareCounter loop = 1
end_while
end_script
The difference between a Monitor and an If statement is that the conditions for an if statement are checked when the if statement is reached, and not again. A monitor can be declared at the beginning of the script and will then be checked continuously.
In the example above, the monitor is declared, but the counter no is not 1. As soon as no changes to 1 (after waiting 10) the monitor is triggered and the code inside it is run.
Event monitors
Code:
script
declare_counter loop
set_counter loop 1
monitor_event buttonpressed buttonpressed end_turn TrueCondition
Insert code here
terminate_monitor
end_monitor
while I_CompareCounter loop = 1
end_while
end_script
An event monitor is basically a trigger using certain conditions. For example the pressing of a button. In this case, on the pressing of the end turn button, the code inside the monitor will be run.
The difference between terminate_monitor and end_monitor
With some monitors, you will see both terminate_monitor and end_monitor at the end. This basically determines whether the monitor can be triggered more than once. If you include both, the monitor can only be triggered once, then it cannot be used again. If you only include the end_monitor, then the monitor can be enabled several times.
And statements
And statments can be used with monitors, if statements and while loops. This is for multiple conditions. For example:
Code:
script
declare_counter noone
declare_counter notwo
declare_counter nothree
set_counter noone 1
set_counter notwo 1
set_counter nothree 1
monitor_conditions I_CompareCounter noone = 1
and I_CompareCounter notwo = 1
and I_CompareCounter nothree = 1
Insert code here
terminate_monitor
end_monitor
if I_CompareCounter noone = 1
and I_CompareCounter notwo = 1
and I_CompareCounter nothree = 1
Insert code here
end_if
end_script
A full list of events, conditions & commands can be found here:
https://forums.totalwar.org/vb/showthread.php?t=54299
Now, that’s all a lot to take in. So let’s try some examples:
More More Money
Here we give the player a little monetary boost each turn. It’ll happen automatically, no need for him to manually activate it.
For the event to trigger it, I’m going to choose FactionTurnStart and I want it only at the start of the player’s turn so I’m going to use the FactionIsLocal conditional.
Code:
script
declare_counter loop
set_counter loop 0
monitor_event FactionTurnStart FactionIsLocal
console_command add_money 100
end_monitor
while I_CompareCounter loop = 0
end_while
end_script
Now, at the beginning of each turn, the player’s treasury will increase by 100.
Simple enough. Let’s make it more complicated.
Here is a script that will make it considerably harder for a player to amass a huge treasury:
Code:
script
declare_counter loop
set_counter loop 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;; Creosote remover
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
monitor_event FactionTurnStart FactionIsLocal
and not LosingMoney
and Treasury > 10000
console_command add_money -1000
end_monitor
monitor_event FactionTurnStart FactionIsLocal
and not LosingMoney
and Treasury > 20000
console_command add_money -3000
end_monitor
monitor_event FactionTurnStart FactionIsLocal
and not LosingMoney
and Treasury > 30000
console_command add_money -6000
end_monitor
while I_CompareCounter loop = 0
end_while
end_script
At the beginning of each turn, the script will check the player’s treasury and then, if it above a certain amount and the player is not losing money, it will reduce it by the specified amount eg, 1,000 if it is above 10,000.
Note that all of these monitors will be triggered at the start of the player’s turn. Therefore if his treasury has gone higher than 30,000 he will not be docked 6,000 but 10,000 (1,000 + 3,000 + 6,000).
Here’s a very different script (from the late, unlamented Client Kingdoms 2 which will never be), one designed to give a non-player controlled faction a helping hand if things start going bad for them.
Code:
script
declare_counter loop
set_counter loop 0
monitor_event FactionTurnStart FactionType britons
and I_NumberOfSettlements britons < 4
and RandomPercent < 15
console_command create_unit Londinium "warband sword briton" 1
console_command create_unit Londinium "warband hurler briton" 1
console_command create_unit Eburacum "warband sword briton" 1
console_command create_unit Eburacum "warband hurler briton" 1
console_command create_unit Deva "warband sword briton" 1
console_command create_unit Deva "warband hurler briton" 1
end_monitor
while I_CompareCounter loop = 0
end_while
end_script
Let’s take it step by step, first of all, the initial event:
Code:
monitor_event FactionTurnStart FactionType Britons
and not FactionIsLocal
and I_NumberOfSettlements britons < 4
and RandomPercent < 26
Means that it will be triggered when:
1) At the start of the Britons turn
2) When the player is _not_ playing the Britons
3) When the number of settlements the Britons own is less than 4
4) And if the computer picks a random number between 1 and 25 – this means that even when all the other conditions are satisfied it will only happen on average 1 time in 4.
If all those conditions are satisfied, then the game will run the script within the monitor, creating the units within those settlements. The problem with it at present is that script will create the unit its told to, irrespective of whether it is the Britons or another faction who control that settlement, and assign it to that faction which controls the settlement. We therefore need to check to make sure we only create the unit in a settlement if the Britons control that settlement, for example:
Code:
if I_SettlementOwner Londinium = britons
console_command create_unit Londinium "warband sword briton" 1
console_command create_unit Londinium "warband hurler briton" 1
end_if
So our full script would look like the following:
Code:
script
declare_counter loop
set_counter loop 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;; britons in danger - Dads Army
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
monitor_event FactionTurnStart FactionType britons
and I_NumberOfSettlements britons < 4
and RandomPercent < 15
if I_SettlementOwner Londinium = britons
console_command create_unit Londinium "warband sword briton" 1
console_command create_unit Londinium "warband hurler briton" 1
end_if
if I_SettlementOwner Eburacum = britons
console_command create_unit Eburacum "warband sword briton" 1
console_command create_unit Eburacum "warband hurler briton" 1
end_if
if I_SettlementOwner Deva = britons
console_command create_unit Deva "warband sword briton" 1
console_command create_unit Deva "warband hurler briton" 1
end_if
end_monitor
while I_CompareCounter loop = 0
end_while
end_script
Triggers
We’re now beginning to understand what a background script is, however the script is only one of the three elements listed in the Beginner Guide – we also need an advice thread and, more importantly, a trigger. These are done in the same way as in the Beginner Guide, so rather than go through them again, I’ll just show you an example.
The F1 trigger
This is the trigger used by Myrddraal in the first scripts that he released. It’s great benefit is that the trigger is not activated by normal play, it is therefore ideal for testing purposes and mods where the player can be relied upon to follow the process each time.
It is, in fact the exact same trigger that was used in the Beginner Guide. But here it is again
This is the advice thread (NB, all this already exists, only the Script line has been added)
Code:
;------------------------------------------
AdviceThread Help_Campaign_Keyboard_Shortcuts_Scroll_Thread
GameArea Campaign
Item Help_Campaign_Keyboard_Shortcuts_Scroll_Text_01
Uninhibitable
Verbosity 0
Threshold 1
Attitude Normal
Presentation Default
Title Help_Campaign_Keyboard_Shortcuts_Scroll_Text_01_Title
Script scripts\show_me\background_script.txt ; This is the added line
Text Help_Campaign_Keyboard_Shortcuts_Scroll_Text_01_Text1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;------------------------------------------
Trigger 2137_Help_Campaign_Keyboard_Shortcuts_Scroll_Trigger
WhenToTest ScrollAdviceRequested
Condition ScrollAdviceRequested help_scroll
AdviceThread Help_Campaign_Keyboard_Shortcuts_Scroll_Thread 0
To activate your background script (placed in the data\scripts\show_me folder, of course), you must press F1 – then click on the ? – then the advisor should pop up and you can click on the Show Me How button at the beginning of the campaign and after each reload.
Now more and more mods are developing background scripts, scripters have been looking into ways to make activation and reactivated more user friendly. Eventually, once a certain number of mods have been released, I imagine that a community standard will develop as mod-users become accustomed with a specific method. More sophisticated triggers (and their consequences) will be the topic of the further portion of this guide which will be a series of modules focusing on various advanced scripting techniques to which all are invited to contribute.
Scripting links
CA's list of commands, events and conditions
Scripting research thread
Hot Seat Mod - Beta Release
More than two turns a year - release
-
Re: An Intermediate Guide to Scripting
You're a scripting god. Thanks very much!!!
-
Re: An Intermediate Guide to Scripting
Quick question Richard
With use of script would that be possible to spawn mercenary unit for hire only for non-Roman factions (playable and non playable one) for example "Roman deserters".Obviously such a unit would not be available for Romans.Is that at all possible ?
-
Re: An Intermediate Guide to Scripting
Yes, perfectly possible - but obviously not through the existing mercenary mechanism. Look at the Client Kingdoms mod for one way of doing it for the player. For non-player factions you would have to do it in a background script using a monitor_event with whatever conditionals you want and a create_unit console command inside.
-
Re: An Intermediate Guide to Scripting
a wonderful Thread...
I'm posting for very first time in this forum but i'm not reading in this section for first time...my english is not very good..please forgive me some grammar faults!
~:rolleyes:
A quick question:
has anybody checked the disable_ai console command if it works?
I would like to make a script that disable all the ai_actions and combine this with the faction switcher script! I have some problems with this matter because in the faction switcher script the ai make some stuff at the end of every turn...
i would like to execute this...
could it be that the command terminate_script? :stupido2:
here is the script:
HTML Code:
script
declare_counter player_faction
if I_LocalFaction romans_julii
set_counter player_faction 1
end_if
if I_LocalFaction macedon
set_counter player_faction 2
end_if
if I_LocalFaction egypt
set_counter player_faction 3
end_if
if I_LocalFaction seleucid
set_counter player_faction 4
end_if
if I_LocalFaction carthage
set_counter player_faction 5
end_if
if I_LocalFaction parthia
set_counter player_faction 6
end_if
if I_LocalFaction pontus
set_counter player_faction 7
end_if
if I_LocalFaction gauls
set_counter player_faction 8
end_if
if I_LocalFaction germans
set_counter player_faction 9
end_if
if I_LocalFaction britons
set_counter player_faction 10
end_if
if I_LocalFaction armenia
set_counter player_faction 11
end_if
if I_LocalFaction dacia
set_counter player_faction 12
end_if
if I_LocalFaction greek_cities
set_counter player_faction 13
end_if
if I_LocalFaction numidia
set_counter player_faction 14
end_if
if I_LocalFaction scythia
set_counter player_faction 15
end_if
if I_LocalFaction spain
set_counter player_faction 16
end_if
if I_LocalFaction thrace
set_counter player_faction 17
end_if
;---------------------------------------------
if I_CompareCounter player_faction = 1
console_command disable_ai thrace
end_if
if I_CompareCounter player_faction = 2
console_command disable_ai romans_julii
end_if
if I_CompareCounter player_faction = 3
console_command disable_ai egypt
end_if
if I_CompareCounter player_faction = 4
console_command disable_ai seleucid
end_if
if I_CompareCounter player_faction = 5
console_command disable_ai carthage
end_if
if I_CompareCounter player_faction = 6
console_command disable_ai parthia
end_if
if I_CompareCounter player_faction = 7
console_command disable_ai pontus
end_if
if I_CompareCounter player_faction = 8
console_command disable_ai gauls
end_if
if I_CompareCounter player_faction = 9
console_command disable_ai germans
end_if
if I_CompareCounter player_faction = 10
console_command disable_ai britons
end_if
if I_CompareCounter player_faction = 11
console_command disable_ai armenia
end_if
if I_CompareCounter player_faction = 12
console_command disable_ai dacia
end_if
if I_CompareCounter player_faction = 13
console_command disable_ai greek_cities
end_if
if I_CompareCounter player_faction = 14
console_command disable_ai numidia
end_if
if I_CompareCounter player_faction = 15
console_command disable_ai scythia
end_if
if I_CompareCounter player_faction = 16
console_command disable_ai spain
end_if
if I_CompareCounter player_faction = 17
console_command disable_ai thrace
end_if
;----------------------------------------------
console_command control slave
if I_LocalFaction romans_julii
console_command control macedon
terminate_script
end_if
if I_LocalFaction macedon
console_command control egypt
terminate_script
end_if
if I_LocalFaction egypt
console_command control seleucid
terminate_script
end_if
if I_LocalFaction seleucid
console_command control carthage
terminate_script
end_if
if I_LocalFaction carthage
console_command control parthia
terminate_script
end_if
if I_LocalFaction parthia
console_command control pontus
terminate_script
end_if
if I_LocalFaction pontus
console_command control gauls
terminate_script
end_if
if I_LocalFaction gauls
console_command control germans
terminate_script
end_if
if I_LocalFaction germans
console_command control britons
terminate_script
end_if
if I_LocalFaction britons
console_command control armenia
terminate_script
end_if
if I_LocalFaction armenia
console_command control dacia
terminate_script
end_if
if I_LocalFaction dacia
console_command control greek_cities
terminate_script
end_if
if I_LocalFaction greek_cities
console_command control numidia
terminate_script
end_if
if I_LocalFaction numidia
console_command control scythia
terminate_script
end_if
if I_LocalFaction scythia
console_command control spain
terminate_script
end_if
if I_LocalFaction spain
console_command control thrace
terminate_script
end_if
if I_LocalFaction thrace
console_command control romans_julii
terminate_script
end_if
end_script
-
Re: An Intermediate Guide to Scripting
Quote:
Originally Posted by Epistolary Richard
Yes, perfectly possible - but obviously not through the existing mercenary mechanism. Look at the
Client Kingdoms mod for one way of doing it for the player. For non-player factions you would have to do it in a background script using a monitor_event with whatever conditionals you want and a create_unit console command inside.
Thx for your reply Richard
Would something like this make any sens ?
HTML Code:
script
if I_SettlementOwner Tarsus =(probably list of all non roman factions or is that another way ?)
console_command create_unit Tarsus "merc roman deserters" 1
end_if
end_script
-
Re: An Intermediate Guide to Scripting
pilatus I remember Myrddraal saying something about the disable_ai command when putting together the Hot Seat Mod. He certainly used halt_ai for that.
Maly Jacek If that's an event script then you're better off putting the conditionals in the trigger. If that's a background script you need a loop to keep it running and a monitor event in there to tell the game when to check the conditionals.
-
Re: An Intermediate Guide to Scripting
thx richard
but i've already checked the halt_ai command in myrdaals script and there is the problem that you can't make all factions playable at yourself..only two of them...if you make more the script says good bye!
I've also already checked the set_ai off command but i think this is only for the battle_ai...
has nobody checked the disable_ai command ?
-
Re: An Intermediate Guide to Scripting
I put command line to export_descr_advise.txt, but when I press F1 and activate advisor, the <show me> button did not highlighted so I cannot click it to start scripts. What is wrong?
-
Re: An Intermediate Guide to Scripting
Did the correct advisor speech bubble appear? The Show Me How button doesn't become available until the speech bubble appears.
Post the advice thread that you added the script line to in export_descr_advice.
-
Re: An Intermediate Guide to Scripting
Richard
As I have got not experience whatsover in scripting I have copy edited your your script:
HTML Code:
script
declare_counter loop
set_counter loop 0
monitor_event FactionTurnStart FactionType sassanids
if I_SettlementOwner Dumatha = sassanids
console_command create_unit Dumatha "merc cata" 1
console_command create_unit Dumatha "merc veteranii" 1
end_if
if I_SettlementOwner Erewan = sassanids
console_command create_unit Erewan "elite cata" 1
end_if
terminate_monitor
end_monitor
while I_CompareCounter loop = 0
end_while
end_script
That works but despite press F1 button it only works once.When I remove terminate_monitor I get new units created on every turn.Could you kindly tell me what line needs to be change for the unit to be created only upon pressing F1.I guess that could be also way of having message appearing advising player he can get new units.Also is there a line that could replace "Sassanids" with something like "all except Romans"
-
Re: An Intermediate Guide to Scripting
Quote:
Originally Posted by dzsagon
I put command line to export_descr_advise.txt, but when I press F1 and activate advisor, the <show me> button did not highlighted so I cannot click it to start scripts. What is wrong?
I solved the problem. If a script has any syntax error, the <show me how> button did not highlighted, not allows to run a script. Now my scripts run, but not wery well:(
script
declare_counter state
set_counter state 0
declare_counter loop
set_counter loop 0
console_command add_money -100; just for test to scripts really runs
monitor_event FactionTurnStart FactionType Egypt
and FactionIsLocal
and FactionHasAllies
if DiplomaticStanceFromFaction pontus >= Hostile
set_counter state 1
console_command add_money 2000; just for test to scripts really runs
end_if
if DiplomaticStanceFromFaction pontus < Hostile
set_counter state 0
console_command add_money -2000; just for test to scripts really runs
end_if
end_monitor
monitor_event FactionTurnStart EgyptFactionType Numidia
and not FactionIsLocal
and DiplomaticStanceFromFaction pontus <= Hostile
and I_CompareCounter state = 1
console_command diplomatic_stance numidia pontus war
end_monitor
while I_CompareCounter loop = 0
end_while
end_script
My allies is Nubidia. If I declare war with pontus I want to Nubidia declares war to. But the script not doing this.
-
Re: An Intermediate Guide to Scripting
If that is a direct copy&paste from your script then this line is part of the problem:
Code:
monitor_event FactionTurnStart EgyptFactionType Numidia
Then, there are the if lines in the first monitor.
Code:
monitor_event FactionTurnStart FactionType Egypt
and FactionIsLocal
and FactionHasAllies
if DiplomaticStanceFromFaction pontus >= Hostile
DiplomaticStanceFromFaction requires exported parametres from a monitor, so it will no work if it is not tied to the monitor with ands. You'll have to split the monitor in two. This is how the other monitor should begin:
Code:
monitor_event FactionTurnStart FactionType Egypt
and FactionIsLocal
and FactionHasAllies
and DiplomaticStanceFromFaction pontus >= Hostile
As a rule of thumb, if a condition doesn't start with I_ it requires to be used as an event monitor condition.
-
Re: An Intermediate Guide to Scripting
Thanks a lot! It works now!
Another question. What is the proper command to give money to other fraction?
add_money <amount> <fraction name> not works.
-
Re: An Intermediate Guide to Scripting
From what other people have posted, you need a comma in there:
console_command add_money faction, how_much
-
Re: An Intermediate Guide to Scripting
Quote:
Originally Posted by Epistolary Richard
From what other people have posted, you need a comma in there:
console_command add_money faction, how_much
Thanks, it seems to be working.
-
Re: An Intermediate Guide to Scripting
HI!
I want to use move_character command , but I don't know how to calculate x,y koordinates of a position on campaign map. Is there a tool or method to do this?
-
Re: An Intermediate Guide to Scripting
Bring up the console on campaign map, place cursor over desired tile and type show_cursorstat, then press enter :)
-
Re: An Intermediate Guide to Scripting
If I use spawn and move command to not local faction with monitor_event, hothing happaned:
script
monitor_event FactionTurnStart FactionType romans_julii
and not FactionIsLocal
spawn_army
faction romans_julii
character Flavius Julius, general, command 0, influence 0, management 0, subterfuge 0, age 20, x 180, y 5
unit roman generals guard cavalry, soldiers 20 exp 9 armour 1 weapon_lvl 0
unit roman legionary first cohort ii, soldiers 40 exp 0 armour 0 weapon_lvl 0
unit roman legionary cohort ii, soldiers 60 exp 0 armour 0 weapon_lvl 0
unit roman praetorian cohort i, soldiers 60 exp 0 armour 0 weapon_lvl 0
end
console_command move_character Flavius Julius 170, 5
campaign_wait 1
console_command move_character Flavius Julius 160, 15
end_monitor
end_script
If I use it to not local faction without monitor_event spawn work, but no moves
If I use it to local faction spawn works, move works too.
-
Re: An Intermediate Guide to Scripting
Weird. Beats me why it doesn't work.
The only thing I can think of is that you were playing with the Julii when testing with not FactionIsLocal, but that wouldn't still explain why the moves didn't work..
-
Re: An Intermediate Guide to Scripting
Is there easiest way to check - me and my ally's- diplomatic stance for all other fractions? I am chartage, my ally is spain.
Quote:
script
declare_counter war0
set_counter war0 0
declare_counter war1
set_counter war1 0
declare_counter war2
set_counter war2 0
declare_counter war3
set_counter war3 0
declare_counter war4
set_counter war4 0
declare_counter war5
set_counter war5 0
declare_counter loop
set_counter loop 0
monitor_event FactionTurnStart FactionType carthage
and FactionIsLocal
and DiplomaticStanceFromFaction romans_brutii = AtWar
set_counter war0 1
end_monitor
monitor_event FactionTurnStart FactionType carthage
and FactionIsLocal
and DiplomaticStanceFromFaction romans_brutii <= Neutral
set_counter war0 0
end_monitor
monitor_event FactionTurnStart FactionType carthage
and FactionIsLocal
and DiplomaticStanceFromFaction romans_julii = AtWar
set_counter war1 1
end_monitor
monitor_event FactionTurnStart FactionType carthage
and FactionIsLocal
and DiplomaticStanceFromFaction romans_julii <= Neutral
set_counter war1 0
end_monitor
monitor_event FactionTurnStart FactionType carthage
and FactionIsLocal
and DiplomaticStanceFromFaction romans_scipii = AtWar
set_counter war2 1
end_monitor
monitor_event FactionTurnStart FactionType carthage
and FactionIsLocal
and DiplomaticStanceFromFaction romans_scipii <= Neutral
set_counter war2 0
end_monitor
monitor_event FactionTurnStart FactionType carthage
and FactionIsLocal
and DiplomaticStanceFromFaction gauls = AtWar
set_counter war3 1
end_monitor
monitor_event FactionTurnStart FactionType carthage
and FactionIsLocal
and DiplomaticStanceFromFaction gauls <= Neutral
set_counter war3 0
end_monitor
monitor_event FactionTurnStart FactionType carthage
and FactionIsLocal
and DiplomaticStanceFromFaction numidia = AtWar
set_counter war4 1
end_monitor
monitor_event FactionTurnStart FactionType carthage
and FactionIsLocal
and DiplomaticStanceFromFaction numidia <= Neutral
set_counter war4 0
end_monitor
monitor_event FactionTurnStart FactionType carthage
and FactionIsLocal
and DiplomaticStanceFromFaction greek_cities = AtWar
set_counter war5 1
end_monitor
monitor_event FactionTurnStart FactionType carthage
and FactionIsLocal
and DiplomaticStanceFromFaction greek_cities <= Neutral
set_counter war5 0
end_monitor
monitor_event FactionTurnStart FactionType spain
and not FactionIsLocal
and DiplomaticStanceFromFaction romans_brutii < AtWar
and DiplomaticStanceFromFaction carthage = Allied
and I_CompareCounter war0 = 1
console_command diplomatic_stance spain romans_brutii war
end_monitor
monitor_event FactionTurnStart FactionType spain
and not FactionIsLocal
and DiplomaticStanceFromFaction romans_julii < AtWar
and DiplomaticStanceFromFaction carthage = Allied
and I_CompareCounter war1 = 1
console_command diplomatic_stance spain romans_julii war
end_monitor
monitor_event FactionTurnStart FactionType spain
and not FactionIsLocal
and DiplomaticStanceFromFaction romans_scipii < AtWar
and DiplomaticStanceFromFaction carthage = Allied
and I_CompareCounter war2 = 1
console_command diplomatic_stance spain romans_scipii war
end_monitor
monitor_event FactionTurnStart FactionType spain
and not FactionIsLocal
and DiplomaticStanceFromFaction gauls < AtWar
and DiplomaticStanceFromFaction carthage = Allied
and I_CompareCounter war3 = 1
console_command diplomatic_stance spain gauls war
end_monitor
monitor_event FactionTurnStart FactionType spain
and not FactionIsLocal
and DiplomaticStanceFromFaction numidia < AtWar
and DiplomaticStanceFromFaction carthage = Allied
and I_CompareCounter war4 = 1
console_command diplomatic_stance spain numidia war
end_monitor
monitor_event FactionTurnStart FactionType spain
and not FactionIsLocal
and DiplomaticStanceFromFaction greek_cities < AtWar
and DiplomaticStanceFromFaction carthage = Allied
and I_CompareCounter war5 = 1
console_command diplomatic_stance spain greek_cities war
end_monitor
while I_CompareCounter loop = 0
end_while
end_script
-
Re: An Intermediate Guide to Scripting
You probably have the easiest way right there in your hands. If you don't need to check for specific factions there are a couple of conditions (OnWarFooting or similar), but for specific factions there's really no way around it. If you start doing these kind of repetitive scripts you should learn how to do script generators, with php, C++, excel or similar.
-
Re: An Intermediate Guide to Scripting
-
Re: An Intermediate Guide to Scripting
is it possible to have nested loops, if-statements and so on? could be a time saver in-game
pseudo-code:
Code:
if 1
if 2
[do something]
end if ; 2
if 3
[do something]
end if ; 3
while [something]
[do something]
end while
end if ; 1
edit: I just realized it is ~D
another thing, for it to be a background script you have to add
Code:
while I_CompareCounter loop = 0
end_while
won't it go faster if you have
Code:
while I_CompareCounter loop = 0
campaign_wait 1
end_while
?
-
Re: An Intermediate Guide to Scripting
Quote:
won't it go faster if you have
while I_CompareCounter loop = 0
campaign_wait 1
end_while?
Well I don't think it would be noticable to be honest, but in theory yes :smile:
-
Re: An Intermediate Guide to Scripting
Is there a way to script senate-like missions?
-
Re: An Intermediate Guide to Scripting
Quote:
Originally Posted by Spitful
Is there a way to script senate-like missions?
I tried something like that some time ago.
https://forums.totalwar.org/vb/showt...without+senate
One of the possible problems is to link the end of one mission with the beginning of the following one, and the method to test if that mission is feasible or not (for example if the corresponding region is still rebel, or it is owned by your own faction).
Any advance will be welcome.
-
Re: An Intermediate Guide to Scripting
Im just going to spawn a building in different provinces on the far reaches of the map to show which mission they are on, then use a monitor that will produce the appropriate mission when the building is spawned on completion of the previous mission, preventing old missions from running again.
Is there a way of counting how many turns have passed since a randomly generated event took place?
What about
and I_SettlementOwner <> Romans_Julii
?
-
Re: An Intermediate Guide to Scripting
Quote:
What about
and I_SettlementOwner <> Romans_Julii
and not I_SettlementOwner = Romans_Julii
or possibly and I_SettlementOwner != Romans_Julii
Nice thread ER. I just noticed it. :laugh4:
I guess i have to come out of EB hole more often.
-
Re: An Intermediate Guide to Scripting
Myrddraal worked out all the technical stuff, I just do the talking sloooowly with hand gestures bit. :bow:
But yes! Let us have some advanced scripting tutorials about the scripting in EB!