# Order Set Target Unit

Grammar — Set Target Unit for inOrder to inUnit
FlagsNative | Action

# Arguments

  • order — Order
  • unit — Unit

Returns — void

native void OrderSetTargetUnit(order inOrder, unit inUnit);

Category: Order / Orders To Be Issued

# Examples

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

        scanCount = scanCount - 1;
    
        OrderSetTargetUnit(ord, unitToCheck);
        if (UnitOrderIsValid(aiUnit, ord)) {
            AICast(aiUnit, ord, c_noMarker, c_castHold);

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

        scanCount = scanCount - 1;
    
        OrderSetTargetUnit(ord, unitToCheck);
        if (UnitOrderIsValid(aiUnit, ord)) {
            AICast(aiUnit, ord, c_noMarker, c_castHold);

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

        }
        
        OrderSetTargetUnit(ord, unitToCheck);
        if (!UnitOrderIsValid(aiUnit, ord)) {
            continue;

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

    }
    
    OrderSetTargetUnit(ord, targetBuilding);
    if (!UnitOrderIsValid(aiUnit, ord)) {
        // should always be valid since it was checked above

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

    }
    
    OrderSetTargetUnit(ord, targetUnit);
    if (!UnitOrderIsValid(aiUnit, ord)) {
        return null;

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


    if (bestReplicate >= 0) {
        OrderSetTargetUnit(ord, bestUnit);
        if (UnitOrderIsValid(aiUnit, ord)) {
            return ord;

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

    
    if (targetUnit != null) {
        OrderSetTargetUnit(ord, targetUnit);                        
    }
    else {

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

    //  Check target validity.
    //
    OrderSetTargetUnit(ord, target);
    if (UnitOrderIsValid(aiUnit, ord)) {
        return ord;

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

                if (unitToCheck != null) {
                    ord = AICreateOrder(player, command, e_AB_TransportLoadUnit); // load the bunker.
                    OrderSetTargetUnit(ord, unitToCheck);
                }
            }

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

            else {
                ord = AICreateOrder(player, command, e_AB_TransportLoadUnit);
                OrderSetTargetUnit(ord, unitToCheck);
            }
            break;

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

        }
        if (airOnly == false || UnitTestPlane(curTarget, c_planeAir) == true) {
            OrderSetTargetUnit(ord, curTarget);
            if (UnitOrderIsValid(aiUnit, ord)) {
                AICast(aiUnit, ord, c_noMarker, c_castHold);

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

    }

    OrderSetTargetUnit(ord, UnitGroupUnit(targetGroup, 1));
    if (UnitOrderIsValid(aiUnit, ord)) {
        AICast(aiUnit, ord, c_noMarker, c_castHold);

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


    target = UnitGroupClosestToPoint(airGroup, loc);
    OrderSetTargetUnit(ord, target);
    if (!UnitOrderIsValid(aiUnit, ord)) {
        return null;

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

    }

    OrderSetTargetUnit(ord, targetUnit);
    if (!UnitOrderIsValid(aiUnit, ord)) {
        return null;

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

        if (immCount > 0) {
            // randomly pick a threatening immobile unit
            OrderSetTargetUnit(ord, UnitGroupUnit(immobileGroup, RandomInt(1, immCount)));
            if (UnitOrderIsValid(aiUnit, ord)) {
                return ord;

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


    // else just try any random target 
    OrderSetTargetUnit(ord, UnitGroupUnit(scanGroup, RandomInt(1, count)));
    if (!UnitOrderIsValid(aiUnit, ord)) {
        ord = AIUnitGroupGetValidOrder(scanGroup, ord, aiUnit, c_forwards);  

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


    // try a random target first
    OrderSetTargetUnit(ord, UnitGroupUnit(targetGroup, RandomInt(1, count)));
    if (!UnitOrderIsValid(aiUnit, ord)) {
        ord = AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_forwards);  

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

        scanCount = scanCount - 1;
    
        OrderSetTargetUnit(ord, unitToCheck);
        if (UnitOrderIsValid(aiUnit, ord)) {
            AICast(aiUnit, ord, c_noMarker, c_castHold);

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

        target = UnitGroupUnit(enemyGroup, RandomInt(1, count));
        if (UnitIsValid(target)) {
            OrderSetTargetUnit(ord, target);
            if (UnitOrderIsValid(aiUnit, ord)) {
                return ord;

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

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

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

        }
        
        OrderSetTargetUnit(ord, unitToCheck);
        if (!UnitOrderIsValid(aiUnit, ord)) {
            continue;

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

    }
    
    OrderSetTargetUnit(ord, targetUnit);
    if (!UnitOrderIsValid(aiUnit, ord)) {
        return null;

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


    if (bestReplicate >= 0) {
        OrderSetTargetUnit(ord, bestUnit);
        if (UnitOrderIsValid(aiUnit, ord)) {
            return ord;

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

    
    if (targetUnit != null) {
        OrderSetTargetUnit(ord, targetUnit);                        
    }
    else {

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

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

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

    //  Check target validity.
    //
    OrderSetTargetUnit(ord, target);
    if (UnitOrderIsValid(aiUnit, ord)) {
        return ord;

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

                if (unitToCheck != null) {
                    ord = AICreateOrder(player, command, e_AB_TransportLoadUnit); // load the bunker.
                    OrderSetTargetUnit(ord, unitToCheck);
                }
            }

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

            else {
                ord = AICreateOrder(player, command, e_AB_TransportLoadUnit);
                OrderSetTargetUnit(ord, unitToCheck);
            }
            break;

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

        }
        if (airOnly == false || UnitTestPlane(curTarget, c_planeAir) == true) {
            OrderSetTargetUnit(ord, curTarget);
            if (UnitOrderIsValid(aiUnit, ord)) {
                AICast(aiUnit, ord, c_noMarker, c_castHold);

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

    }

    OrderSetTargetUnit(ord, UnitGroupUnit(targetGroup, 1));
    if (UnitOrderIsValid(aiUnit, ord)) {
        AICast(aiUnit, ord, c_noMarker, c_castHold);

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


    target = UnitGroupClosestToPoint(airGroup, loc);
    OrderSetTargetUnit(ord, target);
    if (!UnitOrderIsValid(aiUnit, ord)) {
        return null;

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

    }

    OrderSetTargetUnit(ord, targetUnit);
    if (!UnitOrderIsValid(aiUnit, ord)) {
        return null;

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


    // try a random target first
    OrderSetTargetUnit(ord, UnitGroupUnit(targetGroup, RandomInt(1, count)));
    if (!UnitOrderIsValid(aiUnit, ord)) {
        ord = AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_forwards);  

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


    // try a random target first
    OrderSetTargetUnit(ord, UnitGroupUnit(targetGroup, RandomInt(1, count)));
    if (!UnitOrderIsValid(aiUnit, ord)) {
        ord = AIUnitGroupGetValidOrder(targetGroup, ord, aiUnit, c_forwards);