Wiki

effect · random_owned_state

Definition

  • Supported scope:COUNTRY
  • Supported target:none

Description

Executes children effects on random owned state that fulfills the "limit" trigger. 
prioritize = { <stateID> <stateID> } to pick those states first if they fulfull the limit

实战 · 配合 · 坑

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

实战用法

random_owned_state 常用于需要在玩家/AI所有州中随机挑选一个执行操作的场景,例如随机为一个本国州添加建设项目、随机爆发抵抗活动,或在某类满足条件的州中随机触发事件。prioritize 子块可以让开发者优先考虑特定州,避免完全随机带来的不可控性。

# 随机在一个拥有工厂槽位且位于欧洲的州中添加基础设施建设
random_owned_state = {
    prioritize = { 11 12 13 }
    limit = {
        is_on_continent = europe
        free_building_slots = {
            building = infrastructure
            size > 0
        }
    }
    add_building_construction = {
        type = infrastructure
        level = 1
        instant_build = no
    }
}

配合关系

  • is_on_continent — 在 limit 内限定只筛选特定大洲的州,避免效果扩散至全球领土。
  • free_building_slots — 在 limit 内判断州是否有剩余建设槽,确保 add_building_construction 可以合法执行。
  • add_building_construction — 最常见的子效果,在随机命中的州中触发建设任务。
  • set_state_flag — 给随机选中的州打旗帜,防止同一事件链中重复命中同一州(配合 [has_state_flag](/wiki/trigger/has_state_flag) 做排除)。

常见坑

  1. 忘记 limit 会导致在任意州触发:若不写 limit 块,游戏会从所有拥有州中完全随机选取,包括核心工业区、傀儡州等不应被影响的州,容易造成非预期结果;务必用 limit 精确约束目标范围。
  2. scope 混淆导致子效果报错random_owned_state 执行后内部 scope 已切换至 STATE,不能在其内部直接调用 COUNTRY scope 专属的效果(如 add_ideas),需要用 owner = { ... } 等方式显式跳回 COUNTRY scope 再执行。

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

random_owned_state is commonly used when you need to randomly pick one state from all states owned by a country (player or AI) and perform an operation on it — for example, randomly adding a construction project to one of your states, triggering a resistance event in a random state, or firing an event in whichever state meets a given condition. The prioritize sub-block lets developers bias the selection toward specific states, reducing the unpredictability of pure randomness.

# Randomly add an infrastructure construction project in one European state that has available building slots
random_owned_state = {
    prioritize = { 11 12 13 }
    limit = {
        is_on_continent = europe
        free_building_slots = {
            building = infrastructure
            size > 0
        }
    }
    add_building_construction = {
        type = infrastructure
        level = 1
        instant_build = no
    }
}

Synergy

  • is_on_continent — Use inside limit to restrict selection to states on a specific continent, preventing the effect from spreading across your entire global territory.
  • free_building_slots — Use inside limit to check whether a state has remaining building slots, ensuring add_building_construction can legally execute.
  • add_building_construction — The most common child effect; triggers a construction task in whichever state is randomly selected.
  • set_state_flag — Flags the randomly chosen state to prevent the same state from being hit multiple times within the same event chain (use alongside has_state_flag to exclude already-flagged states).

Common Pitfalls

  1. Omitting limit causes the effect to fire on any state: Without a limit block, the game picks completely at random from all owned states, including core industrial regions, puppet states, and other states that should not be affected — leading to unintended results. Always use limit to precisely constrain the target pool.
  2. Scope confusion causes child effects to error: Once random_owned_state executes, the internal scope switches to STATE. You cannot directly call effects that belong exclusively to COUNTRY scope (such as add_ideas) inside it. Use owner = { ... } or a similar construct to explicitly jump back to COUNTRY scope before executing such effects.