# Find Units

Grammar — Create a list of all player player’s units of type unitType within range withinRange of the point centerPoint up to maxCount units
FlagsNative | Function

Returns a group of all of the units of the specified type owned by a player within the specified range of a point up to max count units.

# Arguments

  • int — Player
  • string — Unit Type
  • point — Center Point
  • fixed — Within Range
  • int — Max Count

Returns — unitgroup

native unitgroup AIFindUnits(
	int player,
	string unitType,
	point p,
	fixed range,
	int inMaxCount,
);

Category: AI Advanced / Tactical / Functions

# Examples

mods/core.sc2modbase.sc2data/TriggerLibs/Tactical/TactProtAI.galaxy:488


    // if I have a nearby nexus that isn't already overcharged
    nearbyBuildings = AIFindUnits(player, c_PB_Nexus, UnitGetPosition(aiUnit), 12, c_noMaxCount);
    UnitGroupAddUnitGroup( nearbyBuildings, AIFindUnits(player, c_PB_Pylon, UnitGetPosition(aiUnit), 12, c_noMaxCount) );
    unitCount = UnitGroupCount(nearbyBuildings, c_unitCountAll);

mods/core.sc2modbase.sc2data/TriggerLibs/Tactical/TactProtAI.galaxy:489

    // if I have a nearby nexus that isn't already overcharged
    nearbyBuildings = AIFindUnits(player, c_PB_Nexus, UnitGetPosition(aiUnit), 12, c_noMaxCount);
    UnitGroupAddUnitGroup( nearbyBuildings, AIFindUnits(player, c_PB_Pylon, UnitGetPosition(aiUnit), 12, c_noMaxCount) );
    unitCount = UnitGroupCount(nearbyBuildings, c_unitCountAll);
    while (unitCount > 0) {

mods/core.sc2modbase.sc2data/TriggerLibs/Tactical/TactTerrAI.galaxy:872


            if (ord == null) {
                nearBunkerGroup = AIFindUnits(player, wanted, UnitGetPosition(aiUnit), c_campaignBunkerLoadRange, c_noMaxCount);
                if (wanted == c_nullString) {
                    filter = AIFilter(player);

mods/core.sc2modbase.sc2data/TriggerLibs/Tactical/TactTerrAI.galaxy:905

        }

        nearBunkerGroup = AIFindUnits(player, wanted, UnitGetPosition(aiUnit), loadRange, c_noMaxCount);
        if (wanted == c_nullString) {
            filter = AIFilter(player);

mods/core.sc2modbase.sc2data/TriggerLibs/Tactical/TactTerrAI.galaxy:1165

    unitgroup targetGroup;

    targetGroup = AIFindUnits(player, null, UnitGetPosition(aiUnit), AIEffectFixed(player, c_EF_D8ChargeDmg, c_fieldAreaRadius2), c_noMaxCount);

    AISetFilterAlliance(filter, c_playerGroupAlly);

mods/core.sc2modbase.sc2data/TriggerLibs/Tactical/TactTerrAI.galaxy:1185

    unitgroup targetGroup;

    targetGroup = AIFindUnits(player, null, UnitGetPosition(aiUnit), AIEffectFixed(player, c_EF_KD8ChargeDmg, c_fieldAreaRadius0), c_noMaxCount);

    AISetFilterAlliance(filter, c_playerGroupAlly);

mods/core.sc2modbase.sc2data/TriggerLibs/Tactical/TactZergAI.galaxy:27

    }

    group = AIFindUnits(player, null, UnitGetPosition(aiUnit), 
                        AIAbilityFixed(player, c_AB_Transfusion, c_fieldRange0) + 1,
                        c_noMaxCount)

mods/core.sc2modbase.sc2data/TriggerLibs/Tactical/TactZergAI.galaxy:70

    }

    hatcheries = AIFindUnits(player, 
                             c_ZB_Hatchery_Alias, 
                             UnitGetPosition(aiUnit), 

mods/core.sc2modbase.sc2data/TriggerLibs/Tactical/TactZergAI.galaxy:897


    //  Check to see if there are enough basic units around to follow.
    if ((UnitGroupCount(AIFilterPathable(AIFindUnits(enemyPlayer, c_PU_Zealot, here, range, c_maxEnemyCount), here), c_unitCountAlive) >= 2) ||
        (UnitGroupCount(AIFilterPathable(AIFindUnits(enemyPlayer, c_ZU_Zergling, here, range, c_maxEnemyCount), here), c_unitCountAlive) >= 2) ||
        (UnitGroupCount(AIFilterPathable(AIFindUnits(enemyPlayer, c_TU_Marine, here, range, c_maxEnemyCount), here), c_unitCountAlive) >= 2)) {

mods/core.sc2modbase.sc2data/TriggerLibs/Tactical/TactZergAI.galaxy:898

    //  Check to see if there are enough basic units around to follow.
    if ((UnitGroupCount(AIFilterPathable(AIFindUnits(enemyPlayer, c_PU_Zealot, here, range, c_maxEnemyCount), here), c_unitCountAlive) >= 2) ||
        (UnitGroupCount(AIFilterPathable(AIFindUnits(enemyPlayer, c_ZU_Zergling, here, range, c_maxEnemyCount), here), c_unitCountAlive) >= 2) ||
        (UnitGroupCount(AIFilterPathable(AIFindUnits(enemyPlayer, c_TU_Marine, here, range, c_maxEnemyCount), here), c_unitCountAlive) >= 2)) {
        return ord;

mods/core.sc2modbase.sc2data/TriggerLibs/Tactical/TactZergAI.galaxy:899

    if ((UnitGroupCount(AIFilterPathable(AIFindUnits(enemyPlayer, c_PU_Zealot, here, range, c_maxEnemyCount), here), c_unitCountAlive) >= 2) ||
        (UnitGroupCount(AIFilterPathable(AIFindUnits(enemyPlayer, c_ZU_Zergling, here, range, c_maxEnemyCount), here), c_unitCountAlive) >= 2) ||
        (UnitGroupCount(AIFilterPathable(AIFindUnits(enemyPlayer, c_TU_Marine, here, range, c_maxEnemyCount), here), c_unitCountAlive) >= 2)) {
        return ord;
    }

mods/core.sc2modbase.sc2data/TriggerLibs/Tactical/TactZergAI.galaxy:1242


    //  By default, follow the provided unit type.
    followGroup = AIFindUnits(enemyPlayer, followUnit, UnitGetPosition(aiUnit), AIUnitFixed(player, c_ZU_Overseer, c_fieldSightRange), c_noMaxCount);
    ord = AIUnitGroupGetValidOrder(followGroup, ord, aiUnit, c_forwards);

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:74

	}
	
	nearbyAlliedUnits = AIFindUnits(player, null, UnitGetPosition(aiUnit), 
							8, c_noMaxCount);
	

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:1648

    }

    group = AIFindUnits(player, null, UnitGetPosition(aiUnit), 
                        AIAbilityFixed(player, "DefensiveMatrixTarget", c_fieldRange0) + 1,
                        c_noMaxCount)

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactProtAI.galaxy:482


    // if I have a nearby nexus that isn't already overcharged
    nearbyTargets = AIFindUnits(player, c_PB_Nexus, UnitGetPosition(aiUnit), 10, c_noMaxCount);
    unitCount = UnitGroupCount(nearbyTargets, c_unitCountAll);
    while (unitCount > 0) {

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactTerrAI.galaxy:843


            if (ord == null) {
                nearBunkerGroup = AIFindUnits(player, wanted, UnitGetPosition(aiUnit), c_campaignBunkerLoadRange, c_noMaxCount);
                if (wanted == c_nullString) {
                    filter = AIFilter(player);

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactTerrAI.galaxy:870

        }

        nearBunkerGroup = AIFindUnits(player, wanted, UnitGetPosition(aiUnit), loadRange, c_noMaxCount);
        if (wanted == c_nullString) {
            filter = AIFilter(player);

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactTerrAI.galaxy:1138

    unitgroup targetGroup;

    targetGroup = AIFindUnits(player, null, UnitGetPosition(aiUnit), AIEffectFixed(player, c_EF_D8ChargeDmg, c_fieldAreaRadius2), c_noMaxCount);

    AISetFilterAlliance(filter, c_playerGroupAlly);

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactTerrAI.galaxy:1158

    unitgroup targetGroup;

    targetGroup = AIFindUnits(player, null, UnitGetPosition(aiUnit), AIEffectFixed(player, c_EF_KD8ChargeDmg, c_fieldAreaRadius0), c_noMaxCount);

    AISetFilterAlliance(filter, c_playerGroupAlly);

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactZergAI.galaxy:25

    }

    group = AIFindUnits(player, null, UnitGetPosition(aiUnit), 
                        AIAbilityFixed(player, c_AB_Transfusion, c_fieldRange0) + 1,
                        c_noMaxCount)

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactZergAI.galaxy:68

    }

    hatcheries = AIFindUnits(player, 
                             c_ZB_Hatchery_Alias, 
                             UnitGetPosition(aiUnit), 

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactZergAI.galaxy:427

    AISetFilterLifeSortReference(filter, c_aiConsumptionTargetMinLife, c_aiConsumptionTargetMinLife*c_distanceFromDamage); 
    
    consumptionTargets = AIFindUnits(player, null, UnitGetPosition(aiUnit), 5.0, c_noMaxCount);
    consumptionTargets = AIGetFilterGroup(filter, consumptionTargets);
    if (consumptionTargets == null) {

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactZergAI.galaxy:1106


    //  Check to see if there are enough basic units around to follow.
    if ((UnitGroupCount(AIFilterPathable(AIFindUnits(enemyPlayer, c_PU_Zealot, here, range, c_maxEnemyCount), here), c_unitCountAlive) >= 2) ||
        (UnitGroupCount(AIFilterPathable(AIFindUnits(enemyPlayer, c_ZU_Zergling, here, range, c_maxEnemyCount), here), c_unitCountAlive) >= 2) ||
        (UnitGroupCount(AIFilterPathable(AIFindUnits(enemyPlayer, c_TU_Marine, here, range, c_maxEnemyCount), here), c_unitCountAlive) >= 2)) {

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactZergAI.galaxy:1107

    //  Check to see if there are enough basic units around to follow.
    if ((UnitGroupCount(AIFilterPathable(AIFindUnits(enemyPlayer, c_PU_Zealot, here, range, c_maxEnemyCount), here), c_unitCountAlive) >= 2) ||
        (UnitGroupCount(AIFilterPathable(AIFindUnits(enemyPlayer, c_ZU_Zergling, here, range, c_maxEnemyCount), here), c_unitCountAlive) >= 2) ||
        (UnitGroupCount(AIFilterPathable(AIFindUnits(enemyPlayer, c_TU_Marine, here, range, c_maxEnemyCount), here), c_unitCountAlive) >= 2)) {
        return ord;

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactZergAI.galaxy:1108

    if ((UnitGroupCount(AIFilterPathable(AIFindUnits(enemyPlayer, c_PU_Zealot, here, range, c_maxEnemyCount), here), c_unitCountAlive) >= 2) ||
        (UnitGroupCount(AIFilterPathable(AIFindUnits(enemyPlayer, c_ZU_Zergling, here, range, c_maxEnemyCount), here), c_unitCountAlive) >= 2) ||
        (UnitGroupCount(AIFilterPathable(AIFindUnits(enemyPlayer, c_TU_Marine, here, range, c_maxEnemyCount), here), c_unitCountAlive) >= 2)) {
        return ord;
    }

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactZergAI.galaxy:1437


    //  By default, follow the provided unit type.
    followGroup = AIFindUnits(enemyPlayer, followUnit, UnitGetPosition(aiUnit), AIUnitFixed(player, c_ZU_Overseer, c_fieldSightRange), c_noMaxCount);
    ord = AIUnitGroupGetValidOrder(followGroup, ord, aiUnit, c_forwards);

mods/warcoop/warclassicsystem.sc2modbase.sc2data/TriggerLibs/Tactical/TacticalAIWar3.galaxy:347

    }

    group = AIFindUnits(player, null, UnitGetPosition(aiUnit), 
                        AIAbilityFixed(player, entry, c_fieldRange0) + 2,
                        c_noMaxCount)