Thanks mate! Bare with me, but I'd like to ask some clarifications so that I understand better.

Originally Posted by
HouseOfHam
- I don't think "and if" is valid syntax. At least, I've never seen it used that way. It should be just "and", since it's part of the same "if" statement.
Before ending up with this syntax for monitoring I tried two others that seemed more "according to examples". But none of these two worked.
Code:
FIRST ONE:
monitor_event PostBattle FactionIsLocal
if I_LocalFaction sarmatians
and I_PercentageUnitKilled importantdude_bodyguard > 10
and I_CompareCounter captive = 0
advance_advice_thread PromptThreadCaptive 1
set_counter captive 1
console_command add_money 20000
end_if
end_monitor
SECOND ONE:
monitor_event PostBattle FactionIsLocal
I_LocalFaction sarmatians
I_PercentageUnitKilled importantdude_bodyguard > 10
I_CompareCounter captive = 0
advance_advice_thread PromptThreadCaptive 1
set_counter captive 1
console_command add_money 20000
end_monitor
Neither of them brings up the advance_advice_thread or add money (I'm using it just as an indicator here!). I tried to fight both in battle mode and on strat map with no difference. With both of the versions the background script seems to start endless times every time I select a city or press some of the UI buttons in strat map. I.e. the campaign adviser comes several times saying "background script started". Should any of these be correct syntax and if so, why does the adviser come several times?
The one I sent in the first message (with "and ifs") seemed to be the only one that works at least partly. I am able to get the message defined by advance_advice_thread and to get the money. But it comes every time the unit type loses more than 10 %, which should not be the case.

Originally Posted by
HouseOfHam
- The unit_label parameter expected by I_PercentageUnitKilled is a id created via the label_unit command, where the unit_label refers to a specific unit index within a specific army. This pretty much limits its use to historical battles where you know each unit's index ahead of time.
But I have not used any label_unit command, just the name that is after the dictionary tag in EDU.txt
. I tried to send two different importantdude_bodyguard -units to fight two different armies and it worked for both. So could it be that in the absence of a label it looks at the dictionary name?

Originally Posted by
HouseOfHam
- Moreover, I_PercentageUnitKilled only works in battle mode, whereas PostBattle only work in strategy map mode. I wouldn't expect a monitor that combines the two to work at all.
This I did not know at all! But as said, it seemed to work - at least partly and a weird syntax ;-). Any idea why?

Originally Posted by
HouseOfHam
Anyhow, I don't think there's a way to do this without tying it to general's unit, so you can use the PercentageBodyguardKilled condition.
Ok, that would work both in battle and strat map mode. But i'm still not sure how I should proceed, since the basic syntax of ifs is not clear really... Could you or someone else help?!
I enclose the full background script if that would help:
Code:
script
; Anything following a semicolon is a comment.
; Remove the adviser portrait from screen.
select_ui_element advisor_dismiss_button
simulate_mouse_click lclick_up
; Wait for it to go away.
while I_AdvisorVisible
end_while
suspend_unscripted_advice true
; Open the adviser message bubble automatically whenever advance_advice_thread is called.
; I recommend using this method instead of the select_ui_element + simulate_mouse_click approach.
; Do NOT mix both methods, though, or the advisor will show and then immediately close before
; you get a chance to read the text.
declare_show_me
; Very useful for debugging - uncomment to use
;console_command toggle_perfect_spy
;;;
;;; --- Forced shutdown ---
;;;
;;; Press 'Esc' on the campaign map, then click on the '?' button in the
;;; menu scroll to terminate the script.
;;;
;;; When would this be useful? -- When you are already in a game and
;;; exit back to the main menu to restart the campaign, or reload a saved
;;; game, RTW does not automatically terminate the script, so you have
;;; to do it yourself. If you leave the old script running, you'll have all
;;; sorts of weird problems with the script in the new game.
;;;
monitor_event ScrollAdviceRequested ScrollAdviceRequested end_game_scroll
terminate_script
end_monitor
; Handle saved game reloads
monitor_event GameReloaded TrueCondition
terminate_script
end_monitor
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; This is where to put your own code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
declare_counter captive
set_counter captive 0
monitor_event PostBattle FactionIsLocal
if I_LocalFaction sarmatians
and if I_PercentageUnitKilled importantdude_bodyguard > 10
and if I_CompareCounter captive = 0
advance_advice_thread PromptThreadCaptive 1
set_counter captive 1
console_command add_money 20000
end_if
end_monitor
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; End of your code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Spin forever - Do not let the script terminate or any monitors you have set up will immediately get thrown away.
; In M2TW scripts, this loop is replaced by the wait_monitors command. Unfortunately, this command is not available in RTW.
while I_TurnNumber < 99999
suspend_unscripted_advice true
end_while
end_script