Wiki

effect · set_faction_rule

Definition

  • Supported scope:COUNTRY
  • Supported target:none

Description

Set a rule on the country's faction

### Examples

TAG = { set_faction_rule = rule_id }

实战 · 配合 · 坑

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

实战用法

set_faction_rule 常用于 mod 中自定义派系机制,例如限制派系成员的宣战行为、外交决策或资源共享规则,使派系产生独特的组织约束。典型场景是在国家完成某个国策后,为其所在派系应用一条特殊规则以改变派系运作逻辑。

focus_complete = {
    id = my_focus_restrict_faction_wars
    TAG = {
        set_faction_rule = faction_cannot_justify_wargoals
    }
}

配合关系

  • [create_faction](/wiki/effect/create_faction):创建派系后立即设置规则,确保新派系从成立之初就受到约束,是最常见的组合顺序。
  • [clear_rule](/wiki/effect/clear_rule):与 set_faction_rule 互为逆操作,在条件变化时清除先前设置的派系规则,形成完整的规则开关逻辑。
  • [has_active_rule](/wiki/trigger/has_active_rule):在 trigger 侧检测某条规则是否已生效,用于决策或事件的前置条件,与 set_faction_rule 构成"设置–检测"闭环。
  • [add_faction_goal](/wiki/effect/add_faction_goal):通常与派系规则一同配置,在设定规则的同时赋予派系目标,使派系行为约束与目标导向保持一致。

常见坑

  1. Scope 必须是派系领袖所在国家set_faction_rule 要求执行 scope 为拥有该派系的国家(通常是派系创建者),若在普通成员国 scope 下调用,规则将不会正确绑定到派系,且不会有任何报错提示,极易导致规则静默失效。
  2. rule_id 必须在 faction_rules 定义文件中预先声明:直接填写未注册的 ID 不会自动创建规则,游戏会忽略该指令,新手常误以为任意字符串都可作为规则 ID 使用。

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

set_faction_rule is commonly used in mods to implement custom faction mechanics, such as restricting how faction members declare wars, make diplomatic decisions, or share resources, thereby introducing unique organizational constraints to factions. A typical scenario involves applying a special rule to a faction after a nation completes a national focus, fundamentally altering how the faction operates.

focus_complete = {
    id = my_focus_restrict_faction_wars
    TAG = {
        set_faction_rule = faction_cannot_justify_wargoals
    }
}

Synergy

  • [create_faction](/wiki/effect/create_faction): Set rules immediately after faction creation to ensure the new faction is subject to constraints from its inception; this is the most common pairing sequence.
  • [clear_rule](/wiki/effect/clear_rule): Acts as the inverse operation to set_faction_rule, allowing you to remove previously set faction rules when conditions change, forming a complete rule toggle mechanism.
  • [has_active_rule](/wiki/trigger/has_active_rule): On the trigger side, detect whether a specific rule is currently active to serve as a precondition for decisions or events, working together with set_faction_rule to create a "set–check" loop.
  • [add_faction_goal](/wiki/effect/add_faction_goal): Typically configured alongside faction rules, assigning faction goals while setting rules to keep behavioral constraints and goal orientation consistent.

Common Pitfalls

  1. Scope must be the faction leader's country: set_faction_rule requires the execution scope to be the nation that owns the faction (typically the faction's creator). If called within the scope of a regular member nation, the rule will not bind correctly to the faction and will silently fail with no error messages, making this mistake particularly insidious.
  2. rule_id must be pre-declared in the faction_rules definition file: Directly entering an unregistered ID will not automatically create a rule; the game will simply ignore the command. Beginners often mistakenly assume any arbitrary string can be used as a rule ID.