Wiki

trigger · has_ability

Definition

  • Supported scope:CHARACTER
  • Supported target:any

Description

does unit leader have the abilityCheck if a unit leader has the ability.
Example: has_ability = force_attack

实战 · 配合 · 坑

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

实战用法

has_ability 常用于检查某个将领是否已解锁特定主动技能,从而决定是否允许触发后续事件或特殊效果,例如为拥有"强攻"能力的将领提供额外奖励。在自定义将领成长体系的 mod 中,也可用它来限制某些特质只能被已掌握特定能力的将领获取。

# 仅当该角色拥有 force_attack 能力时,才允许添加特质
if = {
    limit = {
        has_ability = force_attack
    }
    add_unit_leader_trait = aggressive_assaulter
}

配合关系

  • [has_trait](/wiki/trigger/has_trait):通常与 has_ability 联用,先判断将领持有某特质,再检查其是否解锁了对应的主动能力,两者共同构成更精确的条件门槛。
  • [add_trait](/wiki/effect/add_trait):在确认将领已具备某项能力后,通过此 effect 赋予新特质,形成"能力解锁特质"的进阶逻辑链。
  • [add_timed_unit_leader_trait](/wiki/effect/add_timed_unit_leader_trait):类似 add_trait,但可给满足能力条件的将领附加临时增益,适合设计限时激活的技能强化效果。
  • [is_corps_commander](/wiki/trigger/is_corps_commander) / [is_field_marshal](/wiki/trigger/is_field_marshal):能力归属于特定指挥官类型,联用此类 trigger 可避免在错误的领导者 scope 下误触判断。

常见坑

  1. Scope 错误has_ability 只在 CHARACTER scope 下有效,若在 country 或 state scope 中直接使用会导致脚本静默失败或报错,必须先通过 any_army_leaderrandom_army_leader 等方式进入正确的角色 scope。
  2. 能力 key 拼写依赖游戏文件:ability 的标识符来自 unit_leader_abilities 的定义,并非特质名,新手容易将特质名与能力名混淆,导致条件永远无法为真,需在 /common/unit_leader_abilities/ 目录下核实准确的 key。

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_ability is commonly used to check whether a specific leader has unlocked a particular active ability, thereby deciding whether to trigger subsequent events or special effects—for example, granting additional bonuses to leaders possessing the "force attack" ability. In mods featuring custom leader progression systems, it can also be used to restrict certain traits so that only leaders who have mastered specific abilities can acquire them.

# Only allow adding a trait if the character has the force_attack ability
if = {
    limit = {
        has_ability = force_attack
    }
    add_unit_leader_trait = aggressive_assaulter
}

Synergy

  • [has_trait](/wiki/trigger/has_trait): Typically used in conjunction with has_ability—first check whether the leader holds a specific trait, then verify whether they have unlocked the corresponding active ability. Together, they establish a more precise conditional threshold.
  • [add_trait](/wiki/effect/add_trait): After confirming the leader possesses a certain ability, use this effect to grant a new trait, forming an advanced logic chain of "ability unlocks trait".
  • [add_timed_unit_leader_trait](/wiki/effect/add_timed_unit_leader_trait): Similar to add_trait, but applies a temporary bonus to leaders meeting ability conditions, suitable for designing time-limited skill enhancement effects.
  • [is_corps_commander](/wiki/trigger/is_corps_commander) / [is_field_marshal](/wiki/trigger/is_field_marshal): Abilities belong to specific commander types; using these triggers in conjunction avoids unintended judgment triggers under wrong leader scopes.

Common Pitfalls

  1. Scope Errors: has_ability is only valid within the CHARACTER scope. Using it directly in country or state scopes will cause script silent failures or errors. You must first enter the correct character scope via any_army_leader, random_army_leader, or similar constructs.
  2. Ability Key Spelling Dependency on Game Files: The ability identifier comes from definitions in unit_leader_abilities, not from trait names. Beginners often confuse trait names with ability names, causing conditions to never evaluate to true. Always verify the exact key in the /common/unit_leader_abilities/ directory.