Wiki

effect · create_faction_from_template

Definition

  • Supported scope:COUNTRY
  • Supported target:none

Description

Create a faction from a template allows for optional customization of name, icon and color.

### Examples

TAG = { # Creator's tag create_faction_from_template = faction_template_id }

with custom name, icon and color

Tag = { # Creator's tag

create_faction_from_template = { template = faction_template_id name = FACTION_NAME_LOC_ID icon = GFX_faction_icon color = { 0.5 0.5 0.5 } } }

实战 · 配合 · 坑

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

实战用法

当 mod 需要根据玩家或 AI 的某个决策、国策路线来动态组建一个带有自定义外观的势力集团时,create_faction_from_template 非常适用——它可以在运行时覆盖模板预设的名称、图标和颜色,从而让同一模板在不同剧情分支下呈现不同面貌。例如在一条"联合轴心"的国策里,根据玩家选择的意识形态分支,赋予阵营截然不同的本地化名称和配色:

GER = {
    create_faction_from_template = {
        template = axis_template
        name = FACTION_EURASIAN_AXIS
        icon = GFX_faction_eurasian_icon
        color = { 0.8 0.2 0.1 }
    }
}

配合关系

  • [add_to_faction](/wiki/effect/add_to_faction):阵营创建后立即拉入盟友国家,避免新阵营长期只有创建者一国的尴尬局面。
  • [dismantle_faction](/wiki/effect/dismantle_faction):在重建或替换阵营剧情中,先解散旧阵营再从模板创建新阵营,保证阵营数据干净。
  • [has_country_flag](/wiki/trigger/has_country_flag):用来判断是否已经触发过创建阵营的流程,防止重复调用同一模板导致报错或逻辑混乱。
  • [create_wargoal](/wiki/effect/create_wargoal):阵营成立后对目标国生成战争借口,将外交与军事流程串联成完整的剧情链。

常见坑

  1. 模板 ID 必须提前在 common/faction_templates/ 中定义,直接在 effect 里填写一个不存在的 template 值不会产生报错提示,但阵营将静默创建失败,新手常因此误以为是触发条件写错而反复排查逻辑。
  2. 创建者 scope 必须是该阵营的实际领袖国,若在非领袖国的 scope 下调用,游戏不会自动转移领袖权,可能导致阵营领袖与模板预期不符,进而引发后续 add_to_faction 或外交 AI 的异常行为。

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

When a mod needs to dynamically assemble a faction group with custom appearance based on a player or AI decision or focus line, create_faction_from_template is ideal—it allows overriding the template's preset name, icon, and color at runtime, enabling the same template to present different appearances across different story branches. For example, in a "United Axis" focus tree, based on the player's chosen ideology branch, assign the faction completely different localized names and color schemes:

GER = {
    create_faction_from_template = {
        template = axis_template
        name = FACTION_EURASIAN_AXIS
        icon = GFX_faction_eurasian_icon
        color = { 0.8 0.2 0.1 }
    }
}

Synergy

  • [add_to_faction](/wiki/effect/add_to_faction): Immediately recruit ally nations into the faction after creation, avoiding the awkward situation where a new faction only contains its creator for extended periods.
  • [dismantle_faction](/wiki/effect/dismantle_faction): In faction rebuild or replacement narratives, dismantle the old faction first, then create a new one from the template, ensuring clean faction data.
  • [has_country_flag](/wiki/trigger/has_country_flag): Used to check whether the faction creation process has already been triggered, preventing duplicate template invocations that could cause errors or logic conflicts.
  • [create_wargoal](/wiki/effect/create_wargoal): Generate war goals against target nations after faction establishment, chaining diplomatic and military processes into a complete narrative sequence.

Common Pitfalls

  1. The template ID must be predefined in common/faction_templates/ beforehand. Entering a non-existent template value directly in the effect will not produce an error message, but the faction will silently fail to create. Newcomers often mistakenly blame logic errors and repeatedly troubleshoot conditions because of this.
  2. The creator's scope must be the actual leader nation of the faction. If called from a non-leader nation's scope, the game will not automatically transfer leadership, potentially causing the faction leader to deviate from the template's expectations, which may subsequently trigger abnormal behavior in add_to_faction or diplomatic AI.