Wiki

effect · add_random_trait

Definition

  • Supported scope:CHARACTER
  • Supported target:none

Description

add random trait from specified list to unit leader. add_random_trait = { old_guard brilliant_strategist inflexible_strategist }

实战 · 配合 · 坑

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

实战用法

add_random_trait 常用于角色随机成长系统或历史事件中,为将领赋予不确定性特质,增加游戏可重玩性。例如在"晋升将领"事件中,从多个候选特质里随机挑选一个,避免每局结果固定。

# 在某个将领晋升事件的 option 块中
character_event = {
    id = my_mod.10
    option = {
        name = my_mod.10.a
        # 当前 scope 已是 CHARACTER
        add_random_trait = {
            old_guard
            brilliant_strategist
            inflexible_strategist
        }
    }
}

配合关系

  • [has_trait](/wiki/trigger/has_trait) — 在添加随机特质前先检查角色是否已持有某特质,避免重复叠加冲突特质。
  • [add_skill_level](/wiki/effect/add_skill_level) — 随机特质往往与技能提升同步触发,共同模拟将领的综合成长。
  • [add_trait](/wiki/effect/add_trait) — 当需要确定性赋予某特质(而非随机)时作为补充手段,两者搭配可实现"保底+随机"组合逻辑。
  • [can_select_trait](/wiki/trigger/can_select_trait) — 在执行前验证目标角色是否满足选取特质的条件,防止因特质互斥而触发报错或静默失败。

常见坑

  1. 列表内填写了不存在或拼写错误的特质 key:游戏不会崩溃但会静默跳过该条目,导致实际随机池与预期不符,需在 common/unit_leader 相关文件中逐一核对特质定义名称。
  2. 在非 CHARACTER scope 下调用:若当前 scope 是 COUNTRY 或 STATE,效果不会生效,新手容易在 country 级事件中忘记用 any_character / 具名角色将 scope 切换到 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

add_random_trait is commonly used in character progression systems or historical events to assign random traits to generals, adding unpredictability and replayability. For example, in a "promote general" event, you can randomly select one trait from multiple candidates instead of having the same outcome every game.

# In an option block within a general promotion event
character_event = {
    id = my_mod.10
    option = {
        name = my_mod.10.a
        # Current scope is already CHARACTER
        add_random_trait = {
            old_guard
            brilliant_strategist
            inflexible_strategist
        }
    }
}

Synergy

  • [has_trait](/wiki/trigger/has_trait) — Check whether the character already has a trait before adding a random one to avoid duplicate or conflicting traits.
  • [add_skill_level](/wiki/effect/add_skill_level) — Random traits often trigger alongside skill increases to simulate a general's overall development.
  • [add_trait](/wiki/effect/add_trait) — Use as a complement when you need to assign a specific trait deterministically (rather than randomly); combining both enables a "guaranteed + random" logic pattern.
  • [can_select_trait](/wiki/trigger/can_select_trait) — Verify that the target character meets the conditions for selecting the trait before execution to prevent errors or silent failures due to trait conflicts.

Common Pitfalls

  1. Non-existent or misspelled trait keys in the list: The game won't crash but will silently skip that entry, causing the actual random pool to differ from expectations. Always cross-reference trait definition names in common/unit_leader related files.
  2. Calling outside CHARACTER scope: If the current scope is COUNTRY or STATE, the effect won't apply. Beginners often forget to switch scope to CHARACTER using any_character or a specific character reference before calling this command in country-level events.