PDA

View Full Version : An Intermediate Guide to Scripting



Epistolary Richard
11-16-2005, 01:25
AN INTERMEDIATE GUIDE TO SCRIPTING
BACKGROUND SCRIPTS

By Epistolary Richard & Myrddraal
___________________________


In A Beginner Guide to Scripting (https://forums.totalwar.org/vb/showthread.php?t=46738) 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:


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


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.


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.


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

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

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:


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.


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:

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.

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:

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:

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:


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)

;------------------------------------------
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 (https://forums.totalwar.org/vb/showthread.php?t=54299)
Scripting research thread (https://forums.totalwar.org/vb/showthread.php?t=40178)
Hot Seat Mod - Beta Release (https://forums.totalwar.org/vb/showthread.php?t=45563&page=1)
More than two turns a year - release (https://forums.totalwar.org/vb/showthread.php?t=44648)

edyzmedieval
11-16-2005, 20:49
You're a scripting god. Thanks very much!!!

Hans Kloss
11-27-2005, 18:32
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 ?

Epistolary Richard
11-28-2005, 11:46
Yes, perfectly possible - but obviously not through the existing mercenary mechanism. Look at the Client Kingdoms (https://forums.totalwar.org/vb/showthread.php?t=46728) 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.

pilatus
11-28-2005, 21:51
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:

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

Hans Kloss
11-28-2005, 22:43
Yes, perfectly possible - but obviously not through the existing mercenary mechanism. Look at the Client Kingdoms (https://forums.totalwar.org/vb/showthread.php?t=46728) 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 ?


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

Epistolary Richard
11-29-2005, 02:51
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.

pilatus
11-29-2005, 18:01
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 ?

dzsagon
11-30-2005, 17:02
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?

Epistolary Richard
11-30-2005, 18:11
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.

Hans Kloss
11-30-2005, 18:40
Richard
As I have got not experience whatsover in scripting I have copy edited your your script:


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"

dzsagon
11-30-2005, 22:25
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.

The_Mark
11-30-2005, 22:43
If that is a direct copy&paste from your script then this line is part of the problem:

monitor_event FactionTurnStart EgyptFactionType Numidia

Then, there are the if lines in the first monitor.

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:

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.

dzsagon
12-01-2005, 00:28
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.

Epistolary Richard
12-01-2005, 14:35
From what other people have posted, you need a comma in there:

console_command add_money faction, how_much

dzsagon
12-01-2005, 19:01
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.

dzsagon
12-02-2005, 11:09
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?

The_Mark
12-02-2005, 14:40
Bring up the console on campaign map, place cursor over desired tile and type show_cursorstat, then press enter :)

dzsagon
12-02-2005, 19:41
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.

The_Mark
12-03-2005, 21:05
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..

dzsagon
12-06-2005, 09:45
Is there easiest way to check - me and my ally's- diplomatic stance for all other fractions? I am chartage, my ally is spain.


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

The_Mark
12-06-2005, 11:43
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.

SigniferOne
12-16-2005, 23:11
Great thread ER :)

ScionTheWorm
12-31-2005, 01:09
is it possible to have nested loops, if-statements and so on? could be a time saver in-game

pseudo-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


while I_CompareCounter loop = 0
end_while


won't it go faster if you have


while I_CompareCounter loop = 0
campaign_wait 1
end_while

?

Myrddraal
01-13-2006, 19:31
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:

Spitful
01-14-2006, 20:46
Is there a way to script senate-like missions?

Monkwarrior
01-15-2006, 00:34
Is there a way to script senate-like missions?
I tried something like that some time ago.
https://forums.totalwar.org/vb/showthread.php?t=49150&highlight=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.

Spitful
01-15-2006, 01:25
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
?

LorDBulA
01-18-2006, 22:50
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.

Epistolary Richard
01-19-2006, 00:50
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!

Malrubius
01-20-2006, 06:53
I'm going to need some, to keep up with you, LorDBulA, and The_Mark!

SigniferOne
02-05-2006, 05:51
Question guys, which I feel is a little silly but here it is nonetheless: how do you test if a character has a certain trait, and what level of the trait? I tried the following and it doesn't work:



monitor_event CharacterTurnStart TrueCondition
if FactionType empire_west
if Trait AgeTraitLevel1 = 1
; do some stuff
end_if
end_if
end_monitor

Malrubius
02-05-2006, 13:23
monitor_event CharacterTurnStart FactionType empire_west
and Trait AgeTraitLevel1 = 1
; do some stuff

end_monitor

SigniferOne
02-05-2006, 20:30
Hmm, that's weird, I thought both "FactionType" and "Trait" were conditions, and thus not usable in monitor_event, but only in monitor_conditions, or "if" clauses?

Malrubius
02-06-2006, 13:33
Hmm, we have syntax like that in our EBBS background script, and it seems to work.

alpaca
02-06-2006, 17:59
That is because monitor_event in fact requires an event AND a condition.
If you don't want one, you have to use monitor_event EVENT TrueCondition or else the game will crash.

SigniferOne
02-07-2006, 06:11
Right, but then what could be the reason why isolating the conditions into their own "if" statements, e.g in my code above, doesn't work?

Epistolary Richard
02-09-2006, 01:55
Because most conditionals require exports from an event (eg, settlement, character) - and therefore need to be included in a monitor_event. It's only conditionals that start with I_ that do not require an event which can be used in if and monitor_conditions.

Duke John
02-22-2006, 08:02
While experimenting with scripts I noticed that some AdviceThreads in export_descr_advice.txt have a parameter. I found SettlementName and CharacterName. Not useful for me, but I guess some can use it to make their Advisor texts a little bit more detailed, showing the settlement's or character's name.

paullus
03-04-2006, 03:38
Is there a way to make the background script detect whether an AI faction has done something, and then have that trigger an event script at the start of the player's turn?

Epistolary Richard
03-04-2006, 18:53
Depends on what the AI faction has done. What AI event do you want to trigger it?

HalfThere
03-04-2006, 19:19
Which of the following events would be detectable for an AI nation?
Takes a (particular) city.
Declares war/peace with another nation.
Accumulates X amount of money.
Family member (specifically faction leader) dies.
Family member accumulates X command stars.

LorDBulA
03-04-2006, 19:43
These should be possible.
Just open beginer screepting guide and dive in into RTW script documentation.

paullus
03-04-2006, 23:05
Depends on what the AI faction has done. What AI event do you want to trigger it?

Beseiging a city would probably be best.

Epistolary Richard
03-05-2006, 10:31
Besieging a city's tricky, you can put a conditional in for a monitor to fire if an enemy family member is within one tile of a certain location and if the two factions are at war.

Gets a bit cumbersome with large numbers of factions and cities, but it's possible.

LorDBulA does something similar with his Roma siege script, have a look at his code:
http://www.twcenter.net/forums/showthread.php?t=24968

You can use something like that to increment a counter and then have a separate monitor_event FactionTurnStart FactionIsLocal with an I_CompareCounter condition. Be sure to set the counter back to 0 though, otherwise it will keep triggering.

Tittils
03-05-2006, 22:16
This is a quite similar question, but I hope it can be done:

Is it possible to make an army (or naval army) besiege a city/port at game start through a script? I'm not very familiar with scrpits, so I hope someone could help me with this one.

- Tittils -

paullus
03-07-2006, 23:42
ER,

Sorry I was unclear. I meant to say "besieging a neutral city." Unless I'm missing something (certainly a possibility), I don't think those conditions would work with a city you do not own. Is there anything else I could try?

Thanks much.

LorDBulA
03-08-2006, 09:36
As it was said there is no easy way to check for siege.
The only way is to detect enemy army near a settlement.
You can do this for any faction holding city and any faction standing next to the city.
Proximity alert should be set to 2 titles. If you set it to 1 it wont be triggered if enemy attacks from any of city corners.

paullus
03-08-2006, 15:10
Oh ok, I guess I misunderstood. Thanks.

SigniferOne
03-10-2006, 04:52
I don't understand, I'm using Malrubius' code:


monitor_event CharacterTurnStart FactionType empire_west
and Trait AgeTraitLevel1 = 1
; do some stuff

end_monitor
To do something to the character when a turn starts, but nothing happens. Here's the full code:



console_command give_trait "Gaius Fabricius" GoodCommander 2
campaign_wait 2
console_command add_money 1000
campaign_wait 2

monitor_event CharacterTurnStart FactionType empire_west
and Trait GoodCommander = 2

; do stuff

end_monitor

I start the campaign, press F1 and run the script, the Trait is added, I press Next Turn expecting some stuff to happen to the char based on that trait, but nothing happens... Help?

PS: ER, would you like me to use the other thread referencing this one from now on?

Epistolary Richard
03-11-2006, 00:12
Is that the full script? Do you have 'script' at the beginning? end_script at the end? Do you have a loop so that the script is still running the next turn?

If you have all that try getting rid of the campaign_wait commands.

SigniferOne
03-11-2006, 02:47
Do you have a loop so that the script is still running the next turn?
Maybe that's my problem. I was under the assumption that if a script was launched, that it will persist throughout the entire game session, including all the monitors. Is that right, or do I have to have some sort of loop to keep the script persisting through the turns?

All of the action that I want to happen above is inside the monitor, which I thought will persist though turn 2, even though loaded at turn 1 (assuming the game wasn't reloaded).

Epistolary Richard
03-11-2006, 03:29
Have a look at the first script in the first post, there's your basic background script with a while loop. You need a while loop at the bottom otherwise the script will terminate immediately.

LorDBulA
03-11-2006, 10:28
When script execution reaches end_script command you can guess what happens next :)

SigniferOne
03-12-2006, 06:54
I think I figured out what was going wrong:

inside that event monitor I have two commands:



console_command add_money 10000
campaign_wait 2
console_command kill_character "Gaius Fabricius"
campaign_wait 2


(the campaign waits are apparently necessary for all console_commands).

Ok so here's what happens: apparently, under some conditions, the kill_character command does-not-work, and the script processing engine seems to stop processing. What's been happening in my script, and why I was prompted to post in this thread, was that I've been developing a background script for the Paeninsula Italica mod; I tried inserting just one command that had to be in my script -- kill_character -- and it would not work (hence my posts). I started this script every time I started a new campaign in our beta campaign map, so obviously we have a lot of things unbalanced yet, and a lot of provinces (over 50) rebel on the next turn. Also, the Adoption thing springs into action, since there are like 3 generals for the entire faction.

SO -- to make a long story short -- when I start the campaign and run my script, after pressing next turn, all this massive avalanche of events starts to happen on the next turn, and the kill_character event does not work. It is in the monitor correctly, and the monitor is triggered correctly, but the command simply doesn't work! How do I know the monitor is triggered correctly? Because I placed the give money command before it, which never fails to work. And what's even more, I placed a second give money command after it, e.g.



console_command add_money 10000
campaign_wait 2
console_command kill_character "Gaius Fabricius"
campaign_wait 2
console_command add_money 10000
campaign_wait 2


And the execution never reaches the second money command, and no money is added after the first. This is a very weird problem. Here's what's even weirder: sometimes, if I keep pressing Next Turn, the event_monitor is still apparently running in the background, sometimes will make the kill_character command work. So sometimes, a few turns in, the character does get killed (although the money command works always, at least the first one).

It seems that the script engine somehow gets "stuck" on the kill_character command, and simply does not proceed executing any further. I thought that maybe it's from all the events happening so fast, and tried to somehow pause the game, or at least pause all the events and UI things happening, until my script monitor runs and finishes its stuff. Thus, I tried everything imaginable, e.g.:


monitor_event FactionTurnStart FactionIsLocal
declare_show_me
hide_ui
suspend_unscripted_advice true
disable_entire_ui

console_command add_money 10000
campaign_wait 5
console_command kill_character "Gaius Fabricius"
campaign_wait 5
console_command add_money 10000
campaign_wait 5

enable_entire_ui
suspend_unscripted_advice false
show_ui
end_monitor

all the things that I guessed could suspend the proper flow of the game until my poor script has finished. None of these things work. One of the funny things is, I just added the "hide_ui" thing, to try and hide the events until my script finishes, and -- the UI gets hidden, the "adoption" event pops up anyway (due to the conditions in my campaign), and when I dismiss it, the UI continues to remain hidden. The script simply does not proceed further, beyond the kill_character command, the UI remains hidden even though the script says to unhide it. It just gets stuck. And I know that the kill_character command works always when in direct script mode (i.e. without the monitors), and it sometimes works even in the monitors, seemingly when there aren't that many events popping up. So that's what's been going on with my script :-) Anyone else have something similar?

SigniferOne
03-12-2006, 08:30
Okay guys, in order to narrow down the source of the problem, I have considerably cleaned up the campaign situation, gave the faction enough generals so that adoptions would not pop up, removed almost all the provinces owned so that there are would be no rebellions, etc. Now, practically no events happen on each turn, and yet the problem with kill_character still persists!

I don't want to clutter up ER's thread with this one problem, so I've started a new thread, where I explain the situation in less clumsy terms, the above complications have been removed as I just said, and I also posted screenshots of what goes on.

The thread is here: https://forums.totalwar.org/vb/showthread.php?t=62364

SigniferOne
03-12-2006, 21:18
A few more questions: the only way to browse if a character has one of a list of traits is by having a monitor event for each trait, right? i.e. there's no way to do something like right:

if Trait X = 1
do A
if Trait Y = 1
do B

Also, is there a limit for how many "and" conditions can exist for event_monitors? This sort of information seems not to be included in the Hardcoded Limits thread.

Epistolary Richard
03-12-2006, 22:10
I think that's because no one has ever hit it. From my understanding of CA it seems unlikely that they would have imposed a limit because they never expected people to be using big scripts. But equally there may be an extent by which a big monitor may not work right.

There's no easy way to do the trait thing - however if you want to use that in many different monitors then you may want to have a separate monitor to use the existence to set a counter. You can then use an if I_CompareCounter line within your monitors.

Monkwarrior
03-19-2006, 17:28
I've found problems in making the command test_message working:
https://forums.totalwar.org/vb/showpost.php?p=1095565&postcount=8

Any of the experts in scripting could give me the tip?:help:

Piko
04-29-2006, 10:09
Can someone supply me with a code for changing diplomacy between factions? Thanks.

Stuie
04-29-2006, 12:40
diplomatic_stance
Availability: campaign
Usage: diplomatic_stance <faction_a> <faction_b> <allied/neutral/war>:
Set the diplomatic stance between the two factions

So the usage in a script would look like this:


console_command diplomatic_stance romans_brutii parthia neutral
console_command diplomatic_stance romans_julii parthia neutral
console_command diplomatic_stance romans_scipii parthia neutral
console_command diplomatic_stance romans_senate parthia neutral


That makes all the roman factions "Neutral" toward Parthia, whether they were are war or allied. Note that only allied, neutral and war are available - there does not appear to be a way to force protectorates (I only mention this since that's what people usually seem to be looking for).

Piko
04-29-2006, 19:12
Thanks, that was easier than I thought it was.
(BTW I'm Piko on the RTR forums, that was the only thing I wasn't able to locate in your TFT files, thanks again!)

Yet another question, can you force ownership?

Spitful
04-30-2006, 18:36
Can you count how many battles the player has fought in the campaign so far?

Atilius
04-30-2006, 19:47
Is this what you're looking for? It doesn't actually return a number unfortunately.


---------------------------------------------------
Identifier: BattlesFought
Trigger requirements: faction
Parameters: logic token, quantity
Sample use: BattlesFought = 6
Description: How many battles has the player fought so far during this campaign?
Battle or Strat: Either
Class: BATTLES_FOUGHT
Implemented: Yes
Author: Guy
---------------------------------------------------

Spitful
04-30-2006, 20:06
What do you mean?
Does it work for IF and WHILE statements?

Epistolary Richard
04-30-2006, 20:29
Nope, it has an import - the only conditions that work with if and while statements are prefixed with I_

Piko
05-01-2006, 23:42
Can you force ownership of a city? If so can I have the code please?

alpaca
05-03-2006, 16:46
console_command take_settlement i think, take a look at the docudemon

Stuie
05-03-2006, 19:58
Can you force ownership of a city? If so can I have the code please?

Hey Piko-

As an example, on turn #100 at the start of the Julii turn, this will give the Senate control of Antioch and then create two units of Hastati in Antioch.


monitor_event FactionTurnStart FactionType romans_julii
and I_TurnNumber = 100

console_command control romans_senate
console_command capture_settlement Antioch
console_command create_unit Antioch "roman hastati" 2
console_command control romans_julii

terminate_monitor
end_monitor

This assumes the player is playing romans_julii. If not, the code gets more complicated because you'll need some sort of variable to return control of the correct faction to the player.

Legatus_Legionis
05-04-2006, 12:18
Hi all!

I have a question about assassination and whether it's possible to script it?

My idea involes the assassination a faction leader that i don't know the name of i.e a spawned character, has anyone tried this?

Cheers!

Epistolary Richard
05-04-2006, 19:25
To my knowledge, no one's had any luck in scripting agent missions. The kill_character command, which could be used instead, as you say needs to know the character's name.

Piko
05-04-2006, 19:49
Hey Piko-

As an example, on turn #100 at the start of the Julii turn, this will give the Senate control of Antioch and then create two units of Hastati in Antioch.


monitor_event FactionTurnStart FactionType romans_julii
and I_TurnNumber = 100

console_command control romans_senate
console_command capture_settlement Antioch
console_command create_unit Antioch "roman hastati" 2
console_command control romans_julii

terminate_monitor
end_monitor

This assumes the player is playing romans_julii. If not, the code gets more complicated because you'll need some sort of variable to return control of the correct faction to the player.
Thanks, I needed this for RTR: under the eagle, hereby promoting it, please visit us at: http://forums.rometotalrealism.org/index.php?showforum=157 . We're only just starting out but I'm sure this information's all going to help.

Legatus_Legionis
05-04-2006, 22:03
To my knowledge, no one's had any luck in scripting agent missions. The kill_character command, which could be used instead, as you say needs to know the character's name.

Ah, oh well - back to the drawing board. Thank you anyway.

Ciaran
05-07-2006, 13:01
So the usage in a script would look like this:


console_command diplomatic_stance romans_brutii parthia neutral
console_command diplomatic_stance romans_julii parthia neutral
console_command diplomatic_stance romans_scipii parthia neutral
console_command diplomatic_stance romans_senate parthia neutral


That makes all the roman factions "Neutral" toward Parthia, whether they were are war or allied. Note that only allied, neutral and war are available - there does not appear to be a way to force protectorates (I only mention this since that's what people usually seem to be looking for).

I wonder, is there a way to detect the event of one faction becoming a protectorate?
If so, there might be a way to work around the annoying alliance issue with protectorates (You can´t attack allies of your protectorate without losing the protectorate), simply by setting the relations of the protectorate to all other factions to neutral.

Epistolary Richard
05-07-2006, 17:11
No, there's no way that I'm aware of to detect the existence or creation of a protectorate. :sad:

Piko
05-10-2006, 23:48
Here I have learned how to script changing a city's ownership, but now I wish to change a family_members ownership, ex. G M from romans_julii to romans_brutii. I know his name.

Stuie
05-11-2006, 04:00
Here I have learned how to script changing a city's ownership, but now I wish to change a family_members ownership, ex. G M from romans_julii to romans_brutii. I know his name.

As far as I know, you will need to kill_character him from the original faction and then spawn him in the new faction. No other way to force a change of allegiance that I know of.

Piko
05-11-2006, 19:41
Well maybe trigger rebelling in BI? Is that possible? Where are these docudemon files BTW?

Epistolary Richard
05-11-2006, 20:11
No, as far I know there's no change allegiance command.

The docudemon files are linked in the first post of this topic. They can be found here:
https://forums.totalwar.org/vb/showthread.php?t=54299

Stuie
05-11-2006, 20:29
Well maybe trigger rebelling in BI? Is that possible? Where are these docudemon files BTW?

If you're using loyalty in BI, you could always give the character a huge negative to loyalty using a trait. I haven't messed around much with loyalty though, so I'm not so sure how predictable it is.

Piko
05-13-2006, 09:55
Thanks for the replies, it sucks you have to kill the character though, makes scripting Roman civil war MUCH harder...

Stuie
05-18-2006, 19:01
Has anyone found a way to script a keystroke? For instance, making the game peform a quick save in the script by having "Ctrl-S" invoked? I know there are ways to get UI elements activatedd, but I'm specifically trying to do something that has a shortcut, but no UI element. Probably not possible but I thought I'd ask.

Myrddraal
05-19-2006, 13:30
Shortcuts can be called using a scripting command. I made a post about it somewhere, I'll see if I can dig it up. :bow:

Myrddraal
05-19-2006, 13:42
here is a neat scripting command which I found whilst working on the MP campaign:

call_object_shortcut

Here is an example of the syntax:

call_object_shortcut strat_ui speedup_ai

the strat_ui bit is the category of the shortcut. If you open data\text\descr_shortcuts.txt and scroll to the bottom end, you'll find a list of the shortcuts with their categories to the right.
...

Stuie
05-19-2006, 15:46
Ok - I thought I tried that and it didn't work. Guess I'll try again.

Edit: Forgot my manners! Thanks for the quick response!
Edit2: Looks like I had the wrong category for the shortcut I was trying to invoke. I'll test the new one when I get home...

Myrddraal
05-19-2006, 17:20
Were you trying the save game one?

I use it in the mp campaign script and it works.

Stuie
05-19-2006, 17:57
Were you trying the save game one?

I use it in the mp campaign script and it works.

No - something else. If/when I get it to work I'll report back. ~:)

Monkwarrior
05-22-2006, 11:43
Hi to all the scripters.

I've been "fighting" against some script commands, and I've revised the old thread about commands working or not working (or not tested).

As that thread was hidden in the ancient times (last year :laugh4: ), I prefer to post here my doubts and commments, and perhaps somebody could update the list.:book:

suspend_unscripted_advice true
I thought that this command disables all the advices, except those launched in the script.
If so, then I'm doing something wrong, as I put this at the beginning of the script and I receive advices about ships, armies and so on.
I'm studying the scripts from other mods and in one case (I don't remember if it was TFT) this command was repeated in all the turns of the 4tpy script.
As I'm not using 4tpy, I need a loop to keep the script monitoring events and conditions. Thus the structure of the script is this:


script
suspend_unscripted_advice true
while I_TurnNumber < 500
here the whole script
end_while
terminate_script

Should I include the suspend_unscripted advice inside the loop? I think I did it, but the advices keep on being launched.
Should I put some repetition for this command in every turn? I'm thinking in something like this:


monitor_event FactionTurnStart FactionType carthage
and I_TurnNumber < 500
suspend_unscripted_advice true
terminate_monitor

select_ui_element
I'm trying that the scripted advices will be shown directly. For this purpose I tried this structure:


advance_advice_thread MyNewAdvice_Thread no_dismiss
select_ui_element advisor_portrait_button
simulate_mouse_click lclick_down
simulate_mouse_click lclick_up
But I must click on the portrait manually.
Is the ui_element advisor_portrait_button wrong? I think I saw it in some list of ui elements.

test_message
This is the most intriguing problem for me. I've been trying to launch different types of message, such as historic events, wonder captured, civil war... with no success.
Just in case it was a problem of the conditions or event, I tried to launch it at the start and the end of the faction turn, at the start and the end of a character turn, but no way.
And all those conditions or events were functional for other commands such as advices, creation of buildings or training of units.
If the campaign must fullfil the requirements for the event, then the command test_message is useless.
What am I doing wrong?

senate_mission
About the possible update of the list of working commands, I tried several of them related with senate missions:

senate_mission_help_player (with money or units)
senate_mission_declare_war
senate_mission_take_cityThe three are working, with some limitations: only for roman factions as LocalFaction, and the mission is not authomatically assigned, only the message appears.

Cheers.

Myrddraal
05-24-2006, 14:43
select_ui_element
I'm trying that the scripted advices will be shown directly. For this purpose I tried this structure:

... ...

But I must click on the portrait manually.
Is the ui_element advisor_portrait_button wrong? I think I saw it in some list of ui elements.

I used this once after automatically running a show me script at the start of a campaign, I wanted to dismiss the advisor. Only problem is I can't remember if it worked or not...

blacksnail
05-26-2006, 07:04
I can't find this anywhere else so I'll ask here.

Say there's a building in a settlement and I want the script to open the building info scroll for that particular building (ie, the equivalent of "right-clicking" the building in the city scroll). How would I go about this? IE, assume I have the "if building X exists in settlement Y" setup correct, what command could I use to open the scroll for that particular building?

Stuie
06-04-2006, 04:05
No - something else. If/when I get it to work I'll report back. ~:)


Coming back to this now that the most current beta version of TFT is public, I figured out how to *mostly* force automerge units - I'm sure people will find work-arounds but whatever.

Here's the code - obviously needed for every faction playable:


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;; AUTOMERGE UNITS CODE ;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

monitor_event CharacterSelected FactionType romans_brutii
and FactionIsLocal
call_object_shortcut campaign_hud automerge_units
end_monitor

monitor_event SettlementSelected FactionType romans_brutii
and FactionIsLocal
call_object_shortcut campaign_hud automerge_units
end_monitor

monitor_event CharacterSelected FactionType gauls
and FactionIsLocal
call_object_shortcut campaign_hud automerge_units
end_monitor

monitor_event SettlementSelected FactionType gauls
and FactionIsLocal
call_object_shortcut campaign_hud automerge_units
end_monitor

etc.

Galloper
06-16-2006, 20:56
Hi!
I'm trying make a script to reduce settlement population.
Here best what I can do:wall:

script
declare_counter loop
set_counter loop 1
monitor_conditions Carthago SettlementPopulationMaxedOut
if Carthago SettlementPopulationMaxedOut
console_command add_population Carthago -7000
end_if
end_monitor
while I_CompareCounter loop = 1
end_while
end_script

With this Carthago population decreased from 30000 to 400 men, and growth bonus become 12,5%, but on the next turn there are no growth bonus at all. Population freezes on mark with 400 man. :oops:
Can someone tell me what should I do if I need that population checks and reduced only if it's more then 24000,and it happened after turn end :help:

Sorry for my bad english.

Hans Kloss
08-04-2006, 14:12
We have been trying to script sacking Rome by Alaric's troops in 410 AD for new version of IBFD mod



monitor_event FactionTurnStart FactionType goths
and I_TurnNumber = 1
console_command sack_settlement Rome
console_command add_money 10000
terminate_monitor
end_monitor

monitor_event FactionTurnStart empire_west
and I_TurnNumber = 2
console_command capture_settlement Rome
console_command create_unit Rome comitatenses 2 2 1 1
terminate_monitor
end_monitor

I understand line "monitor_event FactionTurnStart empire_west" is incorrect and should be replaced to get script working for AI factions and I would very much appreciate if someone could suggest possible solution

Hans Kloss
08-07-2006, 18:30
anyone?

gruppo3g
08-15-2006, 13:39
Hi,

it's possible to use a script for this:

- Simulate every year a migration from little city to big city/capital in order to give a legion/horde/army recruitement possible only in determined settlement (with particolar recruit's buildind)

- the same above but only if requested by the player (like the legio raise from Res Gestae mod Script)

- Simulate the Romanization (or others culture assimilation) by using Loyalty/Religion setting of every city? so we can trigger to add a Roman Citizenship building when we get a >=50% of loyalty/romanized civilian and this building can make possible different recuit sistem..

- import the Horde army mechanism from BI to RTW 1.5 and modify it to simulate a "Legion recuitment calling" that minus the people from near city in order to get the coscrict legionaire?

Sorry 4 my bad english.. :book: i'm from Italy

VirtualWolf
09-01-2006, 14:28
Just a quick note to say thankyou for your guides I am new to modding and they have been invaluable... A great Help .. and because of your writing style I found them easy to understand...

Psyco
01-16-2007, 06:24
I'm new to scripting, so bear with me.

I want a script that gives the other factions (non player) money every turn, extra depending on the state of their economy.

Would this work? (I'm having troubles getting mods to work at the moment, so I cant test it)


script
declare_counter loop
set_counter loop 0

monitor_event FactionTurnStart
and not FactionIsLocal

console_command add_money 2000

end_monitor

monitor_event FactionTurnStart
and not FactionIsLocal
and Treasury < 2000

console_command add_money 2000

end monitor

monitor_event FactionTurnStart
and not FactionIsLocal
and Treasury < 5000

console_command add_money 2000

end monitor

while I_CompareCounter loop = 0
end_while
end_script


Thanks

Atilius
01-16-2007, 06:47
Your script won't work as you intend. When no faction is specified, the add_money console command puts the specified funds in the player's treasury.

You need to repeat each of your monitors for every faction and specify the faction name in the add_money console command:



monitor_event FactionTurnStart FactionType seleucid
and not FactionIsLocal

console_command add_money seleucid, 2000

end_monitor

monitor_event FactionTurnStart FactionType spain
and not FactionIsLocal

console_command add_money spain, 2000

end_monitor

...(et cetera)



This need for duplication is responsible for the EB background script running to over 165,000 lines of code.

Psyco
01-17-2007, 03:29
Thanks for the help.

Is there any list that shows which versions of the names I should be using? I would assume the ones at the top of descr_strat.txt, but it never hurts to ask.

I'm doing this for Medieval II, but I've heard the architecture is nearly identical, so it shouldn't matter.

Atilius
01-17-2007, 04:41
... which versions of the names I should be using? I would assume the ones at the top of descr_strat.txt...

Yes, that's right. M2TW has the faction names in descr_strat.txt too.

Psyco
01-19-2007, 04:58
Thanks for all the help. I appreciate it.

zxiang1983
01-27-2007, 17:11
Hi all. I want to write a script to achieve this result: Every time I press the "disband unit" button, it will create a certain unit in a certain city.




script

declare_counter loop
set_counter loop 1

monitor_event ButtonPressed ButtonPressed disband_unit
console_command create_unit Bordeaux "Dismounted Feudal Knights80" 1
end_monitor

while I_CompareCounter loop = 1
end_while

end_script

As you can see, the problem is I don't know what the real button ID of "disband unit". The CA docudemon says it can be found in a file called available_ui_elements.txt. But where can I find it?

Atilius
01-28-2007, 03:54
You were very close: it's disband_unit_button. Jerome Grasdyke from CA was kind enough to post the contents of this file here (https://forums.totalwar.org/vb/showpost.php?p=929325&postcount=5).

zxiang1983
01-28-2007, 10:47
Thank u so much! It helps a lot!

chou2714
11-17-2007, 11:27
Hello everyone. I m'essaye scripting and hope poster to the right place. That is my problem.
I managed (with the help of another modder of TWcenter) to a script that damages the shrine battleforge and built a shrine fun when you take the city of genua. Here is the script

script
declare_counter loop
set_counter loop 0

monitor_event GeneralCaptureSettlement SettlementName Genua
and CharacterIsLocal
and not SettlementBuildingExists = shrine_fun

console_command set_building_health Genua battleforge 0
console_command create_building Genua shrine_fun

end_monitor
while I_compareCounter loop = 0
end_while
end_script

I wish now that the shrine battleforge damage and fun shrine built for all cities that I will take. Do you have any idea?

Sorry for my English, I am french:embarassed:

Squid
11-17-2007, 13:56
Replacing the condition SettlementName Genua with TrueCondition should do the trick. You do realise that the script as currently written will give you a shrine_fun even if a settlement doesn't have a battleforge shrine?

chou2714
11-17-2007, 18:04
Yes, I know and that troubles me. But in console_command I replaces genua by what?

octavius vatco
11-23-2007, 12:24
excues me? does this command exist here?

"I_settlement_besiege"??

Squid
11-23-2007, 17:03
You have now asked this question in three different locations, two here at the org, and one at twcenter. The answer doesn't change no matter how many times you ask, it is still no.

Bardo
04-11-2008, 09:59
Now that I'm finishing my work with the scripts for lotr-tw, I would like to thank to Epistolary Richard and Myrddraal for all their reseraching about scripts and for this awesome guide. And I would like to share some info that I missed in this guide and could have saved me a lot of time.
Most of the info is already known by most of the scripters, it is just my list of notes about scripting. I know it is a bit late, and few people still seems working with rtw scripts, but just in case...
Maybe this post encourage to someone with more knowledge to make a "complete guide to scripting", or at least that other scripters share their tips here.

IMPLEMENTING
-The most important when you implement a "monitor_event" is to check the "Trigger requirements:" of the condition you want to use (docudemon_conditions.txt),
and verify that it is included in the "Exports:" of the event used to trigger the monitor (docudemon_events.txt).
Conditions starting by "I_" do not need requeriments from the event and so they can be used with if and while statements.
-The condition RandomPercent can be used without any requeriments, like all conditions starting by I_
-WorldwideAncillaryExists does not need any Trigger requirements (even when the docudemon_conditions.txt says character_record). I use the next syntaxis and it works as expected (I'm sure):

monitor_event PreBattlePanelOpen WorldwideAncillaryExists one_ring true
and not WorldwideAncillaryExists lost_ring true
;code here
end_monitor

-The condition that triggers a "monitor_conditions" can not be changed inside the monitor, so it needs the command "terminate_monitor" to avoid being executed for ever.
If you want the monitor to be triggered more than once you need to use a "monitor_event".

monitor_conditions I_CompareCounter no = 1
;code here executed up to one time until you reload the script
terminate_monitor
end_monitor

-The condition SettlementName uses the Name showed in the strat map (look at ...\text\region and settlement names.txt), not the internal name of the settlement like other commands related to settlements.
Note it does work with CharacterTurnEnd but does not with CharacterTurnStart (the later does not export the settlement)
-The event GeneralCaptureSettlement is triggered no matter the type of character: general, named character or family.
-Moving characters:
1) move: it uses the standard movement points of the character to try to reach the destiny. So it has to be used during the turn of the character you want to move, and it will not work if the character is far from the target possition (it is equal to select the character and click the right button over the target coordinates). If the character is the commander of his army, all the army will be moved, if not, only the character will move.
This is the only command that allows you to move a character in and out of a settlement or an army.
2) console_command move_character: In this case the character is teleported to the target possition, no matter the movement points or the availability of a path, but it does nothing if the character is not the commander of his army, or if the character is inside a settlement.
If the character is moved over an occupied tile (or over a city), the armies do not merge (nor enter into the city). In stead the moved army stand over them, and then you have to select them using the character browser, because sometimes it is not possible to click them directly.
This command sometimes makes the moved character invisible. It seems random, but related to characters teleported when they are sieging or hidden in forests, or in a occupied tile. However, this effect dissapears after reload and it do not cause ctds (that I know).
3) reposition_character: the same than move_character, but it could cause ctds if the character does not exist, and probably in some other cases too, I do not use it.

SUGGESTIONS
-When you are at the console command interface, if you press up-arrow you can see all the commands that have been executed previously, in the order they have been launched.
By using this with a script, you can check if monitors containing a console_command are working, and when they are triggered.
-use console_command toggle_fow and toggle_perfect_spy to view all the info about armies and settlements in the strat map.

CTD CAUSES
People think that scripts causes a lot of ctds and they are sometimes afraid to use them, but in fact there are very few scripting commands that can cause ctds, and most of them are related to mistakes in other files related to advices, buildings, units, trais...
These are the only ctd causes that I have ever found in my scripts:

1- advance_advice_thread Advice_Thread: when the thread name is wrong
2- spawn_army or spawn_character: with a wrong character name or wrong unit name
3- console_command create_unit Settlement "unit name" 1
if there is something wrong with the unit
4- console_command create_building Settlement building_name
if there is something wrong whit the building
5- console_command give_ancillary Character ancillary
if there is something wrong whit the ancillary
6- console_command give_trait Character Trait 1
if there is something wrong whit the trait
7- move or reposition_character cause ctds if the character does not exist (or is died). Better use console_command move_character that can not cause ctds.
8- to spawn admirals (with ships) could cause ctds when other ships try to attack them, because they are created as if they where land units, in stead of naval units.

That I know, it does not matter if you use a name that does not exist with other commands like kill_character or move_character, or if the name of the faction is wrong using diplomatic_stance, control, or add_money or the settlement name is wrong when you use add_population, capture_settlement... Only the commands listed above seems to cause ctds when they are wrong.
However, there are many commands I have never used, so other known ctd causes will be welcome.

NOT WORKING
-Prebattle event is not implemented
-I have been unable to use the console command "event <event_type> <opt:position>", as well as all console commands starting by list_ or test_ (at least using AlexanderTW)

DESIGNING
Since counters are not stored when you save and reload the game, we need some workarround to save script's state upon reloads. There are several options, both with pros and cons:
1)Buildings/plugins: condition checked from an event that exports the settlement. They can be created but not destroyed by script. They can be permanent if hinterland_buildings.
(console_command set_building_health Settlement building -1 does not destroy it)
2)Traits: condition checked from an event that exports the character_record. They can be created and removed by script, but they are not permanent since the characters can die.
3)Ancillaries: can be checked from ANY event using WorldwideAncillaryExists (except from trait triggers). They can be created by script, but the only way to destroy them is to kill the character. As traits, non permanent.

In our mod, we use a hidden city in the top-right corner with a special character who we can use to save a lot of info about the scripts: using buildings with the city, traits and ancillaries with the character (since we know his name we can kill and respawn him), and even changing and checking his possition in the map.
Very useful, but only recomended for heavy scripted mods :P

-To detect the owner for a certain retinue: the retinue should affect one Attribute of the character not affected by any other aspect of the game,
usually "SenateStanding", "PopularStanding", "Electability" (without senate) or "NavalCommand".
-The console_command "diplomatic_stance faction1 faction2 allied" does not change the attitude of one faction against the other, just the alliance agreement, so it is a bit useless to avoid attacks from the ai factions.
-To check that a certain character is placed near a certain position, without using settlements: you can try to move the target character to the target possition in the map, then wait for the movement, and then to check if the character has arrived to the destination, by using "not I_CharacterTypeNearTile" before the movement, and "I_CharacterTypeNearTile" after the movement. If the character has not arrive in this time is because he was not near that tile.
-The commands "wait" or "campaign_wait" do not stop the campaign, just the scripts, and they should not be used inside a monitor, nor during AI turn.
Also, it seems that script's variables are not updated correctly while the "wait" is called from the inside of an "if" sentence.


Some examples from our scripts, that could be useful for someone else



;**********************************************
; FORCE OCCUPY
; Avoid the human player to exterminate/enslave while playing certain factions: seleucid, macedon and thrace in this case
;**********************************************

script

declare_counter player
set_counter player 1
declare_counter scroll
set_counter scroll 0

monitor_event FactionTurnStart FactionIsLocal
set_counter player 1
end_monitor
monitor_event FactionTurnEnd FactionIsLocal
set_counter player 0
end_monitor

monitor_event ScrollOpened ScrollOpened loot_settlement_scroll
if I_LocalFaction seleucid
set_counter scroll 1
end_if
if I_LocalFaction macedon
set_counter scroll 1
end_if
if I_LocalFaction thrace
set_counter scroll 1
end_if
end_monitor

monitor_conditions I_CompareCounter player = 1
and I_CompareCounter scroll = 1
set_counter scroll 0
select_ui_element loot_settlement_occupy_button
simulate_mouse_click lclick_down
simulate_mouse_click lclick_up
end_monitor

while TrueCondition
end_while

script



;**********************************************
; GARRISON SCRIPT
;**********************************************

script

declare_counter City1Besiged
set_counter City1Besiged 0
declare_counter City2Besiged
set_counter City2Besiged 0
;...per settlement

monitor_event FactionTurnEnd FactionType [faction1]
and I_LocalFaction [faction1]

if I_CompareCounter City1Besiged = 0
and not I_SettlementOwner [city1] = [faction1]
if I_CharacterTypeNearTile [faction1] general, 2 x1,y1
set_counter City1Besiged 1
end_if
if I_CharacterTypeNearTile [faction1] family, 2 x1,y1
set_counter City1Besiged 1
end_if
end_if
if I_CompareCounter City1Besiged = 2
and not I_CharacterTypeNearTile [faction1] family, 2 x1,y1
and not I_CharacterTypeNearTile [faction1] general, 2 x1,y1
set_counter City1Besiged 0
end_if

if I_CompareCounter City2Besiged = 0
and not I_SettlementOwner [city2] = [faction1]
if I_CharacterTypeNearTile [faction1] general, 2 x2,y2
set_counter City2Besiged 1
end_if
if I_CharacterTypeNearTile [faction1] family, 2 x2,y2
set_counter City2Besiged 1
end_if
end_if
if I_CompareCounter City2Besiged = 2
and not I_CharacterTypeNearTile [faction1] family, 2 x2,y2
and not I_CharacterTypeNearTile [faction1] general, 2 x2,y2
set_counter City2Besiged 0
end_if
;...per settlement

end_monitor
;...a monitor per possible local faction

monitor_event SettlementTurnEnd SettlementName [city1-mapname]
and I_CompareCounter City1Besiged = 1
and GarrisonSettlementRatio < 0.5
if I_SettlementOwner [city1] = [faction1]
console_command create_unit [city1] "unit name" 4
console_command add_money -2000
console_command add_population City -1500
end_if
if I_SettlementOwner [city1] = [faction2]
console_command create_unit [city1] "unit name" 4
console_command add_money -2000
console_command add_population City -1500
end_if
set_counter City1Besiged 2
;...an if per faction
end_monitor

monitor_event SettlementTurnEnd SettlementName [city2-mapname]
and I_CompareCounter City2Besiged = 1
and GarrisonSettlementRatio < 0.5
if I_SettlementOwner [city2] = [faction1]
console_command create_unit [city1] "unit name" 4
console_command add_money -2000
console_command add_population City -1500
end_if
if I_SettlementOwner [city2] = [faction2]
console_command create_unit [city1] "unit name" 4
console_command add_money -2000
console_command add_population City -1500
end_if
;...an if per faction
set_counter City2Besiged 2
end_monitor
;...a monitor per settlement


while TrueCondition
end_while

end_script




;**********************************************
; CHECK CHARACTER POSSITION
; show_me script
;**********************************************

;(This script does work:)
script

declare_counter Character_moved
set_counter Character_moved 0

if not I_CharacterTypeNearTile faction named_character, 0 116,154
set_counter Character_moved 1
move Character, 116,154
end_if

campaign_wait 5

if I_CharacterTypeNearTile germans named_character, 0 116,154
and I_CompareCounter Character_moved = 1
console_command give_ancillary Character ancillary
end_if

end_script


;(This script do the same, but does not work when the wait is placed inside the if... weird)
script

if not I_CharacterTypeNearTile faction named_character, 0 116,154
set_counter Character_moved 1
move Character, 116,154

campaign_wait 5

if I_CharacterTypeNearTile germans named_character, 0 116,154
console_command give_ancillary Character ancillary
end_if
end_if

end_script


You can find all my scripts into this patch, so people do not need the whole mod if just interested in the scripts:
http://www.mediafire.com/?uzzwg0nemmz

Dol Guldur
04-11-2008, 11:40
Brilliant addendum Bardo. Thank you for posting - so many discover little things or find the best way of doing things and never both to post their findings which results in much lost time for those who follow the same path.

Kudos!

I hope someone does write a "Complete Scripting" guide - though it certainly will not be me ;)

Aradan
04-11-2008, 16:11
Great addition, indeed. Thx Bardo for that compilation of info!

Monkwarrior
04-18-2008, 12:44
In our mod, we use a hidden city in the top-right corner with a special character who we can use to save a lot of info about the scripts: using buildings with the city, traits and ancillaries with the character (since we know his name we can kill and respawn him), and even changing and checking his possition in the map.
Very useful, but only recomended for heavy scripted mods :P


I use the same system, the hidden city in one corner, but I found some little problems when saving and reloading the saved game. I've solved them (I think so) by using a "tricky" method that requires a double building system.

I use mainly scripts to issue missions for human player. But in some cases missions are simultaneous, and hence some type of selective detection method had to be implemented.

The problem was the succession of facts:
- Event in the player turn: counter signal 1
- Creation of building in the hidden city: rebel turn, counter signal 2
- New player turn: message to player and counter signal 3
- Reloading: detection of the buildings present in hidden city and messaged issued to the player to remember him/her the present mission.

If game was saved in between those three facts, there were problems with reloaded games, as the player didn't get the reward, or the message for the new mission was missing, etc because in some turn changes the only mark was the counter (lost in saving).

I don't know if this subject is interesting enough to post the method. If so, I will look for it (I have not the files in this computer) and post it here. :book:

Bardo
04-19-2008, 10:02
Since counters can not be saved (this is something very important I missed in my notes...), I try to use them only between events where the player can not save the game, like between FactionTurnStart-CharacterTurnStart, or CharacterTurnEnd-FactionTurnEnd.

In your case, why don't you create the building in the player's turn:
- Event in the player turn: counter signal 1 = Creation of building in the hidden city during player turn
- New player turn: message to player and counter signal 3

I guess there are some other reason that forces you to have 3 events, in this case I'm interesting in your solution, just paste the code here if you find it.

Monkwarrior
04-22-2008, 00:16
Ok, I will try to explain the question in my poor English.

My scripts are based in a succession of missions and rewards. But it is important that missions are accomplished in the right order.

An example of the first mission in the carthaginian campaign.

I have a counter named switch, that serves only to show the game in which moment we are.
It starts at 100 (turn 0 or when reloaded)


declare_counter switch
set_counter switch 100

but it will be changed in the next turn when the first mission is issued.



if I_TurnNumber = 0

wait 1
advance_advice_thread Mision1_Cartago_Thread no_dismiss
wait 1
select_ui_element advisor_portrait_button
simulate_mouse_click lclick_down
simulate_mouse_click lclick_up
set_counter switch 0
settlement_flash_start Saguntum

end_if


Then we have the conditions for mission success. A first fake building is created at the moment. Because of the overlapping of messages, the success message is issued to the player when the loot settlement scroll is closed.


monitor_event GeneralCaptureSettlement FactionType carthage
and SettlementName Saguntum

settlement_flash_stop Saguntum
console_command add_money 30000
console_command diplomatic_stance romans_julii carthage war
console_command create_building Aquincum monument_victory_minor1
set_counter switch 1

terminate_monitor
end_monitor

monitor_event ScrollClosed loot_settlement_scroll
and I_CompareCounter switch = 1

advance_advice_thread Exito_Mision1_Cartago_Thread no_dismiss
wait 1
select_ui_element advisor_portrait_button
simulate_mouse_click lclick_down
simulate_mouse_click lclick_up
set_counter switch 0

terminate_monitor
end_monitor

In this way it will be sure that we have a fixed point if player saves game in that moment.
If he follows playing, the script checks if this building exists to issue the message for the second mission.


monitor_event SettlementTurnStart SettlementName Aquincum
and SettlementBuildingExists = monument_victory_minor1
and not SettlementBuildingExists = milestone1
and not SettlementBuildingExists = monument_victory_minor2
and not SettlementBuildingExists = monument_victory_minor3
and not SettlementBuildingExists = monument_victory_minor4
and not SettlementBuildingExists = monument_victory_major
and I_CompareCounter switch = 0

set_counter switch 11

terminate_monitor
end_monitor

monitor_event FactionTurnStart FactionType carthage
and I_CompareCounter switch = 11

advance_advice_thread Mision2_Cartago_Thread no_dismiss
wait 1
select_ui_element advisor_portrait_button
simulate_mouse_click lclick_down
simulate_mouse_click lclick_up
console_command create_building Aquincum milestone1
set_counter switch 0

terminate_monitor
end_monitor

The second fake building prevents this messsage to be issued for a second time.

Let's see now what happens if the player loads a saved game. The switch counter will be at 100, and in the slave turn the presence of the fake buildings will be checked.


monitor_event SettlementTurnStart SettlementName Aquincum
and not SettlementBuildingExists = monument_victory_minor1
and not SettlementBuildingExists = monument_victory_minor2
and not SettlementBuildingExists = monument_victory_minor3
and not SettlementBuildingExists = monument_victory_minor4
and I_CompareCounter switch = 100
and I_TurnNumber > 1

set_counter switch 101

end_monitor

monitor_event FactionTurnStart FactionType carthage
and I_CompareCounter switch = 101

advance_advice_thread Recuerdo_Mision1_Cartago_Thread no_dismiss
wait 1
select_ui_element advisor_portrait_button
simulate_mouse_click lclick_down
simulate_mouse_click lclick_up
settlement_flash_start Saguntum
set_counter switch 0

end_monitor

As no building is present, the script launches a message to remember the first mission to human player.

Perhaps there would be a simpler method to do it, but it was the only way I found to prevent missing messages to the human player. :book:

Bardo
04-23-2008, 09:13
If there is an easier way, I don't know it. Afaik,The only way to prevent a message from being showed again is to remember it with a building/trait. The same for the mission success, so you need the 2 fake buildings.
Thank you for explain it, it is very useful to understand how to use buildings to save scripting information.