Wiki

trigger · any_neighbor_state

Definition

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

Description

check if any neighbor state meets the trigger. tooltip=key can be defined to override title

实战 · 配合 · 坑

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

实战用法

any_neighbor_state 常用于领土扩张、战略规划类 mod 中,检测某州是否与敌方/友方控制的州接壤,从而触发事件或解锁决议。例如判断某州的邻接州中是否有被特定国家拥有的州,以决定是否允许执行入侵决议。

# 决议的 available 块:仅当目标州有邻接州被敌国拥有时才可用
available = {
    any_neighbor_state = {
        is_owned_by = ROOT
    }
}
# 在 state 作用域的 trigger 中,检测邻接州是否满足复合条件
any_neighbor_state = {
    is_controlled_by = GER
    is_coastal = yes
}

配合关系

  • all_neighbor_stateany_neighbor_state 验证"至少一个"邻州满足条件,all_neighbor_state 验证"所有"邻州都满足,两者语义互补,常成对出现于领土判断逻辑中。
  • every_neighbor_state:触发条件用 any_neighbor_state 确认存在符合条件的邻州后,再用 every_neighbor_state 对所有满足条件的邻州批量执行 effect,形成"判断→执行"组合。
  • random_neighbor_state:在已知至少一个邻州满足条件(由 any_neighbor_state 保证)的前提下,用 random_neighbor_state 随机抽取其中一个执行效果,避免空抽。
  • is_owned_by:最常见的内层条件,配合 any_neighbor_state 检测邻接州的归属国,是边境冲突、吞并前置判断的核心搭配。

常见坑

  1. 作用域错误any_neighbor_state 只能在 STATE scope 下使用。若当前 scope 是国家(COUNTRY),必须先通过 capital_scope 等方式切换到州 scope,否则脚本会静默失败或报错。
  2. 内层条件 scope 混淆any_neighbor_state 的花括号内部 scope 已自动切换为邻接州(STATE),不需要也不能再手动切换 scope;新手常误将国家级 trigger(如 has_war = yes)直接写在内层,导致条件判断逻辑错误。

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

any_neighbor_state is commonly used in territory-expansion and strategic-planning mods to check whether a state borders one controlled by a friendly or hostile country, thereby triggering events or unlocking decisions. A typical use case is checking whether any neighbor of a given state is owned by a specific nation in order to gate an invasion decision.

# Decision's available block: only usable when the target state has a neighbor owned by ROOT
available = {
    any_neighbor_state = {
        is_owned_by = ROOT
    }
}
# Inside a trigger scoped to a state, check whether any neighbor meets a compound condition
any_neighbor_state = {
    is_controlled_by = GER
    is_coastal = yes
}

Synergy

  • all_neighbor_state: any_neighbor_state checks that at least one neighboring state meets the condition, while all_neighbor_state requires every neighboring state to meet it. The two are semantically complementary and frequently appear together in territorial logic.
  • every_neighbor_state: A common pattern is to use any_neighbor_state to confirm that at least one qualifying neighbor exists, then use every_neighbor_state to apply an effect to all matching neighbors — a clean "check → execute" combination.
  • random_neighbor_state: Once any_neighbor_state has guaranteed that at least one qualifying neighbor exists, random_neighbor_state can safely pick one at random to apply an effect to, avoiding an empty draw.
  • is_owned_by: The most frequently used inner condition alongside any_neighbor_state. Checking which country owns a neighboring state is the core building block for border-conflict and pre-annexation logic.

Common Pitfalls

  1. Wrong scope: any_neighbor_state can only be used inside a STATE scope. If the current scope is a country (COUNTRY), you must first switch to a state scope — for example via capital_scope — otherwise the script will silently fail or throw an error.
  2. Inner scope confusion: Inside the curly braces of any_neighbor_state, the scope is automatically set to the neighboring state (STATE). You do not need to — and must not — manually switch scope again. A common beginner mistake is writing country-level triggers such as has_war = yes directly inside the inner block, which produces incorrect logic.