effect · random_country
Definition
- Supported scope:
any - Supported target:
none
Description
Executes children effects on random country that fulfills the "limit" trigger.
random_countryanynoneExecutes 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
}
}
}
}
limit 内,防止脚本对已经亡国的标签执行效果导致报错。limit 中筛选是否处于战争状态,精确控制随机池范围。limit 导致随机池过大:不加任何限制时,random_country 会把所有已定义的国家标签(含未生成的国家)纳入随机池,极易触发对不存在国家执行效果的报错;至少应加 exists = yes 作为最低门槛。random_country 的子块内 scope 已经是被选中的随机国家,若在子块内再用 ROOT / PREV 引用原始国家时需明确写出,否则效果会错误地叠加在随机国家自身上而非预期目标。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.
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
}
}
}
}
limit to prevent the script from executing effects on a tag that no longer exists, which would cause errors.limit to filter by whether a country is currently at war, giving you precise control over the random pool.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.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.