I've made an ability that is supposed to damage enemy units in an AOE 5 times. However, the 4 last times my allied units (even structures) are damaged aswell, I don't see why as I haven't changed the condition, please explain.
Code:
function Trig_Fire_Conditions takes nothing returns boolean
return GetSpellAbilityId()=='A01Q'
endfunction
function burrn takes nothing returns boolean
return (GetWidgetLife(GetFilterUnit())>0) and (IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(GetTriggerUnit()))) and (IsUnitType(GetFilterUnit(),UNIT_TYPE_MECHANICAL)==false)
endfunction
function Trig_Fire_Actions takes nothing returns nothing
local unit caster=GetTriggerUnit()
local location l1=GetUnitLoc(caster)
local location l2=GetSpellTargetLoc()
local integer lvl=GetUnitAbilityLevel(caster,'A01Q')
local real dmg=100
local integer iS=1
local boolexpr b=Condition(function burrn)
local group g
local integer iF
local unit array uUnits
local integer i=1
local integer times=5
call PolledWait((DistanceBetweenPoints(l1,l2)-90)/575)
loop
exitwhen i>times
set g=GetUnitsInRangeOfLocMatching(200,l2,b)
set iF=CountUnitsInGroup(g)
loop
exitwhen iS>iF
set uUnits[iS]=FirstOfGroup(g)
call UnitDamageTarget(caster,uUnits[iS],dmg,false,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_MAGIC,null)
call GroupRemoveUnit(g,uUnits[iS])
set uUnits[iS]=null
set iS=iS+1
endloop
call PolledWait(0.1)
call DestroyGroup(g)
set iS=1
set i=i+1
endloop
call RemoveLocation(l1)
call RemoveLocation(l2)
call DestroyBoolExpr(b)
set l1=null
set l2=null
set b=null
set caster=null
set g=null
endfunction
//===========================================================================
function InitTrig_Fire takes nothing returns nothing
set gg_trg_Fire = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Fire, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Fire, Condition( function Trig_Fire_Conditions ) )
call TriggerAddAction( gg_trg_Fire, function Trig_Fire_Actions )
endfunction