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.

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.