# Order Targeting Valid Unit In Group

Grammar — Order targeting valid unit in unitGroup, with caster: caster,pattern: inOrder looking forward: forward
FlagsNative | Function

Returns an order targeting a unit group. This is primarily for use in “Issue Order” and “Issue Order To Unit Group” actions.

# Arguments

  • unitgroup — Unit Group
  • order — Order
  • unit — Caster
  • bool — Forward

Returns — order

native order AIUnitGroupGetValidOrder(
	unitgroup inGroup,
	order inOrder,
	unit caster,
	bool forwards,
);

Category: Order / Orders To Be Issued

# Examples

campaigns/liberty.sc2campaignbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:251

    }
    
    return AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_backwards);
}

campaigns/liberty.sc2campaignbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:447

    }
    
    return AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_backwards);
}

campaigns/liberty.sc2campaignbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:569

    }

    return AIUnitGroupGetValidOrder(candidateGroup, ord, aiUnit, c_backwards);
}
//

campaigns/liberty.sc2campaignbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:630

        difficultyOrder = c_backwards;
    }
    return AIUnitGroupGetValidOrder(enemyGroup, ord, aiUnit, difficultyOrder);
}

campaigns/liberty.sc2campaignbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:679

    enemyGroup = AIGetFilterGroup(filter, scanGroup);
    if (enemyGroup != null) {
        returnOrd = AIUnitGroupGetValidOrder(enemyGroup, ord, aiUnit, c_backwards);
        if (returnOrd != null) {
            return returnOrd;

campaigns/liberty.sc2campaignbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:688

        return null;
    }
    return AIUnitGroupGetValidOrder(nonHostileBuildings, ord, aiUnit, c_backwards);
}

campaigns/swarm.sc2campaignbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:251

    }
    
    return AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_backwards);
}

campaigns/swarm.sc2campaignbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:447

    }
    
    return AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_backwards);
}

campaigns/swarm.sc2campaignbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:569

    }

    return AIUnitGroupGetValidOrder(candidateGroup, ord, aiUnit, c_backwards);
}
//

campaigns/swarm.sc2campaignbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:630

        difficultyOrder = c_backwards;
    }
    return AIUnitGroupGetValidOrder(enemyGroup, ord, aiUnit, difficultyOrder);
}

