trigger · has_unit_type
Definition
- Supported scope:
COMBATANT - Supported target:
none
Description
Check if the combatant has at least one of the provided unit types.
For example:
has_unit_type = amphibious_mechanized
has_unit_typeCOMBATANTnoneCheck if the combatant has at least one of the provided unit types.
For example:
has_unit_type = amphibious_mechanized
实战内容由 AI 生成,并已对照 vanilla 命令词表校验 —— 请当作起点而非权威依据。上方的定义节才是游戏自带文档原文。
has_unit_type 常用于战斗事件或决策中,根据参战部队的兵种组成来触发特殊效果,例如当敌方拥有装甲单位时给予己方额外惩罚,或者为包含特定兵种的部队解锁专属战斗加成。典型场景是 mod 中为两栖作战编写额外限制:只有当攻击方确实携带了两栖机械化步兵时,才允许触发某个特殊登陆奖励事件。
# 在战斗事件的 trigger 块中,检查进攻方是否包含装甲单位
combat_event = {
id = my_mod.1
trigger = {
is_attacker = yes
has_unit_type = medium_armor
}
# ...
}
[is_attacker](/wiki/trigger/is_attacker) / [is_defender](/wiki/trigger/is_defender):通常需要先限定检查的是哪一方的兵种组成,避免对双方都生效产生逻辑混乱。[is_amphibious_invasion](/wiki/trigger/is_amphibious_invasion):与 has_unit_type 搭配用于判断"是两栖登陆且携带了专用兵种"的复合条件,常见于登陆战特殊规则。[has_cavalry_ratio](/wiki/trigger/has_cavalry_ratio) / [has_artillery_ratio](/wiki/trigger/has_artillery_ratio):前者检查某兵种是否存在(至少一个),后二者检查比例,组合使用可以构造"有骑兵且骑兵占比超过阈值"的精细条件。[is_fighting_in_terrain](/wiki/trigger/is_fighting_in_terrain):在特定地形战斗时叠加兵种检查,实现"山地作战且有山地步兵"类的地形-兵种联动逻辑。COMBATANT scope(即战斗中的一方)下使用,如果在国家或将领 scope 里直接写会静默失败或报错,务必确认脚本处于 combat_event、on_combat_enter 等进入战斗 scope 的上下文中。false,导致条件永远不触发,调试时需要用日志逐一核对兵种的真实内部名称(如 light_armor、motorized 等)。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.
has_unit_type is commonly used in combat events or decisions to trigger special effects based on the unit composition of participating forces. For example, you can impose additional penalties when the enemy possesses armor units, or unlock exclusive combat bonuses for forces containing specific unit types. A typical scenario is adding extra constraints for amphibious operations in mods: only when the attacking side actually carries dedicated amphibious mechanized infantry should a special landing reward event be triggered.
# In the trigger block of a combat event, check if the attacker contains armor units
combat_event = {
id = my_mod.1
trigger = {
is_attacker = yes
has_unit_type = medium_armor
}
# ...
}
[is_attacker](/wiki/trigger/is_attacker) / [is_defender](/wiki/trigger/is_defender):Usually need to first specify which side's unit composition is being checked to avoid logic confusion from affecting both sides.[is_amphibious_invasion](/wiki/trigger/is_amphibious_invasion):Paired with has_unit_type to determine the compound condition of "is an amphibious landing AND carries dedicated unit types," commonly used in special amphibious assault rules.[has_cavalry_ratio](/wiki/trigger/has_cavalry_ratio) / [has_artillery_ratio](/wiki/trigger/has_artillery_ratio):The first checks whether a unit type exists (at least one), while the latter two check ratios. Combined use allows constructing refined conditions like "has cavalry AND cavalry exceeds a threshold ratio."[is_fighting_in_terrain](/wiki/trigger/is_fighting_in_terrain):Stack unit type checks during combat in specific terrain to implement terrain-unit synergy logic such as "mountain warfare AND mountain infantry."COMBATANT scope (i.e., one side in combat). If written directly under country or unit leader scope, it will silently fail or throw an error. Always verify the script is within the context of entering combat scope such as combat_event or on_combat_enter.false, causing the condition to never trigger. During debugging, use logs to verify the actual internal names of unit types one by one (such as light_armor, motorized, etc.).