Wiki

effect · random_state_division

Definition

  • Supported scope:STATE
  • Supported target:CAPITAL

Description

Executes children effects on a random division that fulfill the "limit" trigger on a state. tooltip=key can be added to override tooltip title

实战 · 配合 · 坑

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

实战用法

random_state_division 常用于 mod 中对某个州内的随机一支部队执行特殊效果,例如战场事件触发时给某州的部队添加指挥官特质、削减组织度或更换模板。典型场景包括:某省份遭受轰炸后随机降低一支驻守部队的组织度,或剧本事件中随机为一支精锐部队授勋。

# STATE scope 下,对某州内满足条件的随机一支部队执行效果
random_state_division = {
    limit = {
        unit_strength > 0.5
    }
    set_unit_organization = 0.3
    tooltip = random_state_division_tt
}

上例在当前州内找到一支强度超过 50% 的部队,将其组织度设为 30%,并用自定义 tooltip key 覆盖提示标题。


配合关系

  • unit_strength:在 limit 块中按部队当前强度筛选目标,是最常见的过滤手段,避免效果作用到已近乎全灭的残部。
  • set_unit_organization:与本效果组合用于调整被选中部队的组织度,是 random_state_division 内部最高频使用的子命令。
  • add_divisional_commander_xp:在事件奖励场景中,对随机选中的部队所属指挥官增加经验值,实现"表彰某州英雄部队"的叙事效果。
  • custom_effect_tooltip:当实际执行的逻辑较复杂时,用来向玩家显示一条可读的说明文字,配合 tooltip=key 参数共同管理 UI 呈现。

常见坑

  1. Scope 用错random_state_division 只能在 STATE scope 下调用,如果当前 scope 是 COUNTRY 或 DIVISION,脚本会静默报错或无效果。需先通过 every_state / random_state 等进入州 scope,再调用本命令。

  2. limit 内混用 effect 命令:新手有时会把 set_unit_organizationdamage_units 写进 limit = { } 块,但 limit 只接受 trigger(如 unit_strengthis_unit_template_reserves),写入 effect 命令会导致解析错误或被游戏忽略,真正的执行逻辑必须写在 limit 块之外、random_state_division 的直接子块中。

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_state_division is commonly used in mods to apply special effects to a single random division within a given state — for example, granting a commander trait to a division when a battlefield event fires, reducing organization, or swapping a unit template. Typical scenarios include reducing the organization of a random garrison after a province is bombed, or awarding a decoration to a random elite division during a scripted event.

# Under STATE scope, apply an effect to one random division in the state that meets the condition
random_state_division = {
    limit = {
        unit_strength > 0.5
    }
    set_unit_organization = 0.3
    tooltip = random_state_division_tt
}

The example above finds one division in the current state with a strength above 50%, sets its organization to 30%, and overrides the tooltip header with a custom tooltip key.


Synergy

  • unit_strength: Used inside the limit block to filter targets by a division's current strength — the most common filtering method, preventing the effect from hitting nearly-destroyed remnants.
  • set_unit_organization: Combined with this effect to adjust the organization of the selected division; it is the most frequently used sub-command inside random_state_division.
  • add_divisional_commander_xp: In event reward scenarios, grants experience to the commander of the randomly selected division, achieving a narrative effect of "commending the heroic division of a state."
  • custom_effect_tooltip: When the underlying logic is complex, this displays a human-readable description to the player, working alongside the tooltip=key parameter to manage UI presentation.

Common Pitfalls

  1. Wrong scope: random_state_division can only be called under a STATE scope. If the current scope is COUNTRY or DIVISION, the script will fail silently or produce no effect. You must first enter a state scope via every_state, random_state, or similar before calling this command.

  2. Mixing effect commands inside limit: Beginners sometimes write set_unit_organization or damage_units inside the limit = { } block, but limit only accepts triggers (such as unit_strength or is_unit_template_reserves). Placing effect commands there will cause a parse error or be silently ignored by the game. All actual execution logic must be written outside the limit block, as direct children of random_state_division.