Hands-On Usage
random_state_division is commonly used in mods to apply special effects to a single random division within a given state — for example, granting a commander trait to a division when a battlefield event fires, reducing organization, or swapping a unit template. Typical scenarios include reducing the organization of a random garrison after a province is bombed, or awarding a decoration to a random elite division during a scripted event.
# Under STATE scope, apply an effect to one random division in the state that meets the condition
random_state_division = {
limit = {
unit_strength > 0.5
}
set_unit_organization = 0.3
tooltip = random_state_division_tt
}
The example above finds one division in the current state with a strength above 50%, sets its organization to 30%, and overrides the tooltip header with a custom tooltip key.
Synergy
- unit_strength: Used inside the
limit block to filter targets by a division's current strength — the most common filtering method, preventing the effect from hitting nearly-destroyed remnants.
- set_unit_organization: Combined with this effect to adjust the organization of the selected division; it is the most frequently used sub-command inside
random_state_division.
- add_divisional_commander_xp: In event reward scenarios, grants experience to the commander of the randomly selected division, achieving a narrative effect of "commending the heroic division of a state."
- custom_effect_tooltip: When the underlying logic is complex, this displays a human-readable description to the player, working alongside the
tooltip=key parameter to manage UI presentation.
Common Pitfalls
-
Wrong scope: random_state_division can only be called under a STATE scope. If the current scope is COUNTRY or DIVISION, the script will fail silently or produce no effect. You must first enter a state scope via every_state, random_state, or similar before calling this command.
-
Mixing effect commands inside limit: Beginners sometimes write set_unit_organization or damage_units inside the limit = { } block, but limit only accepts triggers (such as unit_strength or is_unit_template_reserves). Placing effect commands there will cause a parse error or be silently ignored by the game. All actual execution logic must be written outside the limit block, as direct children of random_state_division.