trigger · is_defender
Definition
- Supported scope:
COMBATANT - Supported target:
none
Description
check if defender side in combat
is_defenderCOMBATANTnonecheck if defender side in combat
实战内容由 AI 生成,并已对照 vanilla 命令词表校验 —— 请当作起点而非权威依据。上方的定义节才是游戏自带文档原文。
is_defender 常用于战斗事件或特殊战斗修正 mod 中,针对防御方触发专属效果或奖励,例如给防守方部队额外的战斗加成或特殊 AI 决策逻辑。在设计"主场防御"类 mod 时,也可用于区分进攻/防守方,给予不同的战斗事件选项。
# 战斗事件中:仅对防守方触发
combat_event = {
id = my_mod.1
trigger = {
is_defender = yes
is_winning = no
}
# 防守方处于劣势时触发...
}
is_defender 互为对立,常同时写在同一事件的不同选项中,分别处理进攻方与防守方的逻辑分支。is_defender 只在 COMBATANT scope 下有效,新手常误将其写在国家 scope(如 country_event 的顶层 trigger 块)中,导致脚本报错或永远返回 false,必须确保处于战斗相关的 scope 内才能正确求值。is_attacker = no 混淆:部分新手认为 is_attacker = no 等同于 is_defender = yes,但在某些特殊战斗状态下两者可能并不完全等价,建议明确使用 is_defender = yes 而非依赖取反逻辑来表达防守方意图。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.
is_defender is commonly used in combat events or specialized combat modifier mods to trigger exclusive effects or rewards for the defending side, such as providing defending units with additional combat bonuses or special AI decision logic. When designing "home turf defense" style mods, it can also be used to distinguish between attacking and defending sides, offering different combat event options.
# In combat events: trigger only for the defending side
combat_event = {
id = my_mod.1
trigger = {
is_defender = yes
is_winning = no
}
# Triggers when defending side is at a disadvantage...
}
is_defender and is commonly written in different options of the same event to handle separate logic branches for attacking and defending sides.is_defender is only valid within COMBATANT scope. Beginners often mistakenly write it in country scope (such as the top-level trigger block of country_event), causing script errors or always returning false. You must ensure you are within a combat-related scope for proper evaluation.is_attacker = no: Some beginners believe is_attacker = no is equivalent to is_defender = yes, but in certain special combat states the two may not be completely equivalent. It is recommended to explicitly use is_defender = yes rather than relying on negation logic to express defending side intentions.