function H2U takes handle h returns unit
return h
return null
endfunction
function UnitFadeTimed_child takes nothing returns nothing
local timer tim = GetExpiredTimer()
local integer alpha = GetHandleInt(tim,"alpha")
local integer interval = GetHandleInt(tim,"interval")
local integer max = GetHandleInt(tim,"max")
local unit u = H2U(GetHandleHandle(tim,"unit"))
if (max > 0) then
set alpha = alpha - R2I(((0.05*interval+1)))
call SetUnitVertexColor(u,255,255,255,alpha)
else
call FlushHandleLocals(tim)
call DestroyTimer(tim)
endif
call SetHandleInt(tim,"alpha",alpha)
call SetHandleInt(tim,"max",(max-1))
set tim = null
set u = null
endfunction
function UnitFadeTimed takes unit u, real time, real percent returns nothing
local integer alpha = 255
local integer interval
local integer max
local timer FadeTim = CreateTimer()
if (time == 0) then
call SetUnitVertexColor(u,255,255,255,0)
return
endif
if (percent > 100) or (percent <= 0) then
set percent = 100
endif
if (percent != 100) then
set percent = RAbsBJ(percent-100)
endif
set interval = R2I(((alpha/time)+1))
set max = R2I((((time*(percent/100))/0.05)+1))
if (max <= 0) then
return
endif
call SetHandleHandle(FadeTim,"unit",u)
call SetHandleInt(FadeTim,"alpha",alpha)
call SetHandleInt(FadeTim,"interval",interval)
call SetHandleInt(FadeTim,"max",max)
call TimerStart(FadeTim,0.05,true,function UnitFadeTimed_child)
set FadeTim = null
endfunction