function AutoLastHit takes nothing returns nothing
local unit u = GetFilterUnit()
local unit hero = GetLocalPlayer()
local real damage
set damage = BlzGetUnitBaseDamage(hero, 0)
local bool hasHit = false
local group enemies = GetUnitsInRangeOfLocMatching(200.00, unit, Condition(function EnumEnemy))
local real lowestHealth = 99999999.0
local unit lowestHealthUnit
local real health
local unit creap
local real creapHealth
local real distance
local real attackRange = BlzGetUnitWeaponRealField(hero, UNIT_WEAPON_RF_ATTACK_RANGE, 0)
local real bestCreapHealth = 99999999.0
local unit bestCreap
local boolean canLastHit
local boolean dangerous
local boolean nearTower
local real towerRange = 900.00
local group nearbyEnemies = GetUnitsInRangeOfLocMatching(towerRange, unit, Condition(function Tower()))
local real maxTowerRange = 0.00
local unit enemy
if not IsUnitType(u, UNIT_TYPE_HERO) then
set health = GetWidgetLife(u)
if health < lowestHealth then
set lowestHealth = health
set lowestHealthUnit = u
endif
if BlzGetUnitBooleanField(u, UNIT_BF_RAISED) == false and not IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE) then
if IsUnitType(u, UNIT_TYPE_STRUCTURE) then set dangerous = false
else set dangerous = true
endif
if dangerous == false then
if IsUnitInGroup(u, nearbyEnemies) then
set nearTower = true
loop
set enemy = FirstOfGroup(nearbyEnemies)
exitwhen enemy == null
set distance = GetUnitFlyHeight(u) - GetLocationZ(GetUnitLoc(enemy))
if distance >= 0.00 and distance < 100.00 then
set canLastHit = false
set hasHit = false
exitwhen true
else
call GroupRemoveUnit(nearbyEnemies, enemy)
endif
endloop
endif
set creap = u
set creapHealth = GetWidgetLife(creap)
set distance = DistanceBetweenUnits(hero, u)
set canLastHit = false
if damage * 1.1 >= GetWidgetLife(u) then set canLastHit = true
elseif damage >= GetWidgetLife(u) and distance < attackRange * 1.05 then set canLastHit = true
endif
if canLastHit == true then
set hasHit = true
call IssueTargetOrder(hero, "attack", creap)
call IssueTargetOrderWait(hero, "attack", creap)
call PolledWait(BlzGetUnitAttackCooldown(hero, 0) + 0.01)
else
if creapHealth < bestCreapHealth then
set bestCreapHealth = creapHealth
set bestCreap = creap
endif
endif
endif
endif
endif
endif
call ReleaseGroup(enemies)
endfunction
function EnumEnemy takes nothing returns boolean
if GetOwningPlayer(GetFilterUnit()) == Player(PLAYER_NEUTRAL_HOSTILE) then
if IsUnitType(GetFilterUnit(), UNIT_TYPE_ATTACK) or IsUnitType(GetFilterUnit(), UNIT_TYPE_ALIVE) then
return true
endif
endif
return false
endfunction
function Tower takes nothing returns boolean
if GetOwningPlayer(GetFilterUnit()) == Player(PLAYER_NEUTRAL_AGGRESSIVE) and IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) then
return true
endif
return false
endfunction
function Initialize takes nothing returns nothing
local timer t = CreateTimer()
call TimerStart(t, 0.05, true, function AutoLastHit)
endfunction
library AutoLastHit initializer Init requires Storm
private function AutoLastHit takes nothing returns nothing
local unit u = GetFilterUnit()
local unit hero = GetLocalPlayer()
local real damage
set damage = BlzGetUnitBaseDamage(hero, 0)
local bool hasHit = false
local group enemies = GetUnitsInRangeOfLocMatching(200.00, unit, Condition(function EnumEnemy))
local real lowestHealth = 99999999.0
local unit lowestHealthUnit
local real health
local unit creap
local real creapHealth
local real distance
local real attackRange = BlzGetUnitWeaponRealField(hero, UNIT_WEAPON_RF_ATTACK_RANGE, 0)
local real bestCreapHealth = 99999999.0
local unit bestCreap
local boolean canLastHit
local boolean dangerous
local boolean nearTower
local real towerRange = 900.00
local group nearbyEnemies = GetUnitsInRangeOfLocMatching(towerRange, unit, Condition(function Tower()))
local real maxTowerRange = 0.00
local unit enemy
if not IsUnitType(u, UNIT_TYPE_HERO) then
set health = GetWidgetLife(u)
if health < lowestHealth then
set lowestHealth = health
set lowestHealthUnit = u
endif
if BlzGetUnitBooleanField(u, UNIT_BF_RAISED) == false and not IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE) then
if IsUnitType(u, UNIT_TYPE_STRUCTURE) then set dangerous = false
else set dangerous = true
endif
if dangerous == false then
if IsUnitInGroup(u, nearbyEnemies) then
set nearTower = true
loop
set enemy = FirstOfGroup(nearbyEnemies)
exitwhen enemy == null
set distance = GetUnitFlyHeight(u) - GetLocationZ(GetUnitLoc(enemy))
if distance >= 0.00 and distance < 100.00 then
set canLastHit = false
set hasHit = false
exitwhen true
else
call GroupRemoveUnit(nearbyEnemies, enemy)
endif
endloop
endif
set creap = u
set creapHealth = GetWidgetLife(creap)
set distance = DistanceBetweenUnits(hero, u)
set canLastHit = false
if damage * 1.1 >= GetWidgetLife(u) then set canLastHit = true
elseif damage >= GetWidgetLife(u) and distance < attackRange * 1.05 then set canLastHit = true
endif
if canLastHit == true then
set hasHit = true
call IssueTargetOrder(hero, "attack", creap)
call IssueTargetOrderWait(hero, "attack", creap)
call PolledWait(BlzGetUnitAttackCooldown(hero, 0) + 0.01)
else
if creapHealth < bestCreapHealth then
set bestCreapHealth = creapHealth
set bestCreap = creap
endif
endif
endif
endif
endif
endif
call ReleaseGroup(enemies)
endfunction
private function EnumEnemy takes nothing returns boolean
if GetOwningPlayer(GetFilterUnit()) == Player(PLAYER_NEUTRAL_HOSTILE) then
if IsUnitType(GetFilterUnit(), UNIT_TYPE_ATTACK) or IsUnitType(GetFilterUnit(), UNIT_TYPE_ALIVE) then
return true
endif
endif
return false
endfunction
private function Tower takes nothing returns boolean
if GetOwningPlayer(GetFilterUnit()) == Player(PLAYER_NEUTRAL_AGGRESSIVE) and IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) then
return true
endif
return false
endfunction
private function Init takes nothing returns nothing
local timer t = CreateTimer()
call TimerStart(t, 0.05, true, function AutoLastHit)
call BJDebugMsg("AutoLastHit is loaded!")
endfunction
endlibrary