Wiki

effect · add_defense

Definition

  • Supported scope:CHARACTER
  • Supported target:none

Description

Adds defense skill to a unit leader
Example: add_defense = 1

实战 · 配合 · 坑

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

实战用法

add_defense 常用于 mod 中为特定将领设计成长事件,例如在战役胜利后奖励指挥官防御技能,或在角色晋升时动态提升其属性以反映战场经验积累。该命令必须在 CHARACTER scope 下执行,通常通过 unit_leader_event 触发的事件选项来调用。

# 战役胜利后,将领获得防御技能奖励
unit_leader_event = {
    id = my_mod.10
    title = "防线大师"
    option = {
        name = "接受嘉奖"
        add_defense = 2
        add_trait = { trait = defense_expert }
    }
}

配合关系

  • [add_attack](/wiki/effect/add_attack):与 add_defense 同类属性命令,常在同一事件选项中组合使用,全面强化将领的攻防数值。
  • [add_trait](/wiki/effect/add_trait):为将领附加特质的同时提升数值属性,使成长在叙事和数值层面均有体现。
  • [defense_skill_level](/wiki/trigger/defense_skill_level):在执行 add_defense 前用于检查将领当前防御等级,避免属性溢出或超出设计上限。
  • [add_skill_level](/wiki/effect/add_skill_level):整体技能等级提升与单项属性提升常搭配使用,兼顾综合成长与专项强化。

常见坑

  1. Scope 错误:在 COUNTRY 或其他非 CHARACTER scope 下调用 add_defense 会导致脚本静默失败,必须确保先通过 characters = { ... } 或事件的 from/root 正确切换到目标角色的 CHARACTER scope。
  2. 无上限意识:游戏内将领属性存在实际显示和平衡上限,连续多次叠加 add_defense 并不会被脚本报错,但会产生超出设计预期的数值,建议配合 [defense_skill_level](/wiki/trigger/defense_skill_level) 做条件判断加以限制。

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_defense is commonly used in mods to design growth events for specific commanders, such as rewarding a leader's defense skill after a campaign victory or dynamically enhancing their attributes upon promotion to reflect accumulated battlefield experience. This command must be executed within a CHARACTER scope and is typically invoked through event options triggered by unit_leader_event.

# After a campaign victory, the commander receives a defense skill reward
unit_leader_event = {
    id = my_mod.10
    title = "Master of the Defense Line"
    option = {
        name = "Accept the Commendation"
        add_defense = 2
        add_trait = { trait = defense_expert }
    }
}

Synergy

  • [add_attack](/wiki/effect/add_attack): A sibling attribute command to add_defense, frequently combined within the same event option to comprehensively strengthen a leader's offensive and defensive stats.
  • [add_trait](/wiki/effect/add_trait): Adds a trait to a leader while simultaneously boosting numerical attributes, ensuring growth is reflected both narratively and mechanically.
  • [defense_skill_level](/wiki/trigger/defense_skill_level): Used to check a leader's current defense level before executing add_defense, preventing attribute overflow or exceeding design caps.
  • [add_skill_level](/wiki/effect/add_skill_level): Overall skill level increases are typically paired with single-attribute boosts to balance comprehensive growth with specialized enhancements.

Common Pitfalls

  1. Scope Mismatch: Calling add_defense within COUNTRY or other non-CHARACTER scopes will cause the script to fail silently. Always ensure you switch to the target character's CHARACTER scope correctly via characters = { ... } or using event from/root references.
  2. Lack of Upper Bound Awareness: Commander attributes in-game have practical display and balance caps. Stacking add_defense multiple times consecutively will not trigger script errors, but can produce values exceeding design intent. It is recommended to pair this with [defense_skill_level](/wiki/trigger/defense_skill_level) for conditional checks to impose limits.