Wiki

trigger · has_id

Definition

  • Supported scope:CHARACTER
  • Supported target:none

Description

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

实战 · 配合 · 坑

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

实战用法

has_id 常用于需要精确定位某个特定角色的场景,例如在剧本事件或国策中判断"当前操作的角色是否就是那个我们预设的特殊将领",从而触发专属分支逻辑。典型场景包括:限制某个隐藏国策只对特定 ID 的将领生效,或在 on_action 触发时过滤掉非目标角色。

# 在某个将领相关事件的 trigger 块中,确认触发者是目标角色
character_event = {
    id = my_mod.1
    trigger = {
        # scope 为 CHARACTER
        has_id = 123
    }
    ...
}

配合关系

  • [is_corps_commander](/wiki/trigger/is_corps_commander) / [is_field_marshal](/wiki/trigger/is_field_marshal):在确认 ID 匹配之后,进一步校验该角色当前的军事职位,避免对职位已变更的角色误触发逻辑。
  • [has_trait](/wiki/trigger/has_trait):与 has_id 并列使用,确认指定 ID 的角色是否同时持有某特质,常用于解锁专属特质链。
  • [add_trait](/wiki/effect/add_trait)(即 [add_trait](/wiki/effect/add_trait)):has_id 作为前置条件通过后,在 effect 块中安全地为该特定角色添加特质,防止 trait 误发给其他角色。
  • [has_character_flag](/wiki/trigger/has_character_flag):与 has_id 配合做"已处理"标记检查,防止同一角色的专属事件链被重复触发。

常见坑

  1. 把 ID 当本地化文本使用:官方明确标注"Don't localize this",该 trigger 的 tooltip 仅用于调试目的,切勿在面向玩家的提示文本中依赖它显示有意义的信息,否则会出现空白或报错提示。
  2. ID 与角色定义不同步:角色的数字 ID 由游戏在加载时动态分配顺序决定,若 mod 中角色文件的加载顺序或数量发生变化(如新增/删除其他角色),原本硬编码的 ID 值可能指向错误的角色,建议在调试模式下用 charinfo 命令实时确认目标角色的真实 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

has_id is commonly used in scenarios requiring precise targeting of a specific character, such as in scripted events or national focuses to determine "whether the character currently being acted upon is the special leader we predefined," thereby triggering exclusive branch logic. Typical use cases include: restricting a hidden national focus to apply only to leaders with a specific ID, or filtering out non-target characters when on_action is triggered.

# In the trigger block of a character-related event, confirm the triggering character matches the target
character_event = {
    id = my_mod.1
    trigger = {
        # scope is CHARACTER
        has_id = 123
    }
    ...
}

Synergy

  • [is_corps_commander](/wiki/trigger/is_corps_commander) / [is_field_marshal](/wiki/trigger/is_field_marshal): After confirming ID match, further verify the character's current military position to avoid misfiring logic on characters whose positions have changed.
  • [has_trait](/wiki/trigger/has_trait): Used alongside has_id to confirm whether the specified ID character simultaneously possesses a certain trait, commonly used to unlock exclusive trait chains.
  • [add_trait](/wiki/effect/add_trait): After has_id passes as a precondition, safely add traits to that specific character in the effect block, preventing traits from being accidentally applied to other characters.
  • [has_character_flag](/wiki/trigger/has_character_flag): Combined with has_id to check "already processed" markers, preventing exclusive event chains for the same character from being triggered repeatedly.

Common Pitfalls

  1. Treating ID as localization text: The official documentation explicitly states "Don't localize this"—the tooltip of this trigger is intended for debugging purposes only. Do not rely on it to display meaningful information to players, otherwise you'll encounter blank displays or error prompts.
  2. ID and character definition out of sync: Character numeric IDs are dynamically assigned by the game during load order, so if the loading order or quantity of character files in your mod changes (e.g., adding/removing other characters), previously hardcoded ID values may point to the wrong character. It's recommended to use the charinfo command in debug mode to confirm the target character's actual ID before writing it into scripts.