effect · random_neighbor_country
Definition
- Supported scope:
COUNTRY - Supported target:
none
Description
Executes children effects on random neighbor country that fulfills the "limit" trigger.
random_neighbor_countryCOUNTRYnoneExecutes children effects on random neighbor country that fulfills the "limit" trigger.
实战内容由 AI 生成,并已对照 vanilla 命令词表校验 —— 请当作起点而非权威依据。上方的定义节才是游戏自带文档原文。
random_neighbor_country 常用于触发外交连锁效果,例如让某国在随机一个邻国传播意识形态、发起战争目标,或给周边国家施加威胁。配合 limit 块可以筛选只对满足特定条件的邻国生效,避免误伤同阵营或已处于战争状态的国家。
# 示例:某国对一个随机的、尚未开战的邻国创建吞并战争目标
country_event = {
id = my_mod.1
immediate = {
random_neighbor_country = {
limit = {
NOT = { has_war_with = ROOT }
NOT = { is_in_faction = yes }
exists = yes
}
create_wargoal = {
type = annex_everything
target = ROOT
}
}
}
}
random_neighbor_country 的筛选逻辑形成互补校验。limit 中用于排除已经处于战争状态的邻国,避免重复对战争目标操作。limit 中过滤掉已加入阵营的邻国,使效果只作用于中立或敌对势力。limit 导致效果作用于意外目标:random_neighbor_country 会在所有直接陆地/海洋边境邻国中随机选择,若不加 limit 过滤,可能命中已灭亡(exists = no)或已是同盟(is_ally_with = ROOT)的国家,导致脚本报错或产生非预期行为,至少应加 exists = yes 作为基础过滤。ROOT 与当前 scope 混淆:进入 random_neighbor_country 块后,当前 scope 切换为被选中的邻国,ROOT 才是触发该 effect 的原始国家;新手常在块内直接用命令意图操作原始国家,却忘记加 ROOT = { ... } 包裹,造成效果施加方向反转。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_neighbor_country is commonly used to trigger cascading diplomatic effects — for example, having a country spread its ideology to a random neighbor, create wargoals against nearby nations, or impose threat on surrounding countries. Pairing it with a limit block lets you filter for neighbors that meet specific conditions, preventing unintended effects on faction members or countries already at war.
# Example: a country creates an annex wargoal against a random neighbor that is not already at war with it
country_event = {
id = my_mod.1
immediate = {
random_neighbor_country = {
limit = {
NOT = { has_war_with = ROOT }
NOT = { is_in_faction = yes }
exists = yes
}
create_wargoal = {
type = annex_everything
target = ROOT
}
}
}
}
random_neighbor_country with an additional cross-check.limit to exclude neighbors already at war, preventing duplicate operations on existing wargoal targets.limit to filter out neighbors that have already joined a faction, so the effect only applies to neutral or hostile powers.limit and hitting unintended targets: random_neighbor_country selects randomly from all direct land/sea border neighbors. Without a limit filter, it may land on a country that no longer exists (exists = no) or is already an ally (is_ally_with = ROOT), causing script errors or unintended behavior. At a minimum, always include exists = yes as a baseline filter.ROOT with the current scope inside the block: Once execution enters the random_neighbor_country block, the current scope switches to the selected neighbor — ROOT is the country that originally triggered the effect. A common beginner mistake is writing commands inside the block intending to affect the original country, but forgetting to wrap them in ROOT = { ... }, which reverses the direction of the effect entirely.