- Joined
- May 20, 2009
- Messages
- 822
JASS:
function BuffBurn_Sorted takes nothing returns nothing
local integer swapped = 0
local unit temp
local integer aindex = 0
local integer first = 0
local integer second = 0
local integer MaxIndex
set MaxIndex = (udg_BBTargetFilterMaxIndex - 1)
// Step 1: sort the array
loop
set aindex = 0
set swapped = 0
loop
exitwhen aindex > MaxIndex
set first = UnitCountBuffsExBJ(bj_BUFF_POLARITY_POSITIVE, bj_BUFF_RESIST_EITHER, udg_BBTargetFilterArray[aindex], false, false)
set second = UnitCountBuffsExBJ(bj_BUFF_POLARITY_POSITIVE, bj_BUFF_RESIST_EITHER, udg_BBTargetFilterArray[aindex + 1], false, false)
if (first < second) then
set swapped = 1
set temp = udg_BBTargetFilterArray[aindex + 1]
set udg_BBTargetFilterArray[aindex + 1] = udg_BBTargetFilterArray[aindex]
set udg_BBTargetFilterArray[aindex] = temp
endif
set aindex = (aindex + 1)
endloop
exitwhen swapped == 0
endloop
// Step 2: iterate over the array and issue target orders
set aindex = 0
loop
exitwhen aindex > udg_BBTargetFilterMaxIndex
call DisplayTextToForce( GetPlayersAll(), "Targeting unit with " + I2S(UnitCountBuffsExBJ(bj_BUFF_POLARITY_POSITIVE, bj_BUFF_RESIST_EITHER, udg_BBTargetFilterArray[aindex], false, false)) + " buffs" )
call IssueTargetOrderBJ( udg_BBUnit[udg_BBAutoTempInit], "poisonarrowstarg", udg_BBTargetFilterArray[aindex] )
set aindex = aindex + 1
exitwhen true
endloop
endfunction
My cousin made this code for me, he doesn't have a lot of experience in JASS, and neither do I, so neither of us know if this is the right way to do things.
What this is suppose to do is:
Units in range of the unit that has this spell will be sorted by which one has the most buffs, and then the unit with the spell will be ordered to target that unit (Which would be the unit that have the most buffs).
It only seems to do that sometimes, though...
Can anyone help?
Last edited: