HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

buff - countdown timer

01-23-2007, 12:27 PM#1
Doomhammer
Idea: have the countdown timer at the beginning of a game displaying the remaining time using icons/buffs on a selected unit.
A green icon equals 3 seconds, a yellow icon equals 2 seconds and a red icon equals 1 second (time remaining). I've got a 15 (0.5*30) sec countdown, so I made 5 buffs with green icons, 1 yellow and 1 red. After starting my global timer (udg_Dialog_Timer) with 30 sec, I'm now using these two functions. It's not quite worked out yet, since I haven't done much with timers before. I'd be happy to receive any constructive criticism on how to improve my 'buff-clock'

Collapse JASS:
function TimerBuffs takes nothing returns nothing
local unit u=GetEnumUnit()
local integer k=R2I(0.5*TimerGetRemaining(udg_Dialog_Timer))
local integer l=ModuloInteger(k,3)
set k=k/3
if (l==0) then
    call UnitRemoveAbility(u, 'B00B')  //remove red icon
elseif (l==1) then
    call UnitRemoveAbility(u, 'B00D')  //remove yellow icon
    call UnitAddAbility(u, 'B00B')     //add red icon
elseif (l==2) then
    call UnitAddAbility(u, 'B00D')    //add yellow icon
    if (k==4) then                      // ...and following: remove 5th, 4th, 3rd... green icon
        call UnitRemoveAbility(u, 'B00C')
    elseif (k==3) then
        call UnitRemoveAbility(u, 'B00A')
    elseif (k==2) then
        call UnitRemoveAbility(u, 'B009')
    elseif (k==1) then
        call UnitRemoveAbility(u, 'B008')
    elseif (k==0) then
        call UnitRemoveAbility(u, 'B007')
    endif
endif
set u=null
endfunction


function TimerPeriod takes nothing returns nothing
    local timer t=CreateTimer()
    local group g=CreateGroup()
    local boolexpr b=Filter(function OneId_filter)  // filters out dummy units only
    set bj_groupEnumTypeId ='h00I'                  // 'h00I' int for dummy
    call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, b)
    call ForGroup(g, function TimerBuffs)
    if (TimerGetRemaining(udg_Dialog_Timer)>0.99) then
        call TimerStart(t, 1.00, true, function TimerPeriod) // recursive call (works?)
    endif
    call DestroyTimer(t)
    call DestroyBoolExpr(b)
    call DestroyGroup(g)
    set t=null
    set b=null
    set g=null
endfunction