Wiki

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

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

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
    }
    # ...
}

Synergy

  • [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."

Common Pitfalls

  1. Scope is not country or unit_leader:This trigger can only be used under 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.
  2. Unit type names with typos won't error:If the unit type string provided doesn't exist (e.g., spelling mistakes), the game typically won't throw a visible error but simply returns 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.).