Wiki

effect · every_state

Definition

  • Supported scope:any
  • Supported target:none

Description

Executes children effects on every State (or \"random_select_amount\" of random state if specified) that fulfills the \"limit\" trigger.
tooltip=key can be added to override tooltip title.
By default the effects are only displayed once, you may display them for each matching state with display_individual_scopes.
ex:
every_state = {
	tooltip = my_loc_key # Optional
	random_select_amount = 3 # Optional
	display_individual_scopes = yes # Optional - default = no
	... state scope effects ...
}

实战 · 配合 · 坑

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

实战用法

every_state 常用于 mod 中批量修改满足特定条件的地块,例如在事件触发时对所有被某国控制且驻有抵抗力量的州同时降低抵抗度,或在战后和平脚本里对胜利者核心的所有州进行移交。下面示例在某国的所有核心州(若尚未拥有)中批量添加核心归属并转移控制权:

# 在某国事件 option 中执行:
every_state = {
    limit = {
        is_core_of = ROOT
        NOT = { is_owned_by = ROOT }
    }
    add_core_of = ROOT
    set_state_controller_to = ROOT
}

也可结合 random_select_amount 随机选取若干州执行效果,适合随机事件场景:

every_state = {
    random_select_amount = 3
    limit = {
        is_on_continent = europe
        is_controlled_by = ROOT
    }
    add_resistance = -10
}

配合关系

  • is_core_of:在 limit 块中筛选目标州,确保只对特定国家的核心州执行效果,是最常见的过滤条件之一。
  • transfer_state_to:遍历满足条件的州后将其移交给目标国,典型用于和平会议后的领土重组脚本。
  • set_resistance:配合 every_state 批量重置占领区的抵抗等级,适合 mod 中触发大规模政治变动的场景。
  • add_building_construction:在所有符合条件的州批量开工建设,常见于工业化事件或国策完成后的奖励效果。

常见坑

  1. 忘记 limit 导致效果作用于全图所有州every_state 默认遍历游戏中存在的每一个州,若不加 limit 筛选,批量添加建筑或修改抵抗度等操作会影响全部州,造成性能问题甚至逻辑错误,务必在 limit 中明确约束范围。
  2. limit 内误用 effect 命令(或反之)limit 块只能写 trigger(条件判断),不能把 add_core_ofset_state_controller_to 等 effect 写进去;反过来,limit 外的执行体内不能写触发器判断,需要条件分支时应在执行体内用 if = { limit = { ... } } 嵌套。

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

every_state is commonly used in mods to batch-modify states that meet specific conditions — for example, reducing resistance across all states controlled by a country that have active resistance forces when an event fires, or transferring all of a victor's core states during a post-war peace script. The example below adds cores and transfers control for all of a country's core states that it does not yet own:

# Executed inside a country event option:
every_state = {
    limit = {
        is_core_of = ROOT
        NOT = { is_owned_by = ROOT }
    }
    add_core_of = ROOT
    set_state_controller_to = ROOT
}

You can also combine it with random_select_amount to apply effects to a random subset of states, which works well for randomized event scenarios:

every_state = {
    random_select_amount = 3
    limit = {
        is_on_continent = europe
        is_controlled_by = ROOT
    }
    add_resistance = -10
}

Synergy

  • is_core_of: Used inside a limit block to filter target states, ensuring effects only apply to a specific country's core states — one of the most common filtering conditions.
  • transfer_state_to: After iterating over qualifying states, transfers them to a target country; typically used in post-peace-conference territorial reorganization scripts.
  • set_resistance: Combined with every_state to bulk-reset resistance levels across occupied territories, useful in mod scenarios that trigger large-scale political upheaval.
  • add_building_construction: Queues construction in all qualifying states at once; commonly seen as a reward effect after industrial events or national focus completions.

Common Pitfalls

  1. Forgetting limit, causing the effect to apply to every state on the map: every_state iterates over every state in the game by default. Without a limit to narrow the scope, operations such as bulk-adding buildings or modifying resistance will affect all states, leading to performance issues or outright logic errors. Always explicitly constrain the target range inside limit.
  2. Using effect commands inside limit (or triggers outside it): The limit block only accepts triggers (condition checks) — effects such as add_core_of or set_state_controller_to must not be placed inside it. Conversely, trigger checks do not belong in the execution body outside limit; when conditional branching is needed there, nest it with if = { limit = { ... } }.