# Unit Can Attack Unit Type
Grammar — u Can Attack a Unit of Type s
Flags —Native
|Function
Returns true if the specified unit has an enabled weapon with target filters that match the specified target unit type.
# Arguments
unit
— Unitunit
— Target
Returns — bool
native bool UnitCanAttackTarget(
unit inUnit,
unit inTarget,
);
# Related
Category: Unit / Weapons
- Remove Weapon From Unit —
void
— UnitWeaponRemove - Add Weapon To Unit —
void
— UnitWeaponAdd - Number Of Weapons On Unit —
int
— UnitWeaponCount - Unit Weapon —
string
<gamelink::Weapon> — UnitWeaponGet - Weapon Is Enabled —
bool
— UnitWeaponIsEnabled - Weapon Target Check —
bool
— UnitWeaponCheck - Weapon Cooldown —
fixed
— UnitWeaponPeriod - Weapon Range —
fixed
— UnitWeaponRange - Weapon Cooldown Remaining —
fixed
— UnitWeaponPeriodRemaining - Add Ammo To Magazine —
void
— UnitMagazineArm - Last Created Magazine Ammo Unit —
unit
— UnitMagazineLastCreated - Last Created Magazine Ammo Units —
unitgroup
— UnitMagazineLastCreatedGroup - Magazine Count Of Unit —
int
— UnitMagazineCount - Magazine Owner Of Unit —
unit
— UnitGetMagazine - Unit Can Attack Unit Old —
bool
— libNtve_gf_UnitCanAttackUnit - Unit Can Attack Unit Type —
bool
— UnitCanAttackTarget - Unit In Range And Able To Attack Target —
bool
— UnitInRangeAndAbleToAttackTarget - Weapon Damage —
fixed
— UnitWeaponDamage - Weapon Speed Multiplier —
fixed
— UnitWeaponSpeedMultiplier - Set Weapon Cooldown Remaining —
void
— UnitWeaponSetPeriodRemaining
# Examples
campaigns/swarm.sc2campaign — base.sc2maps/maps/campaign/swarm/zhybrid02.sc2map/MapScript.galaxy:1033
if ((gv_aIHybridAttacker[lv_indexHybrid] != null) && (UnitIsAlive(gv_aIHybridAttacker[lv_indexHybrid]) == true)) {
if ((lv_lastAttacker != null) && (UnitIsAlive(lv_lastAttacker) == true) && ((FixedToInt(GameGetMissionTime()) - AILastAttack(lp_hybrid)) < 5)) {
if ((((gv_aIHybridAttacker[lv_indexHybrid] != lv_lastAttacker) && (UnitCanAttackTarget(lv_lastAttacker, lp_hybrid) == true) && (UnitCanAttackTarget(gv_aIHybridAttacker[lv_indexHybrid], lp_hybrid) == false)) || ((DistanceBetweenPoints(UnitGetPosition(lp_hybrid), UnitGetPosition(gv_aIHybridAttacker[lv_indexHybrid])) > 4.3) && (DistanceBetweenPoints(UnitGetPosition(lp_hybrid), UnitGetPosition(gv_aIHybridAttacker[lv_indexHybrid])) > DistanceBetweenPoints(UnitGetPosition(lp_hybrid), UnitGetPosition(lv_lastAttacker)))))) {
gv_aIHybridAttacker[lv_indexHybrid] = lv_lastAttacker;
}
campaigns/swarm.sc2campaign — base.sc2maps/maps/campaign/swarm/zhybrid02.sc2map/MapScript.galaxy:1033
if ((gv_aIHybridAttacker[lv_indexHybrid] != null) && (UnitIsAlive(gv_aIHybridAttacker[lv_indexHybrid]) == true)) {
if ((lv_lastAttacker != null) && (UnitIsAlive(lv_lastAttacker) == true) && ((FixedToInt(GameGetMissionTime()) - AILastAttack(lp_hybrid)) < 5)) {
if ((((gv_aIHybridAttacker[lv_indexHybrid] != lv_lastAttacker) && (UnitCanAttackTarget(lv_lastAttacker, lp_hybrid) == true) && (UnitCanAttackTarget(gv_aIHybridAttacker[lv_indexHybrid], lp_hybrid) == false)) || ((DistanceBetweenPoints(UnitGetPosition(lp_hybrid), UnitGetPosition(gv_aIHybridAttacker[lv_indexHybrid])) > 4.3) && (DistanceBetweenPoints(UnitGetPosition(lp_hybrid), UnitGetPosition(gv_aIHybridAttacker[lv_indexHybrid])) > DistanceBetweenPoints(UnitGetPosition(lp_hybrid), UnitGetPosition(lv_lastAttacker)))))) {
gv_aIHybridAttacker[lv_indexHybrid] = lv_lastAttacker;
}
campaigns/swarm.sc2campaign — base.sc2maps/maps/campaign/swarm/zzerus01.sc2map/MapScript.galaxy:635
lv_defendingUnit = UnitGroupUnitFromEnd(autoAD5963EB_g, autoAD5963EB_u);
if (lv_defendingUnit == null) { break; }
if ((UnitCanAttackTarget(lv_attackingUnit, lv_defendingUnit) == true)) {
return true;
}
campaigns/swarm.sc2campaign — base.sc2maps/maps/campaign/swarm/zzerus01.sc2map/MapScript.galaxy:5394
auto6D7AC1CE_var = UnitGroupUnitFromEnd(auto6D7AC1CE_g, auto6D7AC1CE_u);
if (auto6D7AC1CE_var == null) { break; }
if ((UnitCanAttackTarget(auto6D7AC1CE_var, lv_attacker) == true)) {
UnitGroupAdd(lv_attackGroup, auto6D7AC1CE_var);
}
campaigns/swarm.sc2campaign — base.sc2maps/maps/campaign/swarm/zzerus02.sc2map/MapScript.galaxy:3688
auto8C6F2799_var = UnitGroupUnitFromEnd(auto8C6F2799_g, auto8C6F2799_u);
if (auto8C6F2799_var == null) { break; }
if ((UnitTestState(auto8C6F2799_var, c_unitStateIdle) == true) && (UnitGroupHasUnit(gv_primalCritterAttackers, auto8C6F2799_var) == false) && (UnitCanAttackTarget(auto8C6F2799_var, lv_currentCritter) == true) && (libNtve_gf_UnitIsPaused(auto8C6F2799_var) == false) && ((UnitGetType(auto8C6F2799_var) == "PrimalZergling") || (UnitGetType(auto8C6F2799_var) == "PrimalHydralisk") || (UnitGetType(auto8C6F2799_var) == "PrimalRoach") || (UnitGetType(auto8C6F2799_var) == "PrimalUltralisk") || (UnitGetType(auto8C6F2799_var) == "PrimalFlyer") || (UnitGetType(auto8C6F2799_var) == "PrimalMutalisk") || (UnitGetType(auto8C6F2799_var) == "Ravasaur"))) {
UnitGroupAdd(lv_primalGroup, auto8C6F2799_var);
}
campaigns/swarm.sc2campaign — base.sc2maps/maps/campaign/swarm/zzerus03.sc2map/MapScript.galaxy:2921
auto27257508_var = UnitGroupUnitFromEnd(auto27257508_g, auto27257508_u);
if (auto27257508_var == null) { break; }
if ((UnitTestState(auto27257508_var, c_unitStateIdle) == true) && (UnitGroupHasUnit(gv_primalCritterAttackers, auto27257508_var) == false) && (UnitCanAttackTarget(auto27257508_var, lv_currentCritter) == true) && (libNtve_gf_UnitIsPaused(auto27257508_var) == false) && ((UnitGetType(auto27257508_var) == "PrimalZergling") || (UnitGetType(auto27257508_var) == "PrimalHydralisk") || (UnitGetType(auto27257508_var) == "PrimalRoach") || (UnitGetType(auto27257508_var) == "PrimalUltralisk") || (UnitGetType(auto27257508_var) == "PrimalFlyer") || (UnitGetType(auto27257508_var) == "PrimalMutalisk") || (UnitGetType(auto27257508_var) == "Ravasaur"))) {
UnitGroupAdd(lv_primalGroup, auto27257508_var);
}
campaigns/swarm.sc2campaign/base.sc2maps/maps/campaign/swarm/zhybrid02.sc2map — MapScript.galaxy:1033
if ((gv_aIHybridAttacker[lv_indexHybrid] != null) && (UnitIsAlive(gv_aIHybridAttacker[lv_indexHybrid]) == true)) {
if ((lv_lastAttacker != null) && (UnitIsAlive(lv_lastAttacker) == true) && ((FixedToInt(GameGetMissionTime()) - AILastAttack(lp_hybrid)) < 5)) {
if ((((gv_aIHybridAttacker[lv_indexHybrid] != lv_lastAttacker) && (UnitCanAttackTarget(lv_lastAttacker, lp_hybrid) == true) && (UnitCanAttackTarget(gv_aIHybridAttacker[lv_indexHybrid], lp_hybrid) == false)) || ((DistanceBetweenPoints(UnitGetPosition(lp_hybrid), UnitGetPosition(gv_aIHybridAttacker[lv_indexHybrid])) > 4.3) && (DistanceBetweenPoints(UnitGetPosition(lp_hybrid), UnitGetPosition(gv_aIHybridAttacker[lv_indexHybrid])) > DistanceBetweenPoints(UnitGetPosition(lp_hybrid), UnitGetPosition(lv_lastAttacker)))))) {
gv_aIHybridAttacker[lv_indexHybrid] = lv_lastAttacker;
}
campaigns/swarm.sc2campaign/base.sc2maps/maps/campaign/swarm/zhybrid02.sc2map — MapScript.galaxy:1033
if ((gv_aIHybridAttacker[lv_indexHybrid] != null) && (UnitIsAlive(gv_aIHybridAttacker[lv_indexHybrid]) == true)) {
if ((lv_lastAttacker != null) && (UnitIsAlive(lv_lastAttacker) == true) && ((FixedToInt(GameGetMissionTime()) - AILastAttack(lp_hybrid)) < 5)) {
if ((((gv_aIHybridAttacker[lv_indexHybrid] != lv_lastAttacker) && (UnitCanAttackTarget(lv_lastAttacker, lp_hybrid) == true) && (UnitCanAttackTarget(gv_aIHybridAttacker[lv_indexHybrid], lp_hybrid) == false)) || ((DistanceBetweenPoints(UnitGetPosition(lp_hybrid), UnitGetPosition(gv_aIHybridAttacker[lv_indexHybrid])) > 4.3) && (DistanceBetweenPoints(UnitGetPosition(lp_hybrid), UnitGetPosition(gv_aIHybridAttacker[lv_indexHybrid])) > DistanceBetweenPoints(UnitGetPosition(lp_hybrid), UnitGetPosition(lv_lastAttacker)))))) {
gv_aIHybridAttacker[lv_indexHybrid] = lv_lastAttacker;
}
campaigns/swarm.sc2campaign/base.sc2maps/maps/campaign/swarm/zzerus01.sc2map — MapScript.galaxy:635
lv_defendingUnit = UnitGroupUnitFromEnd(autoAD5963EB_g, autoAD5963EB_u);
if (lv_defendingUnit == null) { break; }
if ((UnitCanAttackTarget(lv_attackingUnit, lv_defendingUnit) == true)) {
return true;
}
campaigns/swarm.sc2campaign/base.sc2maps/maps/campaign/swarm/zzerus01.sc2map — MapScript.galaxy:5394
auto6D7AC1CE_var = UnitGroupUnitFromEnd(auto6D7AC1CE_g, auto6D7AC1CE_u);
if (auto6D7AC1CE_var == null) { break; }
if ((UnitCanAttackTarget(auto6D7AC1CE_var, lv_attacker) == true)) {
UnitGroupAdd(lv_attackGroup, auto6D7AC1CE_var);
}
campaigns/swarm.sc2campaign/base.sc2maps/maps/campaign/swarm/zzerus02.sc2map — MapScript.galaxy:3688
auto8C6F2799_var = UnitGroupUnitFromEnd(auto8C6F2799_g, auto8C6F2799_u);
if (auto8C6F2799_var == null) { break; }
if ((UnitTestState(auto8C6F2799_var, c_unitStateIdle) == true) && (UnitGroupHasUnit(gv_primalCritterAttackers, auto8C6F2799_var) == false) && (UnitCanAttackTarget(auto8C6F2799_var, lv_currentCritter) == true) && (libNtve_gf_UnitIsPaused(auto8C6F2799_var) == false) && ((UnitGetType(auto8C6F2799_var) == "PrimalZergling") || (UnitGetType(auto8C6F2799_var) == "PrimalHydralisk") || (UnitGetType(auto8C6F2799_var) == "PrimalRoach") || (UnitGetType(auto8C6F2799_var) == "PrimalUltralisk") || (UnitGetType(auto8C6F2799_var) == "PrimalFlyer") || (UnitGetType(auto8C6F2799_var) == "PrimalMutalisk") || (UnitGetType(auto8C6F2799_var) == "Ravasaur"))) {
UnitGroupAdd(lv_primalGroup, auto8C6F2799_var);
}
campaigns/swarm.sc2campaign/base.sc2maps/maps/campaign/swarm/zzerus03.sc2map — MapScript.galaxy:2921
auto27257508_var = UnitGroupUnitFromEnd(auto27257508_g, auto27257508_u);
if (auto27257508_var == null) { break; }
if ((UnitTestState(auto27257508_var, c_unitStateIdle) == true) && (UnitGroupHasUnit(gv_primalCritterAttackers, auto27257508_var) == false) && (UnitCanAttackTarget(auto27257508_var, lv_currentCritter) == true) && (libNtve_gf_UnitIsPaused(auto27257508_var) == false) && ((UnitGetType(auto27257508_var) == "PrimalZergling") || (UnitGetType(auto27257508_var) == "PrimalHydralisk") || (UnitGetType(auto27257508_var) == "PrimalRoach") || (UnitGetType(auto27257508_var) == "PrimalUltralisk") || (UnitGetType(auto27257508_var) == "PrimalFlyer") || (UnitGetType(auto27257508_var) == "PrimalMutalisk") || (UnitGetType(auto27257508_var) == "Ravasaur"))) {
UnitGroupAdd(lv_primalGroup, auto27257508_var);
}
campaigns/swarmstory.sc2campaign — base.sc2data/TriggerLibs/SwarmCampaignLib.galaxy:2238
auto8858001F_var = UnitGroupUnitFromEnd(auto8858001F_g, auto8858001F_u);
if (auto8858001F_var == null) { break; }
if ((UnitCanAttackTarget(auto8858001F_var, lp_unit) == true)) {
lv_validAttackerFound = true;
break;
campaigns/swarmstory.sc2campaign — base.sc2data/TriggerLibs/SwarmCampaignLib.galaxy:2250
auto89807BFA_var = UnitGroupUnitFromEnd(auto89807BFA_g, auto89807BFA_u);
if (auto89807BFA_var == null) { break; }
if ((UnitCanAttackTarget(auto89807BFA_var, lp_unit) == true)) {
lv_validAttackerFound = true;
break;
campaigns/void.sc2campaign — base.sc2maps/maps/campaign/void/paiur03.sc2map/MapScript.galaxy:2730
lv_iterUnit = UnitGroupUnitFromEnd(autoCEEFF9AB_g, autoCEEFF9AB_u);
if (lv_iterUnit == null) { break; }
if (((UnitGroupHasUnit(UnitGroupIdle(gv_pLAYER_02_DOMINION2, false), lv_iterUnit) == false) || (UnitCanAttackTarget(lv_iterUnit, auto075978B0_var) == false))) {
UnitGroupRemove(lv_nearbyZergGroup, lv_iterUnit);
}
campaigns/void.sc2campaign/base.sc2maps/maps/campaign/void/paiur03.sc2map — MapScript.galaxy:2730
lv_iterUnit = UnitGroupUnitFromEnd(autoCEEFF9AB_g, autoCEEFF9AB_u);
if (lv_iterUnit == null) { break; }
if (((UnitGroupHasUnit(UnitGroupIdle(gv_pLAYER_02_DOMINION2, false), lv_iterUnit) == false) || (UnitCanAttackTarget(lv_iterUnit, auto075978B0_var) == false))) {
UnitGroupRemove(lv_nearbyZergGroup, lv_iterUnit);
}
campaigns/voidstory.sc2campaign — base.sc2data/TriggerLibs/VoidCampaignMissionLib.galaxy:2164
auto4C6B244C_var = UnitGroupUnitFromEnd(auto4C6B244C_g, auto4C6B244C_u);
if (auto4C6B244C_var == null) { break; }
if ((UnitCanAttackTarget(auto4C6B244C_var, lp_unit) == true)) {
lv_validAttackerFound = true;
break;
campaigns/voidstory.sc2campaign — base.sc2data/TriggerLibs/VoidCampaignMissionLib.galaxy:2176
auto89AFDACF_var = UnitGroupUnitFromEnd(auto89AFDACF_g, auto89AFDACF_u);
if (auto89AFDACF_var == null) { break; }
if ((UnitCanAttackTarget(auto89AFDACF_var, lp_unit) == true)) {
lv_validAttackerFound = true;
break;
mods/missionpacks/novacampaign.sc2mod — base.sc2data/LibNCMI.galaxy:2803
UnitGroupLoopBegin(UnitGroup(null, lp_player, RegionCircle(lv_unitPosition, 16.0), UnitFilter(0, 0, (1 << c_targetFilterStructure) | (1 << c_targetFilterWorker) | (1 << c_targetFilterMissile), (1 << (c_targetFilterDead - 32)) | (1 << (c_targetFilterHidden - 32))), 0));
for ( ; !UnitGroupLoopDone() ; UnitGroupLoopStep() ) {
if ((UnitCanAttackTarget(UnitGroupLoopCurrent(), lp_unit) == true)) {
lv_validAttackerFound = true;
break;
mods/missionpacks/novacampaign.sc2mod — base.sc2data/LibNCMI.galaxy:2813
UnitGroupLoopBegin(UnitGroup(null, lp_player, RegionCircle(lv_unitPosition, 8.0), UnitFilter((1 << c_targetFilterStructure), 0, (1 << c_targetFilterWorker) | (1 << c_targetFilterMissile), (1 << (c_targetFilterDead - 32)) | (1 << (c_targetFilterHidden - 32))), 0));
for ( ; !UnitGroupLoopDone() ; UnitGroupLoopStep() ) {
if ((UnitCanAttackTarget(UnitGroupLoopCurrent(), lp_unit) == true)) {
lv_validAttackerFound = true;
break;
mods/starcoop/starcoop.sc2mod — base.sc2data/LibCOMI.galaxy:8857
auto4C6B244C_var = UnitGroupUnitFromEnd(auto4C6B244C_g, auto4C6B244C_u);
if (auto4C6B244C_var == null) { break; }
if ((UnitCanAttackTarget(auto4C6B244C_var, lp_unit) == true)) {
lv_validAttackerFound = true;
break;
mods/starcoop/starcoop.sc2mod — base.sc2data/LibCOMI.galaxy:8869
auto89AFDACF_var = UnitGroupUnitFromEnd(auto89AFDACF_g, auto89AFDACF_u);
if (auto89AFDACF_var == null) { break; }
if ((UnitCanAttackTarget(auto89AFDACF_var, lp_unit) == true)) {
lv_validAttackerFound = true;
break;
mods/starcoop/starcoop.sc2mod — base.sc2data/LibCOMU.galaxy:4528
for ( ; ( (auto694A0AEB_ai >= 0 && lv_targetSelectionIndex <= auto694A0AEB_ae) || (auto694A0AEB_ai < 0 && lv_targetSelectionIndex >= auto694A0AEB_ae) ) ; lv_targetSelectionIndex += auto694A0AEB_ai ) {
lv_possibleTargetUnit = UnitGroupRandomUnit(lv_enemyUnitsNearby, c_unitCountAlive);
if ((UnitCanAttackTarget(lp_aIUnit, lv_possibleTargetUnit) == true)) {
lv_targetUnit = lv_possibleTargetUnit;
break;