Wiki

trigger · has_dynamic_modifier

Definition

  • Supported scope:STATE, COUNTRY, CHARACTER
  • Supported target:THIS, ROOT, PREV, FROM, OWNER, CONTROLLER, OCCUPIED, CAPITAL

Description

Checks if scope has a dynamic modifier.

### Example 1

has_dynamic_modifier = dynamic_modifier_name


### Example 2

has_dynamic_modifier = { modifier = dynamic_modifier_name scope = GER #optional, if the original modifier has been targeted }

实战 · 配合 · 坑

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

实战用法

has_dynamic_modifier 常用于检测某个国家、州或角色当前是否附带了特定的动态修正器,从而决定后续 focus/decision/event 的可用性或触发条件。例如,在一个经济危机系统中,只有当国家已被施加"经济崩溃"动态修正器时,才允许玩家触发救援决议:

available = {
    has_dynamic_modifier = economic_collapse_modifier
}

若该修正器带有 target scope(即创建时指定了目标国家),则需要使用带 scope 字段的写法来精确匹配:

trigger = {
    has_dynamic_modifier = {
        modifier = foreign_pressure_modifier
        scope = USA
    }
}

配合关系

  • [add_dynamic_modifier](/wiki/effect/add_dynamic_modifier):添加动态修正器的效果命令,通常先用它施加修正器,再用 has_dynamic_modifier 检测是否已存在,避免重复叠加。
  • [remove_dynamic_modifier](/wiki/effect/remove_dynamic_modifier):当条件满足时移除修正器,has_dynamic_modifier 作为前置检查确保移除操作不会在修正器不存在时报错或产生意外行为。
  • [force_update_dynamic_modifier](/wiki/effect/force_update_dynamic_modifier):动态修正器的变量值发生改变后需要强制刷新,配合 has_dynamic_modifier 可以在确认修正器存在的前提下再调用刷新,逻辑更严谨。
  • [has_active_mission](/wiki/trigger/has_active_mission):在复杂任务系统中,常同时检测动态修正器与激活任务的状态,以判断某一游戏阶段是否真正生效。

常见坑

  1. 忘记指定 scope 字段导致匹配失败:如果 add_dynamic_modifier 创建时带了 scope = TAG,那么 has_dynamic_modifier 也必须用带 scope 的写法,否则即使修正器存在也会返回假,新手常以为修正器没有被正确添加而反复排查添加逻辑。
  2. 在错误的 scope 下使用:该 trigger 只在 STATE、COUNTRY、CHARACTER 三种 scope 下有效,若在其他 scope(如 unit leader 的某些子块)中直接调用,脚本不会报语法错误但始终返回假,导致难以察觉的逻辑 bug。

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_dynamic_modifier is commonly used to check whether a specific country, state, or character currently has a particular dynamic modifier attached, which determines the availability or trigger conditions of subsequent focuses, decisions, or events. For example, in an economic crisis system, players can only trigger a relief decision if the country has been assigned the "economic_collapse_modifier" dynamic modifier:

available = {
    has_dynamic_modifier = economic_collapse_modifier
}

If the modifier has a target scope (i.e., a target country was specified during creation), use the syntax with the scope field to match precisely:

trigger = {
    has_dynamic_modifier = {
        modifier = foreign_pressure_modifier
        scope = USA
    }
}

Synergy

  • [add_dynamic_modifier](/wiki/effect/add_dynamic_modifier): The effect command for adding dynamic modifiers; typically use this to apply a modifier first, then use has_dynamic_modifier to check if it already exists, avoiding redundant stacking.
  • [remove_dynamic_modifier](/wiki/effect/remove_dynamic_modifier): When conditions are met, remove the modifier. has_dynamic_modifier serves as a precondition check to ensure the removal operation doesn't cause errors or unexpected behavior if the modifier doesn't exist.
  • [force_update_dynamic_modifier](/wiki/effect/force_update_dynamic_modifier): When dynamic modifier variable values change, a forced refresh is required. Combined with has_dynamic_modifier, you can confirm the modifier exists before calling the refresh, making the logic more robust.
  • [has_active_mission](/wiki/trigger/has_active_mission): In complex mission systems, dynamic modifier and active mission states are often checked simultaneously to determine whether a particular game phase is truly in effect.

Common Pitfalls

  1. Forgetting to specify the scope field causes matching to fail: If add_dynamic_modifier was created with scope = TAG, then has_dynamic_modifier must also use the syntax with scope, otherwise it will return false even if the modifier exists. Beginners often mistakenly assume the modifier wasn't properly added and repeatedly troubleshoot the addition logic.
  2. Using in the wrong scope: This trigger only works under STATE, COUNTRY, and CHARACTER scopes. If called directly in other scopes (such as certain sub-blocks in unit leaders), the script won't produce a syntax error but will always return false, resulting in hard-to-detect logic bugs.