I_NumberOfSettlements is one way to test whether a faction is alive but it doesn't necessarily work for horde factions because they can be alive without owning any settlements.
An alternative is to use the I_FactionLeaderAttribute condition because it will only work if a faction has a faction leader; if they do not have a faction leader then they must be dead, a rule that also applies to hordes.
For example, to test that the Mongols are alive:
Code:
monitor_event (whatever)
if I_FactionLeaderAttribute mongols Command < 999
;yes they are alive: do whatever...
end_if
end_monitor
If they have no faction leader (they are dead) then that condition returns false. If they do have a faction leader (they are alive) then it returns true, assuming that he does not have Command >= 999 (which would only be possible if some wild script, trait or ancillary was giving him that much for a special reason).
Testing that they are dead is a little more complicated. It needs an additional counter...
Code:
declare_counter faction_is_dead
monitor_event (whatever)
set_counter faction_is_dead 1 ;default to dead=true
if I_FactionLeaderAttribute mongols Command < 999
;they are alive: set dead=false
set_counter faction_is_dead 0
end_if
if I_CompareCounter faction_is_dead == 1
;yes they are dead: do whatever...
end_if
end_monitor
Because I_FactionLeaderAttribute is an independent (I_xxx) condition it can be used anywhere and anytime. e.g. Within the body of monitors.
There are other ways to test for the alive-ness of factions, such as testing whether any CharacterTurnStart event fires for that faction, but such testing is at the mercy of the timing of events, i.e. end of turn. And if you need to test more than one faction then each faction would need its own monitor(s), whereas this I_FactionLeaderAttribute way can be used multiple times within one monitor.
e.g. Script to test if more than one faction is dead, all in one monitor...
Code:
declare_counter faction_is_dead
monitor_event (whatever)
;mongols dead?
set_counter faction_is_dead 1
if I_FactionLeaderAttribute mongols Command < 999
set_counter faction_is_dead 0
end_if
if I_CompareCounter faction_is_dead == 1
;yes mongols are dead: do whatever...
end_if
;england dead?
set_counter faction_is_dead 1
if I_FactionLeaderAttribute england Command < 999
set_counter faction_is_dead 0
end_if
if I_CompareCounter faction_is_dead == 1
;yes england is dead: do whatever...
end_if
;france dead?
set_counter faction_is_dead 1
if I_FactionLeaderAttribute france Command < 999
set_counter faction_is_dead 0
end_if
if I_CompareCounter faction_is_dead == 1
;yes france is dead: do whatever...
end_if
end_monitor
UPDATE:
I just discovered that doing this during PostBattle or CeasedFactionLeader won't work. e.g. If the leader has just been killed then CeasedFactionLeader does fire (even if no other characters remain to take his place) but at the time of this event firing the just-killed leader is still the leader, so I_FactionLeaderAttribute is still looking at him which breaks the whole concept. PostBattle has the same problem.
So while this technique is fine during turn start/end etc. events it falls down when the test needs to be done as soon as the faction is destroyed. This thread has a solution to that: http://www.twcenter.net/forums/showt...3#post13890413
UPDATE 2:
If the faction has family_tree = "no" in descr_sm_factions.txt then it is possible for the faction to be alive without a leader. This method won't work in this case; it will report that the faction is dead when it is not. Thanks gsthoed.