
Originally Posted by
gigantus
My goal is twofold:
1. the event in case of war should fire only once
2. the termination should occur for all factions to make it 'neat' - no unnecessary monitors
What would be the drawback of those counters? It appears to me a viable solution. And I could use those counters in a different\similar monitor again.
So you only want the very first war declaration by any faction to throw up an event based on who they're at war with, and then no events besides that one? Or, you only want the event to fire once for each aggressor? Or, you only want the event to fire once for each pairing?
Those three approaches require different solutions but they can all be solved I'd say. Here's an example of all three methods, the first and last bits apply to all methods. Each method is only an example, they'd need to have *_turn counters and 'if' statements added for every applicable faction, as well as having monitors for each applicable faction to check that war was declared on them.
Code:
declare_counter france_turn
declare_counter england_turn
declare_counter scotland_turn
declare_counter milan_turn
;etc
; Set the counters to 1 at the start of the turn, Kingdoms only command, use FactionTurnStart if on M2
monitor_event PreFactionTurnStart FactionType england
set_counter england_turn 1
end_monitor
monitor_event PreFactionTurnStart FactionType france
set_counter france_turn 1
end_monitor
monitor_event PreFactionTurnStart FactionType scotland
set_counter scotland_turn 1
end_monitor
monitor_event PreFactionTurnStart FactionType milan
set_counter milan_turn 1
end_monitor
;; Method #1
;; Use this method if you only want to check the very first
;; war declaration of any faction
; Someone has declared war on Milan
monitor_event FactionWarDeclared TargetFactionType milan
; If it's England's turn at the time, we can assume it was them
if I_CompareCounter england_turn == 1
and I_EventCounter war_has_been_declared == 0
; do something
end_if
; If it's France's turn at the time, we can assume it was them
if I_CompareCounter france_turn == 1
and I_EventCounter war_has_been_declared == 0
; do something
end_if
; If it's Scotland's turn at the time, we can assume it was them
if I_CompareCounter scotland_turn == 1
and I_EventCounter war_has_been_declared == 0
; do something
end_if
set_event_counter war_has_been_declared 1
terminate_monitor
end_monitor
;; End Method #1
;;Method #2
;; Use this method if you want to spawn an event for each
;; aggressor only once, based on which faction it's attacking
;Someone has declared war on Scotland
monitor_event FactionWarDeclared TargetFactionType scotland
; If it's France's turn at the time, we can assume it was them
if I_CompareCounter france_turn == 1
and I_EventCounter france_declared_a_war == 0
; do something
set_event_counter france_declared_a_war 1
end_if
; If it's England's turn at the time, we can assume it was them
if I_CompareCounter england_turn == 1
and I_EventCounter england_declared_a_war == 0
; do something
set_event_counter england_declared_a_war 1
end_if
; If it's Milan's turn at the time, we can assume it was them
if I_CompareCounter milan_turn == 1
and I_EventCounter milan_declared_a_war == 0
; do something
set_event_counter milan_declared_a_war 1
end_if
if I_EventCounter milan_declared_a_war == 1
and I_EventCounter england_declared_a_war == 1
and I_EventCounter france_declared_a_war == 1
and I_EventCounter milan_declared_a_war == 1
;; etc etc for each faction
terminate_monitor
end_if
end_monitor
;; End Method #2
;; Method #3
;; Use this method if you want the event to fire
;; once for each war pairing
;Someone has declared war on England
monitor_event FactionWarDeclared TargetFactionType england
; If it's Milan's turn at the time, we can assume it was them
if I_CompareCounter milan_turn == 1
and I_EventCounter milan_vs_england == 0
; do something
set_event_counter milan_vs_england 1
end_if
; If it's Scotland's turn at the time, we can assume it was them
if I_CompareCounter scotland_turn == 1
and I_EventCounter scotland_vs_england == 0
; do something
set_event_counter scotland_vs_england 1
end_if
; If it's France's turn at the time, we can assume it was them
if I_CompareCounter france_turn == 1
and I_EventCounter france_vs_england == 0
; do something
set_event_counter france_vs_england 1
end_if
if I_EventCounter france_vs_england == 1
and I_EventCounter scotland_vs_england == 1
and I_EventCounter milan_vs_england == 1
;;etc etc for each vs. England
terminate_monitor
end_if
end_monitor
;; End Method #3
;Set the counters back to 0 at the end of the turn
monitor_event FactionTurnEnd FactionType england
set_counter england_turn 0
end_monitor
monitor_event FactionTurnEnd FactionType france
set_counter france_turn 0
end_monitor
monitor_event FactionTurnEnd FactionType scotland
set_counter scotland_turn 0
end_monitor
monitor_event FactionTurnEnd FactionType milan
set_counter milan_turn 0
end_monitor
You can also kill the *_turn monitors based on the same criteria as whatever it takes to kill the other monitors. For the last method you'd want to use a further event counter set in the terminate_monitor 'if' statements and then check all of those for true.

Originally Posted by
Taiji
Looking at it again, I think you're right about me being right
Only joking, you deserve the credit, nice idea

I probably wouldn't have thought of it actually.