campaigns/swarm.sc2campaignbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:679

    enemyGroup = AIGetFilterGroup(filter, scanGroup);
    if (enemyGroup != null) {
        returnOrd = AIUnitGroupGetValidOrder(enemyGroup, ord, aiUnit, c_backwards);
        if (returnOrd != null) {
            return returnOrd;

campaigns/swarm.sc2campaignbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:688

        return null;
    }
    return AIUnitGroupGetValidOrder(nonHostileBuildings, ord, aiUnit, c_backwards);
}

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

    }

    return AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_forwards);
}

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

    ord = AICreateOrder(player, c_AB_ArchonWarp, 1);
    targetGroup = UnitGroupSearch(c_PU_HighTemplar, player, UnitGetPosition(aiUnit), 5.0, UnitFilter((1 << c_targetFilterSelf), 0, 0, 0), c_noMaxCount);
    targetUnit =  OrderGetTargetUnit( AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_forwards) );
    if (targetUnit == null) {
        return false;

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

    }

    ord = AIUnitGroupGetValidOrder(prodGroup, ord, aiUnit, c_forwards);    
    if (ord != null) {
        AICast(aiUnit, ord, c_noMarker, c_castHold);

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


    // else just clone the first possible enemy
    return AIUnitGroupGetValidOrder(scanGroup, ord, aiUnit, c_forwards);
}

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

    }

    ord = AIUnitGroupGetValidOrder(enemyGroup, ord, aiUnit, c_forwards);    
    return ord;
}

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

    }

    ord = AIUnitGroupGetValidOrder(scanGroup, ord, aiUnit, c_forwards);    
    return ord;
}

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

    }

    return AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_backwards);
}

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

    UnitGroupAddUnitGroup(targetGroup, psiGroup);

    return AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_backwards);
}

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

    }

    return AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_backwards);
}

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

    }
    
    return AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_backwards);
}

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

    }

    return AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_backwards);
}

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



    return AIUnitGroupGetValidOrder(group, ord, aiUnit, c_forwards);
}

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

                             c_noMaxCount)
                             ;
    return AIUnitGroupGetValidOrder(hatcheries, ord, aiUnit, c_backwards);
}

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

    //  Return valid target order
    //
    return AIUnitGroupGetValidOrder(filterGroup, ord, aiUnit, c_forwards);
}

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

    //  Return valid target
    //
    return AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_forwards);
}

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

    }

    ord = AIUnitGroupGetValidOrder(enemyGroup, ord, aiUnit, c_forwards);    
    return ord;
}

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

    }

    ord = AIUnitGroupGetValidOrder(enemyGroup, ord, aiUnit, c_forwards);
    return ord;
}

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

    }

    ord = AIUnitGroupGetValidOrder(enemyGroup, ord, aiUnit, c_forwards);    
    return ord;
}

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


    enemyGroundGroup = UnitGroupFilterPlane(scanGroup, c_planeGround, 0);
    ord = AIUnitGroupGetValidOrder(enemyGroundGroup, ord, aiUnit, c_forwards);    
    return ord;
}

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

    //  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);

    if (ord != null) {

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

    }
    
    ord = AIUnitGroupGetValidOrder(scanGroup, ord, aiUnit, c_forwards);
    if (ord != null) {
        AICast(aiUnit, ord, c_noMarker, c_castHold);

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

    }

    return AIUnitGroupGetValidOrder(filterGroup, ord, aiUnit, c_forwards);
}

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

    }

    return AIUnitGroupGetValidOrder(filterGroup, ord, aiUnit, c_forwards);
}

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

    }
    
    return AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_backwards);
}

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

    }
    
    return AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_backwards);
}

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

    }

    return AIUnitGroupGetValidOrder(candidateGroup, ord, aiUnit, c_backwards);
}

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

    }

    return AIUnitGroupGetValidOrder(candidateGroup, ord, aiUnit, c_backwards);
}

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


    // else target lowest hp fodder units first
    return AIUnitGroupGetValidOrder(enemyGroup, ord, aiUnit, c_backwards);
}

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

    enemyGroup = AIGetFilterGroup(filter, scanGroup);
    if (enemyGroup != null) {
        returnOrd = AIUnitGroupGetValidOrder(enemyGroup, ord, aiUnit, c_backwards);
        if (returnOrd != null) {
            return returnOrd;

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

    enemyGroup = AIGetFilterGroup(filter, scanGroup);
    if (enemyGroup != null) {
        returnOrd = AIUnitGroupGetValidOrder(enemyGroup, ord, aiUnit, c_backwards);
        if (returnOrd != null) {
            return returnOrd;

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

        return null;
    }
    return AIUnitGroupGetValidOrder(nonHostileBuildings, ord, aiUnit, c_backwards);
}

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

    ord = AICreateOrder(player, c_AB_ArchonWarp, 1);
    targetGroup = UnitGroupSearch(c_PU_HighTemplar, player, UnitGetPosition(aiUnit), 5.0, UnitFilter((1 << c_targetFilterSelf), 0, 0, 0), c_noMaxCount);
    targetUnit =  OrderGetTargetUnit( AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_forwards) );
    if (targetUnit == null) {
        return false;

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

    }

    ord = AIUnitGroupGetValidOrder(prodGroup, ord, aiUnit, c_forwards);    
    if (ord != null) {
        AICast(aiUnit, ord, c_noMarker, c_castHold);

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


    // else just clone the first possible enemy
    return AIUnitGroupGetValidOrder(scanGroup, ord, aiUnit, c_forwards);
}

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

    }

    ord = AIUnitGroupGetValidOrder(enemyGroup, ord, aiUnit, c_forwards);    
    return ord;
}

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

    }

    ord = AIUnitGroupGetValidOrder(scanGroup, ord, aiUnit, c_forwards);    
    return ord;
}

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

    }

    return AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_backwards);
}

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

    OrderSetTargetUnit(ord, UnitGroupUnit(targetGroup, RandomInt(1, count)));
    if (!UnitOrderIsValid(aiUnit, ord)) {
        ord = AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_backwards);
    }
    return ord;

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

    }

    return AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_backwards);
}

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

    }
    
    return AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_backwards);
}

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

    }

    return AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_backwards);
}

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



    return AIUnitGroupGetValidOrder(group, ord, aiUnit, c_forwards);
}

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

                             c_noMaxCount)
                             ;
    return AIUnitGroupGetValidOrder(hatcheries, ord, aiUnit, c_backwards);
}

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

    //  Return valid target order
    //
    return AIUnitGroupGetValidOrder(filterGroup, ord, aiUnit, c_forwards);
}

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

    }
        
    ord = AIUnitGroupGetValidOrder(consumptionTargets, ord, aiUnit, c_forwards);
    return ord;
}

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

    //  Return valid target
    //
    return AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_forwards);
}

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

    }

    ord = AIUnitGroupGetValidOrder(enemyGroup, ord, aiUnit, c_forwards);    
    return ord;
}

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

    }

    ord = AIUnitGroupGetValidOrder(enemyGroup, ord, aiUnit, c_forwards);
    return ord;
}

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

    }

    ord = AIUnitGroupGetValidOrder(enemyGroup, ord, aiUnit, c_forwards);    
    return ord;
}

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


    enemyGroundGroup = UnitGroupFilterPlane(scanGroup, c_planeGround, 0);
    ord = AIUnitGroupGetValidOrder(enemyGroundGroup, ord, aiUnit, c_forwards);    
    return ord;
}

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

    //  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);

    if (ord != null) {

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

        return null;
    }
    return AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_forwards);
}
const fixed c_spellScaleEthereal=1.66;

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

        killable=c_backwards;
    }
    return AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, killable);
}
static order AIOrderCombatSummon(int player, unit aiUnit,string entry) {

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

        return null;
    }
    return AIUnitGroupGetValidOrder(group, ord, aiUnit, c_forwards);
}
abilcmd c_cmd_Attack=AbilityCommand("Aatk", 0);

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

        return;
    }
	ord=AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_backwards);
	target=OrderGetTargetUnit(ord);
	ordCurr=UnitOrder(aiUnit,0);

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

		return;
	}
	ord=AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_backwards);
	target=OrderGetTargetUnit(ord);
	if (ord != null) {

mods/warcoop/warclassicsystem.sc2modbase.sc2data/TriggerLibs/WarClassicTactical.galaxy:560

    AISetFilterLife(lv_rangeUnitFilter, libGAwT_gv_c_noMin, 100.0);
    lv_unitsInRangeFriend = AIGetFilterGroup(lv_rangeUnitFilter, lv_unitsInRange);
    lv_orderFinal = AIUnitGroupGetValidOrder(lv_unitsInRangeFriend, lv_order, lp_aIUnit, true);
    if ((lv_orderFinal != null)) {
        libNtve_gf_AICast(lp_aIUnit, lv_orderFinal);

mods/warcoop/warclassicsystem.sc2modbase.sc2data/TriggerLibs/WarClassicTactical.galaxy:571

    AISetFilterLifeLost(lv_rangeUnitFilter, lv_heal, libGAwT_gv_c_noMax);
    lv_unitsInRangeFriend = AIGetFilterGroup(lv_rangeUnitFilter, lv_unitsInRange);
    lv_orderFinal = AIUnitGroupGetValidOrder(lv_unitsInRangeFriend, lv_order, lp_aIUnit, true);
    if ((lv_orderFinal != null)) {
        libNtve_gf_AICast(lp_aIUnit, lv_orderFinal);

mods/warcoop/warclassicsystem.sc2modbase.sc2data/TriggerLibs/WarClassicTactical.galaxy:591

    AISetFilterAlliance(lv_rangeUnitFilter, c_playerGroupEnemy);
    lv_unitsInRangeEnemyHeroes = AIGetFilterGroup(lv_rangeUnitFilter, UnitGroupFilter(null, c_playerAny, lv_unitsInRange, UnitFilter(0, (1 << (c_targetFilterHeroUnit - 32)), (1 << c_targetFilterMissile), (1 << (c_targetFilterDead - 32)) | (1 << (c_targetFilterHidden - 32))), 0));
    lv_orderFinal = AIUnitGroupGetValidOrder(lv_unitsInRangeEnemyHeroes, lv_order, lp_aIUnit, true);
    if ((lv_orderFinal != null)) {
        libNtve_gf_AICast(lp_aIUnit, lv_orderFinal);

mods/warcoop/warclassicsystem.sc2modbase.sc2data/TriggerLibs/WarClassicTactical.galaxy:599

    AISetFilterLife(lv_rangeUnitFilter, (lv_damage-50), lv_damage);
    lv_unitsInRangeEnemy = AIGetFilterGroup(lv_rangeUnitFilter, lv_unitsInRange);
    lv_orderFinal = AIUnitGroupGetValidOrder(lv_unitsInRangeEnemy, lv_order, lp_aIUnit, true);
    if ((lv_orderFinal != null)) {
        libNtve_gf_AICast(lp_aIUnit, lv_orderFinal);