Wiki

effect · every_unit_leader

Definition

  • Supported scope:COUNTRY
  • Supported target:none

Description

Executes children effects on every Unit Leader (or \"random_select_amount\" of random leader if specified) of the country in scope, that fulfills the \"limit\" trigger.
tooltip=key can be added to override tooltip title.
By default the effects are only displayed once, you may display them for each matching unit leader with display_individual_scopes.
ex: GER = {
  every_unit_leader = {
	tooltip = my_loc_key # Optional
	random_select_amount = 3 # Optional
	include_invisible = yes # Optional - default = no
	display_individual_scopes = yes # Optional - default = no
    ... character scope effects ...
  }
}

实战 · 配合 · 坑

实战内容由 AI 生成,并已对照 vanilla 命令词表校验 —— 请当作起点而非权威依据。上方的定义节才是游戏自带文档原文。

实战用法

every_unit_leader 常用于战争胜利或特定国策完成时,批量给所有将领添加特质、提升技能,或在游戏事件中对满足条件的将领执行清理操作(如移除某个特质)。例如,可以用它在一次大捷后给所有参战将领统一发放经验奖励。

# 某国国策完成后,给所有陆军将领添加攻击特质
GER = {
    every_unit_leader = {
        limit = {
            is_army_leader = yes
            NOT = { has_trait = brilliant_strategist }
        }
        add_unit_leader_trait = aggressive_assaulter
        gain_xp = 10
    }
}

配合关系

  • is_army_leader / is_navy_leader:在 limit 块中筛选特定兵种的将领,避免将效果误施加到海军或空军指挥官。
  • add_unit_leader_trait:最常见的搭配目标,用于批量为将领添加特质,是该循环最典型的用途。
  • has_trait:在 limit 中配合 NOT 使用,防止重复添加同一特质导致脚本报错或产生意外效果。
  • add_skill_level:与 every_unit_leader 配合批量提升将领等级,常用于 formable nation 或特定剧本开局的初始化逻辑中。

常见坑

  1. 忘记 limit 导致效果覆盖所有将领:不写 limit 时,效果会作用于该国 所有 Unit Leader(包括海军将领、空军将领等),若 add_unit_leader_trait 添加的是陆军专属特质,会在日志中产生警告甚至静默失败,务必用 is_army_leader/is_navy_leader 等触发器明确筛选范围。
  2. random_select_amount 一起使用时误以为顺序固定:加上 random_select_amount 后,每次执行都是随机抽取指定数量的将领,结果不可复现;若需要稳定地针对特定将领操作,应改用 if + has_id 或在对应角色文件中直接操作,而非依赖随机抽取。

Hands-On Notes

Hands-on notes are AI-generated and checked against the vanilla command vocabulary — treat them as a starting point, not authoritative reference. The definition above is the game's own documentation.

Hands-On Usage

every_unit_leader is commonly used when a war is won or a specific national focus is completed, to bulk-add traits or raise skill levels for all generals, or to clean up leaders that meet certain conditions during game events (such as removing a specific trait). For example, it can be used to uniformly grant experience rewards to all participating commanders after a major victory.

# After a national focus completes, add an attack trait to all army leaders
GER = {
    every_unit_leader = {
        limit = {
            is_army_leader = yes
            NOT = { has_trait = brilliant_strategist }
        }
        add_unit_leader_trait = aggressive_assaulter
        gain_xp = 10
    }
}

Synergy

  • is_army_leader / is_navy_leader: Use inside a limit block to filter leaders by branch, preventing effects from accidentally being applied to naval or air commanders.
  • add_unit_leader_trait: The most common pairing target — bulk-adding traits to leaders is the quintessential use case for this loop.
  • has_trait: Use together with NOT inside limit to prevent adding the same trait twice, which can cause script errors or unexpected behavior.
  • add_skill_level: Pairs with every_unit_leader to bulk-increase leader skill levels; frequently used in initialization logic for formable nations or specific scenario startups.

Common Pitfalls

  1. Forgetting limit causes the effect to apply to every leader: Without a limit, the effect targets all Unit Leaders belonging to that country (including naval and air commanders). If add_unit_leader_trait adds a trait exclusive to army leaders, this will generate warnings in the log or silently fail. Always use triggers such as is_army_leader / is_navy_leader to explicitly narrow the scope.
  2. Assuming a fixed order when used with random_select_amount: Once random_select_amount is added, each execution randomly picks the specified number of leaders, making the result non-reproducible. If you need to reliably target a specific leader, use if + has_id or operate directly in the corresponding character file instead of relying on random selection.