Wiki

trigger · has_game_rule

Definition

  • Supported scope:any
  • Supported target:none

Description

Checks if a game rule is set to a particular option.
Example:
has_game_rule = {
	rule = GER_can_remilitarize_rhineland
	option = yes
}

实战 · 配合 · 坑

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

实战用法

has_game_rule 常用于根据房间规则动态调整 focus tree 可用性或 event 走向,例如让某个国策仅在"允许历史事件"规则开启时才可选。在多人联机 mod 中,也经常用它来检查是否开启了特定的平衡性选项,从而决定是否触发某段脚本逻辑。

# 仅当规则允许时,某个决议才可用
available = {
    has_game_rule = {
        rule = GER_can_remilitarize_rhineland
        option = GER_CAN_REMILITARIZE_RHINELAND_YES
    }
}

配合关系

  • [has_global_flag](/wiki/trigger/has_global_flag):常与 has_game_rule 并列放在同一 and 块中,一个检查规则设定,另一个确认某全局事件是否已触发,共同把守条件入口。
  • [is_historical_focus_on](/wiki/trigger/is_historical_focus_on):两者经常组合使用,用于区分"历史模式"与自定义规则之间的优先级,避免规则冲突。
  • [custom_trigger_tooltip](/wiki/trigger/custom_trigger_tooltip):将 has_game_rule 包裹其中,可以为玩家提供更友好的本地化提示,说明为何某功能被规则禁用。
  • [or](/wiki/trigger/or):当同一条件需要兼容多个规则选项时,用 or 包住多个 has_game_rule 块,逻辑更清晰。

常见坑

  1. option 值写错大小写或拼写option 字段必须与游戏规则文件(common/game_rules/)中定义的选项 token 完全一致,包括大小写;写成 yes/no 这类简写仅在规则选项本身就叫那个名字时才有效,切勿想当然地省略前缀。
  2. 在不存在该规则的版本/mod 环境中使用:如果引用的 rule 在当前 mod 或基础游戏中未定义,trigger 不会报错而是静默返回 false,导致条件块永远不满足,排查时极易被忽视;务必确认规则已在 common/game_rules/ 中正确注册。

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_game_rule is commonly used to dynamically adjust focus tree availability or event paths based on room rules. For example, you can make a specific focus available only when the "Allow Historical Events" rule is enabled. In multiplayer mods, it's frequently used to check whether specific balance options are enabled, thereby deciding whether to trigger certain script logic.

# A decision is available only when the rule permits it
available = {
    has_game_rule = {
        rule = GER_can_remilitarize_rhineland
        option = GER_CAN_REMILITARIZE_RHINELAND_YES
    }
}

Synergy

  • [has_global_flag](/wiki/trigger/has_global_flag): Often placed alongside has_game_rule in the same and block. One checks rule settings while the other confirms whether a global flag has been triggered, jointly guarding the condition gate.
  • [is_historical_focus_on](/wiki/trigger/is_historical_focus_on): Frequently combined with has_game_rule to distinguish priority between "historical mode" and custom rules, preventing rule conflicts.
  • [custom_trigger_tooltip](/wiki/trigger/custom_trigger_tooltip): Wrapping has_game_rule within it provides players with friendlier localized tooltips explaining why a feature is disabled by rules.
  • [or](/wiki/trigger/or): When a single condition needs to support multiple rule options, wrap multiple has_game_rule blocks with or for clearer logic.

Common Pitfalls

  1. Incorrect capitalization or spelling in the option value: The option field must exactly match the option token defined in the game rules file (common/game_rules/), including case sensitivity. Shortcuts like yes/no are only valid when the rule option itself is named that way; don't arbitrarily omit the prefix.
  2. Using the trigger in a version/mod environment where the rule doesn't exist: If the referenced rule is not defined in the current mod or base game, the trigger won't error but silently returns false, causing the condition block to never be satisfied. This is easily overlooked during debugging; always confirm that the rule is properly registered in common/game_rules/.