Wiki

trigger · has_trait

Definition

  • Supported scope:CHARACTER, COMBATANT
  • Supported target:none

Description

check if sides leader has trait

实战 · 配合 · 坑

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

实战用法

has_trait 常用于判断将领或角色是否已拥有特定特质,从而决定是否触发后续事件或开放特殊选项,例如在将领成长事件中检查前置特质、或在顾问招募条件里过滤具备某特质的角色。以下示例展示在事件选项中仅当指定角色持有某特质时才允许选择:

# 在事件触发条件或选项 available 块中使用
available = {
    FROM = {
        has_trait = guerrilla_fighter
    }
}

配合关系

  • [can_select_trait](/wiki/trigger/can_select_trait):先用 has_trait 确认当前特质持有状态,再用 can_select_trait 判断目标特质是否可解锁,两者配合构建特质树前置检查逻辑。
  • [add_trait](/wiki/effect/add_trait):条件判断通过后执行 add_trait,实现"若尚未拥有则赋予"的安全添加模式,避免重复叠加。
  • [replace_unit_leader_trait](/wiki/effect/replace_unit_leader_trait):配合 has_trait 确认旧特质存在后再替换,防止因特质不存在导致脚本报错或静默失败。
  • [add_timed_unit_leader_trait](/wiki/effect/add_timed_unit_leader_trait):与 has_trait 组合可实现"拥有永久特质时才叠加临时强化特质"的进阶触发逻辑。

常见坑

  1. Scope 混用has_trait 要求 scope 为 CHARACTERCOMBATANT,新手容易在 COUNTRY scope 下直接调用而不切换 scope(如忘记用 any_character/FROM 等进入角色 scope),导致条件永远不成立且引擎不会给出明显报错。
  2. 特质名拼写依赖内部 key:传入的特质标识符必须是游戏内部定义的 trait key(如 old_guard),而非本地化显示名称;直接填写中文或显示文本会导致条件静默失败,调试时难以察觉。

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_trait is commonly used to check whether a character or leader possesses a specific trait, enabling conditional logic for subsequent events or unlocking special options. For example, you can verify prerequisite traits in leader growth events or filter characters with certain traits in advisor recruitment conditions. The following example demonstrates how to restrict an event option to characters that hold a specific trait:

# Used within event trigger conditions or option available blocks
available = {
    FROM = {
        has_trait = guerrilla_fighter
    }
}

Synergy

  • [can_select_trait](/wiki/trigger/can_select_trait): Use has_trait first to confirm the current trait ownership status, then use can_select_trait to determine if a target trait can be unlocked. Together, they construct prerequisite checking logic for trait trees.
  • [add_trait](/wiki/effect/add_trait): After condition checks pass, execute add_trait to implement a safe "add if not already owned" pattern, preventing unintended trait stacking.
  • [replace_unit_leader_trait](/wiki/effect/replace_unit_leader_trait): Combine with has_trait to confirm the old trait exists before replacing it, preventing script errors or silent failures caused by missing traits.
  • [add_timed_unit_leader_trait](/wiki/effect/add_timed_unit_leader_trait): Pair with has_trait to implement advanced logic such as "stack temporary trait enhancements only when a permanent trait is present".

Common Pitfalls

  1. Scope Confusion: has_trait requires the scope to be CHARACTER or COMBATANT. Beginners often call it directly under COUNTRY scope without switching scopes (e.g., forgetting to use any_character/FROM to enter character scope), causing the condition to never evaluate true and producing no obvious error message from the engine.
  2. Trait Name Spelling Depends on Internal Key: The trait identifier passed must be the trait key defined internally in the game (e.g., old_guard), not the localized display name. Using Chinese text or display names directly will cause the condition to silently fail, making it difficult to debug.