# Last Attack
Grammar — Returns the time the specified unit unit was last attacked
Flags —Native
|Function
Returns the time the specified unit was last attacked.
# Arguments
unit
— Unit
Returns — int
native int AILastAttack(unit u);
# Related
Category: AI Advanced / Tactical / Functions
- Same Command —
bool
— AISameCommand - Last Attacker —
unit
— AILastAttacker - Last Attack —
int
— AILastAttack - Get Wants To Move Status —
bool
— AIControlWantsToMove - Is Ignored By Wave —
bool
— AIIsIgnoredByWave - Is In Combat —
bool
— AIUnitIsInCombat - Get Cloaked Attacker —
point
— AIGetCloakedAttacker - Get Best Target Point On Group —
point
— AIBestTargetPoint - Find Units —
unitgroup
— AIFindUnits - Get Default Combat Priority —
unit
— AIDefaultCombatPriority - Combat Diff Flag Special High Priority —
bool
— AICombatDiffFlagCatSpecialHighPrio - Combat Diff Flag Splash High Priority —
bool
— AICombatDiffFlagCatSplashHighPrio - Combat Diff Flag Timed Low Priority —
bool
— AICombatDiffFlagCatTimedLowPrio - Combat Diff Flag Workers Normal Priority —
bool
— AICombatDiffFlagCatWorkersNormalPrio - Combat Diff Flag Sort Buildings Priority —
bool
— AICombatDiffFlagCatSortBuildingsPrio - Combat Diff Flag Healers —
bool
— AICombatDiffFlagTieBreakHealers - Combat Diff Flag Low Health —
bool
— AICombatDiffFlagTieBreakLowHP - Combat Diff Flag Bonus Damage —
bool
— AICombatDiffFlagTieBreakBonusDamage - Combat Diff Flag Injured —
bool
— AICombatDiffFlagTieBreakInjured - Combat Diff Flag Detector —
bool
— AICombatDiffFlagTieBreakDetector - Combat Diff Flag Siege Range —
bool
— AICombatDiffFlagTieBreakRange - Does Unit Have Tactical Disabled —
bool
— AIIsTacticalDisabled
# Examples
campaigns/swarm.sc2campaign — base.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.sc2campaign — base.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.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.sc2campaign/base.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/void.sc2campaign — base.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.sc2map — MapScript.galaxy:1873
}
if (((GameGetMissionTime() - AILastAttack(gv_titanicWarpPrism)) <= 15.0)) {
lv_phaseThreshold = true;
}
mods/core.sc2mod — base.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.sc2mod — base.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.sc2mod — base.sc2data/TriggerLibs/Tactical/TactProtAI.galaxy:1609
}
if (AILastAttack(aiUnit) < (AIGetTime() - 4.0)) {
return null;
}
mods/core.sc2mod — base.sc2data/TriggerLibs/Tactical/TactProtAI.galaxy:1651
}
if (AILastAttack(aiUnit) < (AIGetTime() - 3.0)) {
return null;
}
mods/core.sc2mod — base.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.sc2mod — base.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.sc2mod — base.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.sc2mod — base.sc2data/TriggerLibs/Tactical/TactProtAI.galaxy:1598
}
if (AILastAttack(aiUnit) < (AIGetTime() - 4.0)) {
return null;
}
mods/starcoop/starcoop.sc2mod — base.sc2data/TriggerLibs/Tactical/TactProtAI.galaxy:1640
}
if (AILastAttack(aiUnit) < (AIGetTime() - 3.0)) {
return null;
}
mods/starcoop/starcoop.sc2mod — base.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.sc2mod — base.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.sc2mod — base.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.sc2mod — base.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");