Hands-On Usage
Commonly used when you need to apply effects to a random unit leader within a country — for example, randomly granting a qualifying leader a new trait, boosting their skill level, or rewarding/penalizing a certain type of leader through an event. Typical scenarios include: wartime random events in mods (a random infantry general gains combat experience), or campaign story triggers (a random naval leader receives a promotion).
# Grant a random German general who has the "brilliant_strategist" trait an additional trait
GER = {
random_unit_leader = {
limit = {
has_trait = brilliant_strategist
is_field_marshal = no
}
add_trait = aggressive_assaulter
add_skill_level = 1
}
}
Synergy
- has_trait: Used inside a
limit block to filter for leaders with a specific trait, ensuring the effect only applies to qualifying members of the target pool.
- is_field_marshal: Used inside
limit to distinguish field marshals from corps commanders and army commanders, preventing high-ranking leaders from being selected unintentionally.
- add_unit_leader_trait: Works hand-in-hand with this command and is one of the most common effects for adding a trait to a randomly selected leader within a character scope.
- add_skill_level: Can be combined in the same
random_unit_leader block to modify both traits and skill values in a single pass, avoiding redundant calls.
Common Pitfalls
- Omitting
limit and selecting unintended leaders: If the limit block is left out, the game will randomly pick from all unit leaders in the country — including naval and air leaders — rather than restricting to land generals. This easily produces unintended results. Always use triggers such as is_corps_commander, is_field_marshal, and is_navy_leader to precisely narrow the selection pool.
- Calling the effect outside a COUNTRY scope:
random_unit_leader is only valid within a country scope. Calling it directly inside a state or character scope will cause a script error or silent failure. You must first switch back to a country scope using PREV/ROOT or an explicit country tag before invoking it.