was needed for a chain spell i am making which targets always the weakest units,and i decided to post it.
Source
function GroupGetWeakestUnit takes group g returns unit
local unit temp
local unit weakest
local group g2 = CreateGroup()
call GroupAddGroup(g,g2)
if CountUnitsInGroup(g2)<1 then
return null
endif
set weakest = FirstOfGroup(g2)
call GroupRemoveUnit(g2,weakest)
set temp = FirstOfGroup(g2)
call GroupRemoveUnit(g2,temp)
if GetWidgetLife(temp)<GetWidgetLife(weakest) then
set weakest = temp
endif
loop
exitwhen temp == null
set temp = FirstOfGroup(g2)
if GetUnitState(weakest,UNIT_STATE_LIFE)>GetUnitState(temp,UNIT_STATE_LIFE) then
set weakest = temp
endif
call GroupRemoveUnit(g2,temp)
set temp = FirstOfGroup(g2)
endloop
call DestroyGroup(g2)
set g2 = null
set temp = null
set g = null
return weakest
endfunction
if I wanted to use this for a spell, say the spell I just uploaded blink storm, so that it always targets the weakest unit in a group, how exactly could I go about doing that?
from what I can decern of it, and I cant really tell how you are picking your unit group, or if you even do, i could say make all that stuff into a trigger, then have it run after I make the unit group( say pick all unit within 600 range matching blah), then have my trigger target the weakest unit variable that this picks