# Last Attack

Grammar — Returns the time the specified unit unit was last attacked
FlagsNative | Function

Returns the time the specified unit was last attacked.

# Arguments

  • unit — Unit

Returns — int

native int AILastAttack(unit u);

Category: AI Advanced / Tactical / Functions

# Examples

campaigns/swarm.sc2campaignbase.sc2maps/maps/campaign/swarm/zhybrid02.sc2map/MapScript.galaxy:1032

    lv_lastAttacker = AILastAttacker(lp_hybrid);
    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.sc2campaignbase.sc2maps/maps/campaign/swarm/zhybrid02.sc2map/MapScript.galaxy:1041

    }
    else {
        if ((lv_lastAttacker != null) && (UnitIsAlive(lv_lastAttacker) == true) && ((FixedToInt(GameGetMissionTime()) - AILastAttack(lp_hybrid)) < 5)) {
            gv_aIHybridAttacker[lv_indexHybrid] = lv_lastAttacker;
        }

campaigns/swarm.sc2campaign/base.sc2maps/maps/campaign/swarm/zhybrid02.sc2mapMapScript.galaxy:1032

    lv_lastAttacker = AILastAttacker(lp_hybrid);
    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.sc2mapMapScript.galaxy:1041

    }
    else {
        if ((lv_lastAttacker != null) && (UnitIsAlive(lv_lastAttacker) == true) && ((FixedToInt(GameGetMissionTime()) - AILastAttack(lp_hybrid)) < 5)) {
            gv_aIHybridAttacker[lv_indexHybrid] = lv_lastAttacker;
        }

campaigns/void.sc2campaignbase.sc2maps/maps/campaign/void/pulnar01.sc2map/MapScript.galaxy:1873

        }

        if (((GameGetMissionTime() - AILastAttack(gv_titanicWarpPrism)) <= 15.0)) {
            lv_phaseThreshold = true;
        }

campaigns/void.sc2campaign/base.sc2maps/maps/campaign/void/pulnar01.sc2mapMapScript.galaxy:1873

        }

        if (((GameGetMissionTime() - AILastAttack(gv_titanicWarpPrism)) <= 15.0)) {
            lv_phaseThreshold = true;
        }

mods/core.sc2modbase.sc2data/TriggerLibs/MeleeWaveAI.galaxy:243


    leaderType = UnitGetType(leader);
    if ((leaderType == c_PU_Oracle) && (AILastAttack(leader) > (AIGetTime()-c_wasAttackedRecently))) {
        if (state != c_waveStateRetreat) {
DebugAIPlayerWave(player, "set divert = retreat to harass point");

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

    
    // if we're not under attack, don't try to merge
    if (AILastAttack(aiUnit) < (AIGetTime() - 4.0)) {
        return false;
    }

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

    }

    if (AILastAttack(aiUnit) < (AIGetTime() - 4.0)) {
        return null;
    }

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

    }

    if (AILastAttack(aiUnit) < (AIGetTime() - 3.0)) {
        return null;
    }

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


    // don't try if we've been attacked recently (taking damage interrupts it).
    if (AILastAttack(aiUnit) > (AIGetTime() - 4.0)) {
        return null;
    }

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

    
    // Don't jump if we're not taking damage
    if (AILastAttack(aiUnit) < (AIGetTime() - 3.0)) {
        return null;
    }

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


    // if we haven't been attacked recently, don't use it
    if (AILastAttack(aiUnit) < (AIGetTime() - 4.0)) {
        return;
    }

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

    }

    if (AILastAttack(aiUnit) < (AIGetTime() - 4.0)) {
        return null;
    }

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

    }

    if (AILastAttack(aiUnit) < (AIGetTime() - 3.0)) {
        return null;
    }

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


    // don't try if we've been attacked recently (taking damage interrupts it).
    if (AILastAttack(aiUnit) > (AIGetTime() - 4.0)) {
        return null;
    }

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

    
    // Don't jump if we're not taking damage
    if (AILastAttack(aiUnit) < (AIGetTime() - 3.0)) {
        return null;
    }

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


    // if we haven't been attacked recently, don't use it
    if (AILastAttack(aiUnit) < (AIGetTime() - 4.0)) {
        return;
    }

mods/warcoop/warmeleeai.sc2modbase.sc2data/TriggerLibs/MeleeWaveAI.galaxy:332


    leaderType = UnitGetType(leader);
    if ((leaderType == c_PU_Oracle) && (AILastAttack(leader) > (AIGetTime()-c_wasAttackedRecently))) {
        if (state != c_waveStateRetreat) {
DebugAIPlayerWave(player, "set divert = retreat to harass point");