I have been investigating a crash together with Kull, where the game crashes when the faction leader gets killed in the battle where the last settlement of his faction falls, unless the rest of the family dies too. At least in EBII's case, this was narrowed down to be because of trait triggers using WhenToTest BecomesFactionLeader.
While these triggers work perfectly fine for normal succession, they are also tested when the faction dies and crash the game if any of them get fired (they have all conditions evaluating to true).
The workaround I found was to postpone processing of succession related triggers to the end of the turn. It introduces these traits as flags:
Code:
Trait NotFactionLeader
Characters family
Hidden
Level NotFactionLeader
Description Hidden_desc
EffectsDescription Hidden_effects_desc
Threshold 1
Trait BecameFactionLeader
Characters family
Hidden
Level BecameFactionLeader
Description hidden_desc
EffectsDescription hidden_effects_desc
Threshold 1
These triggers below must be placed before any succession triggers to set these flags - keep NotFactionLeader on all generals, and switch to BecameFactionLeader whenever the faction leader has this flag, signalling succession.
Code:
Trigger NotAFactionLeader
WhenToTest CharacterTurnEnd
Condition IsGeneral
and not IsFactionLeader
and Trait NotFactionLeader < 1
Affects NotFactionLeader 1 Chance 100
Trigger IsNowFactionLeader
WhenToTest CharacterTurnEnd
Condition IsGeneral
and IsFactionLeader
and Trait NotFactionLeader > 0
Affects BecameFactionLeader 1 Chance 100
Affects NotFactionLeader -1 Chance 100
Each trigger currently using BecomesFactionLeader then has to change like this:
Code:
Trigger ArmenianBecomesLeader
WhenToTest BecomesFactionLeader CharacterTurnEnd
Condition FactionType f_hayasdan
and Trait Arkah < 1
and Trait BecameFactionLeader > 0
Affects Arkah 1 Chance 100
Finally, after all succession triggers, the flag that someone became faction leader must be reset to avoid them firing each turn.
Code:
Trigger BecomingFactionLeaderFinished
WhenToTest CharacterTurnEnd
Condition IsGeneral
and Trait BecameFactionLeader > 0
Affects BecameFactionLeader -1 Chance 100