Wiki

effect · random_character

Definition

  • Supported scope:COUNTRY
  • Supported target:none

Description

Executes children effects on random characters that fulfills the "limit" trigger. tooltip=key can be added to override tooltip title

实战 · 配合 · 坑

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

实战用法

random_character 常用于需要对国家内随机一名符合条件的角色执行一次性操作的场景,例如在事件中随机给一名将领添加特质、随机晋升一名顾问,或为随机一名特工执行状态变更。相比 every_character(作用于所有符合者),它只影响其中一个,适合"抽签式"叙事设计。

# 示例:随机选取一名陆军指挥官,给其添加一个特质
random_character = {
    limit = {
        is_army_leader = yes
        has_trait = old_guard
    }
    add_trait = brilliant_strategist
}

配合关系

  • is_army_leader / is_corps_commander:在 limit 块中用于筛选角色兵种身份,确保操作只命中目标类型的将领。
  • has_trait:在 limit 中进一步过滤拥有特定特质的角色,避免重复赋予或产生冲突。
  • add_trait / remove_trait:最常见的子效果,对随机命中的角色增减特质。
  • set_character_flag:对命中角色打上标记,配合后续 has_character_flag 条件防止同一角色被重复选中。

常见坑

  1. 忘记写 limit 导致范围过宽:不加 limit 时会从国家内所有角色(包括顾问、间谍等)中随机选取,执行效果可能命中意料之外的角色;务必在 limit 内用 is_army_leaderis_operative 等触发器精确限定范围。
  2. 误以为会遍历执行random_character 只对恰好一个符合条件的角色生效,若需对所有符合条件的角色统一操作,应改用 every_character(但该命令需确认在当前白名单可用,若无则拆分处理),切勿用 random_character 循环来模拟"全选"行为。

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_character is commonly used when you need to perform a one-time operation on a single randomly selected character within a country — for example, adding a trait to a random general during an event, randomly promoting an advisor, or changing the status of a random operative. Unlike every_character (which affects all matching characters), it only targets one, making it well-suited for "lottery-style" narrative design.

# Example: randomly select an army commander and add a trait to them
random_character = {
    limit = {
        is_army_leader = yes
        has_trait = old_guard
    }
    add_trait = brilliant_strategist
}

Synergy

  • is_army_leader / is_corps_commander: Used inside the limit block to filter characters by their military role, ensuring the operation only targets the intended type of commander.
  • has_trait: Further narrows the pool inside limit to characters with a specific trait, preventing duplicate assignment or conflicting results.
  • add_trait / remove_trait: The most common child effects — add or remove traits on whichever character is randomly selected.
  • set_character_flag: Stamps the selected character with a flag, which can then be checked via has_character_flag in subsequent conditions to prevent the same character from being picked again.

Common Pitfalls

  1. Forgetting limit, causing an overly broad scope: Without a limit block, the scope draws from all characters in the country — including advisors, operatives, and others — so the effect may land on an unintended character. Always use triggers such as is_army_leader or is_operative inside limit to precisely restrict the candidate pool.
  2. Mistaking it for an iterating effect: random_character affects exactly one matching character. If you need to apply an operation to every qualifying character, use every_character instead (verify it is available in your current whitelist; if not, handle the cases separately). Never loop random_character in an attempt to simulate "select all" behavior.