//below function optimized.
function Trig_Locust_Heal_Conditions takes nothing returns boolean
return GetSpellAbilityId()=='A001'
endfunction
//optimized function below.
function Healers_Filter takes nothing returns boolean
return IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE) == false and GetUnitLifePercent(GetFilterUnit())<100 and IsUnitAliveBJ(GetFilterUnit()) and GetUnitAbilityLevelSwapped('A002',GetFilterUnit())==0 and IsUnitAlly(GetFilterUnit(),GetOwningPlayer(GetTriggerUnit()))
endfunction
function Trig_Locust_Heal_Actions takes nothing returns nothing
local location L
local group G
local integer IA=1
local integer IB=10
local integer IC
local integer ID=1+2*GetUnitAbilityLevel(GetTriggerUnit(),'A001')
local unit U
loop
exitwhen IA>IB
set L=GetUnitLoc(GetTriggerUnit())
set G=GetUnitsInRangeOfLocMatching(350.,L,Condition(function Healers_Filter))
set IC=1
loop
exitwhen IC>ID
set U=GroupPickRandomUnit(G)
if(U!=null)then
call SetWidgetLife(U,GetUnitState(U,UNIT_STATE_LIFE)+10)
endif
set IC=IC+1
endloop
call PolledWait(1.)
call DestroyGroup(G)
call RemoveLocation(L)
set IA=IA+1
endloop
endfunction
//Make sure below function is called by some other trigger as currently the spell will not work as there is nothing to create the trigger so that it may be triggered.
function StartTrigger_Locust_Heal takes nothing returns nothing
set gg_trg_Locust_Heal=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_Locust_Heal,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(gg_trg_Locust_Heal,Condition(function Trig_Locust_Heal_Conditions))
call TriggerAddAction(gg_trg_Locust_Heal,function Trig_Locust_Heal_Actions)
endfunction
function InitTrig_Locust_Heal takes nothing returns nothing
endfunction