Wiki

trigger · is_attacker

Definition

  • Supported scope:COMBATANT
  • Supported target:none

Description

check if attacker side in combat

实战 · 配合 · 坑

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

实战用法

is_attacker 常用于战斗事件或战斗修正器中,根据当前部队是进攻方还是防守方来施加不同的效果或条件判断。例如,在自定义战斗 modifier mod 里,可以让进攻方在特定地形获得额外士气加成,或在特定 focus/决策链中只对进攻战斗触发某段文本。

# 战斗事件中:只对进攻方触发特殊对话选项
combat_event = {
    id = my_mod.1
    trigger = {
        is_attacker = yes
        is_fighting_in_terrain = { terrain = forest }
    }
    ...
}

配合关系

  • is_defender:与 is_attacker 互为对立,通常成对出现以覆盖进攻/防守两种分支逻辑,避免条件遗漏。
  • is_fighting_in_terrain:配合地形判断,实现"进攻方在山地/河流作战时"的精细条件,常用于地形惩罚类 mod。
  • is_winning:结合胜负判断,可描述"进攻方且正在占优"的复合条件,用于触发战斗推进类事件。
  • phase:配合战斗阶段判断,区分进攻方在不同战斗阶段(如突破阶段)的行为触发时机。

常见坑

  1. Scope 用错is_attacker 只能在 COMBATANT(战斗参与方)scope 下使用,若写在国家或将领 scope 中会静默失败或报错,新手容易将其误放在 division_leader 或顶层国家 scope 里。
  2. 逻辑取反误解is_attacker = no 并不等同于"是防守方"——当该单位不在任何战斗中时,两者均可能返回 no,应搭配 is_defender = yes 明确判断,而非单纯对 is_attacker 取反。

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

is_attacker is commonly used in combat events or combat modifiers to apply different effects or conditional logic based on whether the current unit is attacking or defending. For example, in a custom combat modifier mod, you can grant the attacking side additional morale bonuses in specific terrain, or trigger certain text blocks only for attacking combats within specific focus/decision chains.

# In combat events: trigger special dialogue options only for the attacking side
combat_event = {
    id = my_mod.1
    trigger = {
        is_attacker = yes
        is_fighting_in_terrain = { terrain = forest }
    }
    ...
}

Synergy

  • is_defender: Forms a mutually exclusive pair with is_attacker, typically used together to cover both attacking and defending branches, preventing logical gaps.
  • is_fighting_in_terrain: Combined with terrain checks to implement fine-grained conditions like "attacking side fighting in mountains/rivers", commonly used in terrain penalty mods.
  • is_winning: Combined with victory condition checks to describe compound conditions such as "attacking and winning", used to trigger combat advancement events.
  • phase: Paired with combat phase checks to differentiate when attacking side behaviors trigger across different combat phases (e.g., breakthrough phase).

Common Pitfalls

  1. Wrong Scope: is_attacker can only be used within COMBATANT (combat participant) scope. Placing it in country or commander scopes will silently fail or throw errors—newcomers often mistakenly put it in division_leader or top-level country scope.
  2. Logic Inversion Misunderstanding: is_attacker = no does not equate to "is defending"—when the unit is not in any combat, both can return no. You should pair it with is_defender = yes for explicit checking, rather than simply negating is_attacker.