Wiki

trigger · has_unit_leader

Definition

  • Supported scope:COUNTRY
  • Supported target:none

Description

check if country has unit leader with specified ID. Don't localize this. Tooltip only for debug.

实战 · 配合 · 坑

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

实战用法

has_unit_leader 常用于检测某位特定将领是否仍在某国麾下,例如在事件或决策中判断某个剧情关键人物(如特定 ID 的将领)是否还存活、未被俘虏,从而决定是否触发后续剧情链。也可用于 available 块中锁定某决策,只有当玩家拥有该将领时方可执行。

# 示例:某决策仅在拥有 ID 为 500 的将领时可用
decision_example = {
    available = {
        has_unit_leader = 500
    }
    ...
}

配合关系

  • [any_unit_leader](/wiki/trigger/any_unit_leader):当不需要精确 ID、只需检查是否存在满足某条件的将领时,两者形成互补——has_unit_leader 精确定位,any_unit_leader 泛化筛选。
  • [every_unit_leader](/wiki/effect/every_unit_leader):确认该将领存在后,用 every_unit_leader 对其批量添加特性或修改属性,配合使用保证操作安全不报错。
  • [has_character](/wiki/trigger/has_character):若将领同时以顾问/角色形式存在,has_character 可检测其角色状态,两者联合使用可覆盖同一人物的多重身份判断。
  • [add_trait](/wiki/effect/add_trait):在确认将领存在后为其添加特性,避免在将领不存在时执行特性添加导致脚本报错或静默失效。

常见坑

  1. ID 来源混乱:该 trigger 使用的是将领的数值 ID(id = XXX),而非 name 字段或 character 标签。新手常误用本地化名称或 character key 作为参数,导致条件永远不满足。
  2. 不适用于 tooltip 展示:官方明确说明此 trigger 仅用于调试,不应对玩家显示 tooltip,若将其放在 trigger_tooltip 块中向玩家呈现会造成说明文本缺失或显示乱码,应改用其他更直观的条件做可读性替代。

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

has_unit_leader is commonly used to check whether a specific unit leader remains under a particular country's command. For example, it can be used in events or decisions to determine whether a key story character (such as a leader with a specific ID) is still alive and not captured, thereby deciding whether to trigger subsequent story chains. It can also be used in the available block to lock a decision, allowing execution only when the player possesses that leader.

# Example: A decision is only available when possessing a leader with ID 500
decision_example = {
    available = {
        has_unit_leader = 500
    }
    ...
}

Synergy

  • [any_unit_leader](/wiki/trigger/any_unit_leader): When precise ID matching is unnecessary and you only need to check whether a leader exists that meets certain conditions, the two form a complementary pair — has_unit_leader provides exact pinpointing while any_unit_leader enables generalized filtering.
  • [every_unit_leader](/wiki/effect/every_unit_leader): After confirming the leader exists, use every_unit_leader to batch-add traits or modify attributes to them. Using them together ensures operations are safe and error-free.
  • [has_character](/wiki/trigger/has_character): If a leader simultaneously exists as an advisor or character, has_character can detect their character status. Using both together allows you to cover multi-faceted identity checks for the same person.
  • [add_trait](/wiki/effect/add_trait): After confirming the leader exists, add traits to them to avoid executing trait additions when a leader doesn't exist, which could cause script errors or silent failures.

Common Pitfalls

  1. Confusion over ID sources: This trigger uses the leader's numeric ID (id = XXX), not the name field or character key. Beginners often mistakenly use localized names or character keys as parameters, causing the condition to never be satisfied.
  2. Not suitable for tooltip display: The official documentation explicitly states this trigger is for debugging purposes only and should not display tooltips to players. Placing it in a trigger_tooltip block to show players will result in missing or garbled description text. Use other more intuitive conditions as readable alternatives instead.