Wiki

trigger · has_template

Definition

  • Supported scope:COUNTRY
  • Supported target:none

Description

Check if country has a division template of specific name

实战 · 配合 · 坑

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

实战用法

has_template 常用于检查某国是否已建立特定编制的师模板,适合在国策、决策或 AI 策略中作为前置条件,例如判断玩家是否完成了装甲师或精锐步兵师的编制准备。典型场景包括:只有当国家拥有某个模板时才解锁后续决策,或用于 AI 行为判断。

# 决策的 available 块:只有建立了"装甲师"模板才可触发
available = {
    has_template = "装甲师"
}

配合关系

  • [has_army_size](/wiki/trigger/has_army_size):先用 has_template 确认模板存在,再用此 trigger 检查实际部署的兵力数量,两者配合形成完整的军事准备判断。
  • [any_country_division](/wiki/trigger/any_country_division)has_template 只验证模板存在,any_country_division 可进一步核查该模板是否已有实际部队在场上运行。
  • [division_template](/wiki/effect/division_template):在 effect 块中用于动态创建或修改师模板,通常在 has_template 判断为假时才执行,避免重复创建同名模板。
  • [delete_unit_template_and_units](/wiki/effect/delete_unit_template_and_units):需要替换旧模板时,先用 has_template 确认目标模板存在,再用此 effect 安全删除,防止删除不存在模板导致报错。

常见坑

  1. 模板名称大小写与空格必须完全一致:游戏对模板名做精确字符串匹配,"Armored Division""armored division" 会被视为不同模板,建议直接复制游戏内或脚本中定义的原始名称。
  2. Scope 混用导致静默失效has_template 只在 COUNTRY scope 下有效,若误写在 STATECHARACTER scope 内,触发器不会报错但会始终返回假,排查时容易忽略。

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

has_template is commonly used to check whether a country has established a division template of a specific type. It serves as a prerequisite condition in national focuses, decisions, or AI strategies—for example, determining whether the player has completed preparation of an armored division or elite infantry division template. Typical scenarios include unlocking subsequent decisions only when a country possesses a certain template, or using it for AI behavior evaluation.

# Available block in a decision: only trigger if an "Armored Division" template exists
available = {
    has_template = "Armored Division"
}

Synergy

  • [has_army_size](/wiki/trigger/has_army_size): First use has_template to confirm the template exists, then apply this trigger to check the actual deployed troop count. Together they form a complete military readiness assessment.
  • [any_country_division](/wiki/trigger/any_country_division): has_template only verifies template existence, while any_country_division can further verify whether that template already has active units deployed on the map.
  • [division_template](/wiki/effect/division_template): Used in effect blocks to dynamically create or modify division templates. Typically execute this only when has_template evaluates to false, avoiding duplicate creation of same-named templates.
  • [delete_unit_template_and_units](/wiki/effect/delete_unit_template_and_units): When replacing an old template, first confirm the target template exists with has_template, then safely delete it with this effect to prevent errors from deleting non-existent templates.

Common Pitfalls

  1. Template name case and spacing must match exactly: The game performs exact string matching on template names, so "Armored Division" and "armored division" are treated as different templates. It is recommended to copy the original name directly as defined in-game or in scripts.
  2. Scope confusion causes silent failure: has_template is only valid under COUNTRY scope. If mistakenly written within STATE or CHARACTER scope, the trigger will not error but will always return false, making it easy to overlook during debugging.