Wiki

trigger · has_opinion_modifier

Definition

  • Supported scope:COUNTRY
  • Supported target:none

Description

check if a country has the opinion modifier

实战 · 配合 · 坑

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

实战用法

has_opinion_modifier 常用于判断外交关系是否已进入特定阶段,例如检查某国是否已对玩家施加了"不信任"或"友好协议"等舆论修正,从而决定后续外交事件或决议是否可用。在制作外交链条 mod 时,可以用它来防止重复添加同名修正,或作为解锁高级合作选项的前置条件。

# 示例:只有目标国尚未拥有"贸易协定"舆论修正时,才允许触发该决议
available = {
    FROM = {
        NOT = {
            has_opinion_modifier = {
                modifier = trade_agreement_bonus
                target = ROOT
            }
        }
    }
}

配合关系

  • [add_opinion_modifier](/wiki/effect/add_opinion_modifier) — 最直接的搭档:先用 has_opinion_modifier 检查修正是否存在,避免重复叠加同名修正导致逻辑混乱。
  • [add_opinion_modifier](/wiki/effect/add_opinion_modifier) 的反向操作对应触发侧常与 [has_country_flag](/wiki/trigger/has_country_flag) 联用 — 用国家旗标记录外交状态,配合舆论修正共同构成"已处理过"的双重保险判断。
  • [has_dynamic_modifier](/wiki/trigger/has_dynamic_modifier) — 同样用于检查某种附加状态是否存在,两者常在同一 trigger 块内并列,共同描述完整的外交或关系状态条件。
  • [has_relation_modifier](/wiki/trigger/has_relation_modifier) — 在白名单外,但逻辑上… (注:白名单中无此 trigger,故不列入) — 改用 [has_country_flag](/wiki/trigger/has_country_flag) 作为补充判断,标记双边关系阶段。

常见坑

  1. 忘记指定 target 字段has_opinion_modifier 通常需要同时写明 modifier(修正名)和 target(被施加修正的对象),如果只写修正名而遗漏 target,脚本可能报错或始终返回假,新手常以为 trigger 本身有问题。
  2. 修正名与 add_opinion_modifier 中的定义名不一致:opinion modifier 必须在 /common/opinion_modifiers/ 中预先定义,has_opinion_modifier 里填写的名称必须与定义文件中的 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_opinion_modifier is commonly used to determine whether diplomatic relations have entered a specific phase, such as checking whether a country has imposed an "distrust" or "friendly agreement" opinion modifier on the player, thereby deciding whether subsequent diplomatic events or decisions should be available. When creating diplomatic chain mods, you can use it to prevent duplicate additions of same-named modifiers, or as a prerequisite condition for unlocking advanced cooperation options.

# Example: Only allow triggering this decision if the target country does not yet have the "trade_agreement_bonus" opinion modifier
available = {
    FROM = {
        NOT = {
            has_opinion_modifier = {
                modifier = trade_agreement_bonus
                target = ROOT
            }
        }
    }
}

Synergy

  • [add_opinion_modifier](/wiki/effect/add_opinion_modifier) — The most direct companion: use has_opinion_modifier first to check whether the modifier exists, avoiding duplicate stacking of same-named modifiers that could cause logic confusion.
  • The reverse operation of [add_opinion_modifier](/wiki/effect/add_opinion_modifier) on the trigger side often works in conjunction with [has_country_flag](/wiki/trigger/has_country_flag) — use country flags to record diplomatic status, and combine with opinion modifiers to form a double-check judgment for "already processed" states.
  • [has_dynamic_modifier](/wiki/trigger/has_dynamic_modifier) — similarly used to check whether a certain attached status exists; both are often listed in parallel within the same trigger block to jointly describe complete diplomatic or relationship state conditions.
  • [has_relation_modifier](/wiki/trigger/has_relation_modifier) — outside the whitelist, but logically… (Note: this trigger is not in the whitelist, so not listed) — instead use [has_country_flag](/wiki/trigger/has_country_flag) as a supplementary judgment to mark bilateral relationship phases.

Common Pitfalls

  1. Forgetting to specify the target field: has_opinion_modifier typically requires both modifier (the modifier name) and target (the object being given the modifier) to be specified. If only the modifier name is written and target is omitted, the script may error or always return false. Beginners often mistakenly think the trigger itself has a problem.
  2. Modifier name inconsistency with the definition in add_opinion_modifier: opinion modifiers must be predefined in /common/opinion_modifiers/ first. The name filled in has_opinion_modifier must exactly match the key in the definition file (case-sensitive). Minor spelling differences will cause the judgment to always return false with no error message.