function Attack_IsOutOfRange takes unit attacked, unit attacker returns boolean
local string name = GetObjectName(GetUnitTypeId(attacker))
local real range
local real dist = SquareRoot((GetUnitX(attacker) - GetUnitX(attacked)) * (GetUnitX(attacker) - GetUnitX(attacked)) + (GetUnitY(attacker) - GetUnitY(attacked)) * (GetUnitY(attacker) - GetUnitY(attacked)))
set name = SubString(name,4,7)
set range = S2R(name) * 2
//call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,10,"Range: "+R2S(range)+"\nDistance: "+R2S(dist))
return dist > range
endfunction
function Attack_RangeCheck takes nothing returns nothing
local unit damaged = GetTriggerUnit()
local unit damager = GetEventDamageSource()
local real life = GetUnitState(damaged,UNIT_STATE_LIFE)
//Now we find out if the unit is out of range
if Attack_IsOutOfRange(damaged,damager) and IsUnitType(damager,UNIT_TYPE_MELEE_ATTACKER) then
call AddAbilityTimed(damaged,'A01Y',1,0)
call ResetLifeToVal(damaged,life)
call AddFadingTextTag("missed",GetUnitX(damager),GetUnitY(damager),255,0,0,255)
endif
//Boobs - ( . Y . )
set damaged = null
set damager = null
endfunction
//===========================================================================
function InitTrig_Out_of_Range_Attacks takes nothing returns nothing
call GenericDamage_QueueFuncByAttack("Attack_RangeCheck")
endfunction