Wiki

trigger · count_in_collection

Definition

  • Supported scope:COUNTRY
  • Supported target:none

Description

Checks the size of a given collection.
	Note: unit and building and manpower are mutually exclusive

	### Example
	```
	count_in_collection = {
		collection = {
			input = game:scope
			operators = { faction_members }
			name = FACTION
		}
		unit = armor  # (optional) checks the number of subunits that have the correct equipment type
		buildings = {industrial_complex } # (optional) checks the number of building types in total
		manpower = yes # (optional, default: no) checks the number of deployed manpower
		equipment_ratio = 0.9 (optional, only works with land units default 0) what percentage of equipment the division needs to atleast have to be counted
		unit_category = { marine marine_commando category_fighter }(optional) checks the number of sub units that match a certain sub unit definition / category
		stockpile = light_tank_equipment (optional) counts the amount of a certain archetype in the countries stockpile
		size > 10
	}
	```

实战 · 配合 · 坑

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

实战用法

count_in_collection 常用于检测派系成员数量、某类型部队数量或已部署兵力规模,从而动态解锁决议、触发事件或限制国策。例如,可以用它判断玩家所在的派系成员是否达到一定规模再允许某个"统一行动"决议出现:

available = {
    count_in_collection = {
        collection = {
            input = game:scope
            operators = { faction_members }
            name = FACTION
        }
        size > 4
    }
}

配合关系

  • [any_faction_member](/wiki/trigger/any_faction_member) / [all_faction_member](/wiki/trigger/all_faction_member)(虽不在白名单中,但可参考白名单内的)→ 使用 [has_completed_focus](/wiki/trigger/has_completed_focus) 配合:先用 count_in_collection 确认派系规模达标,再用该 trigger 检查成员是否完成了特定国策,二者共同构成更精确的条件门槛。
  • [add_faction_goal](/wiki/effect/add_faction_goal):通常在 count_in_collection 确认派系成员数量满足条件后,才向派系追加新目标,避免在派系规模不足时触发无效逻辑。
  • [faction_influence_ratio](/wiki/trigger/faction_influence_ratio):两者配合可同时约束派系的"体量"与"影响力占比",双重筛选确保只有真正强势的大派系才能触发特定剧情。
  • [activate_targeted_decision](/wiki/effect/activate_targeted_decision):当 count_in_collection 判断通过后,用此 effect 批量激活针对派系成员的定向决议,实现规模达标即触发联动机制。

常见坑

  1. unitbuildingsmanpower 三选一互斥:新手常同时写多个过滤字段(如既写 unit = armor 又写 manpower = yes),这会导致脚本报错或行为未定义,必须只保留其中一个,或三者全不写(此时统计的是 collection 本身的元素个数)。
  2. collectionoperators 写错导致空集operators 决定了如何从 input scope 展开集合,若写了不适用于当前 scope 的运算符(例如在非派系国家 scope 下使用 faction_members),collection 会返回空集,size > 0 永远为假,但脚本不会报错,极难排查。

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

count_in_collection is commonly used to detect the number of faction members, units of a certain type, or the scale of deployed forces, thereby dynamically unlocking decisions, triggering events, or restricting national focuses. For example, you can use it to determine whether the faction that the player belongs to has reached a certain scale before allowing a "unified action" decision to appear:

available = {
    count_in_collection = {
        collection = {
            input = game:scope
            operators = { faction_members }
            name = FACTION
        }
        size > 4
    }
}

Synergy

  • [any_faction_member](/wiki/trigger/any_faction_member) / [all_faction_member](/wiki/trigger/all_faction_member) (not in the whitelist, but can reference those in the whitelist) → Use in conjunction with [has_completed_focus](/wiki/trigger/has_completed_focus): first use count_in_collection to confirm that the faction scale meets the threshold, then use this trigger to check whether members have completed a specific national focus. Together, they form a more precise condition gate.
  • [add_faction_goal](/wiki/effect/add_faction_goal): typically only append new goals to the faction after count_in_collection confirms that the faction member count meets the requirements, avoiding triggering invalid logic when the faction scale is insufficient.
  • [faction_influence_ratio](/wiki/trigger/faction_influence_ratio): when combined with count_in_collection, both the "scale" and "influence ratio" of the faction can be constrained simultaneously. This dual filtering ensures that only truly dominant major factions can trigger specific narrative events.
  • [activate_targeted_decision](/wiki/effect/activate_targeted_decision): once count_in_collection passes the judgment, use this effect to batch activate targeted decisions against faction members, implementing a linked mechanism that triggers when the scale threshold is met.

Common Pitfalls

  1. unit, buildings, manpower are mutually exclusive (choose one): beginners often write multiple filter fields simultaneously (such as writing both unit = armor and manpower = yes), which causes script errors or undefined behavior. You must keep only one of them, or write none of the three (in which case the count is the number of elements in the collection itself).
  2. operators in collection is written incorrectly, resulting in an empty set: operators determines how the set is expanded from the input scope. If you use operators that are not applicable to the current scope (for example, using faction_members under a non-faction country scope), the collection returns an empty set and size > 0 is always false. However, the script will not report an error, making it extremely difficult to debug.