命令百科

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 永远为假,但脚本不会报错,极难排查。