Wiki

effect · random_country

Definition

  • Supported scope:any
  • Supported target:none

Description

Executes children effects on random country that fulfills the "limit" trigger.

实战 · 配合 · 坑

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

实战用法

random_country 常用于事件或决议效果中,需要对一个满足条件的随机国家执行操作,例如在战争爆发时随机挑选一个中立小国施加威胁值,或随机选一个敌对国家发出外交警告。它与 every_country 的区别在于只作用于其中一个随机目标,适合"抽签式"效果。

# 示例:某事件触发后,随机选择一个存在且非主要国家的国家增加威胁值
country_event = {
    id = my_mod.1
    immediate = {
        random_country = {
            limit = {
                exists = yes
                is_major = no
                has_war = no
            }
            add_named_threat = {
                threat = 2
                name = my_mod_threat_key
            }
        }
    }
}

配合关系

  • exists:几乎必须放在 limit 内,防止脚本对已经亡国的标签执行效果导致报错。
  • has_war:在 limit 中筛选是否处于战争状态,精确控制随机池范围。
  • is_in_faction:配合使用可将随机目标限定为派系内/外的国家,常见于联盟相关事件。
  • country_event:选出随机国家后,向其发送事件,实现"通知随机一方"的剧情链。

常见坑

  1. 忘记写 limit 导致随机池过大:不加任何限制时,random_country 会把所有已定义的国家标签(含未生成的国家)纳入随机池,极易触发对不存在国家执行效果的报错;至少应加 exists = yes 作为最低门槛。
  2. 误以为 scope 会自动切换到被选中国家random_country 的子块内 scope 已经是被选中的随机国家,若在子块内再用 ROOT / PREV 引用原始国家时需明确写出,否则效果会错误地叠加在随机国家自身上而非预期目标。

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_country is commonly used in event or decision effects when you need to perform an operation on a single qualifying country chosen at random — for example, applying a threat value to a random neutral minor when a war breaks out, or sending a diplomatic warning to a randomly selected hostile nation. The key difference from every_country is that it acts on only one randomly picked target, making it ideal for "lottery-style" effects.

# Example: after an event fires, randomly select a country that exists, is not a major, and is not at war, then add threat
country_event = {
    id = my_mod.1
    immediate = {
        random_country = {
            limit = {
                exists = yes
                is_major = no
                has_war = no
            }
            add_named_threat = {
                threat = 2
                name = my_mod_threat_key
            }
        }
    }
}

Synergy

  • exists: Almost always required inside limit to prevent the script from executing effects on a tag that no longer exists, which would cause errors.
  • has_war: Use inside limit to filter by whether a country is currently at war, giving you precise control over the random pool.
  • is_in_faction: Combine with this to restrict the random target to countries inside or outside a specific faction — commonly seen in alliance-related events.
  • country_event: After a random country is selected, fire an event targeting it to implement a "notify a random party" narrative chain.

Common Pitfalls

  1. Forgetting limit and ending up with an oversized random pool: Without any restrictions, random_country includes every defined country tag in the pool — even tags for countries that have never spawned — making it very easy to trigger errors from effects applied to non-existent countries. At a minimum, always add exists = yes as a baseline guard.
  2. Assuming the scope does not automatically switch to the selected country: Inside the random_country block the scope is already the randomly selected country. If you need to reference the original country within that block, you must explicitly use ROOT or PREV; otherwise your effects will be applied to the random country itself rather than the intended target.