//*************************************************************************
//*
//* Globals required
//*
//*************************************************************************
//* udg_Index Counts the amount of instances
//* udg_Counter Counts instances
//* udg_FadeGroup Group for fading units
//* udg_Timer Global timer that runs whole script
//* udg_fade[] Counts alpha for given unit
//* For instances support:
//* udg_Player[]
//* udg_UnitId[]
//* udg_Amount[]
//* udg_Delay[]
//* udg_CurWave[]
//* udg_x1[]
//* udg_y1[]
//* udg_x2[]
//* udg_y2[]
//*************************************************************************
//*
//* Code itself
//*
//*************************************************************************
//* The interval of OnExpire function (means how quickly unit's alpha changes)
constant function FadeInterval takes nothing returns real
return 0.03125
endfunction
//* Constant fade duration.
constant function FadeTime takes nothing returns real
return 2.
endfunction
//* Determinates inteval between unit creation
constant function SpawnInterval takes nothing returns real
return 8.
endfunction
function Register takes player owner, integer id, integer amount, integer delay, real rect1x, real rect1y, real rect2x, real rect2y returns nothing
set udg_Index = udg_Index + 1
set udg_Player[udg_Index] = owner
set udg_UnitId[udg_Index] = id
set udg_Amount[udg_Index] = amount
set udg_Delay[udg_Index] = delay
set udg_CurWave[udg_Index] = 0
set udg_x1[udg_Index] = rect1x
set udg_y1[udg_Index] = rect1y
set udg_x2[udg_Index] = rect2x
set udg_y2[udg_Index] = rect2y
endfunction
function Callback takes nothing returns nothing
local unit u = GetEnumUnit()
local integer id = GetUnitUserData(u)
if udg_fade[id] < 255 then
set udg_fade[id] = udg_fade[id] + (255 / R2I(FadeTime() / FadeInterval()))
call SetUnitVertexColor(u, 255, 255, 255, udg_fade[id])
else
call GroupRemoveUnit(udg_FadeGroup, u)
set udg_Counter = udg_Counter - 1
if udg_Counter == 0 then
call PauseTimer(udg_Timer)
endif
endif
set u = null
endfunction
function OnExpire takes nothing returns nothing
call ForGroup(udg_FadeGroup, function Callback)
endfunction
function RunSpawn takes nothing returns boolean
local integer i = udg_Index
local integer j
loop
exitwhen i == 0
set udg_CurWave[i] = udg_CurWave[i] + 1
if udg_CurWave[i] == udg_Delay[i] then
set udg_CurWave[i] = 0
set j = udg_Amount[i]
loop
exitwhen j == 0
set bj_lastCreatedUnit = CreateUnit(udg_Player[i], udg_UnitId[i], udg_x1[i], udg_y1[i], bj_UNIT_FACING)
call IssuePointOrderById(bj_lastCreatedUnit, 851983, udg_x2[i], udg_y2[i])
if udg_Counter == 0 then
call TimerStart(udg_Timer, FadeInterval(), true, function OnExpire)
endif
set udg_Counter = udg_Counter + 1
set udg_fade[GetUnitUserData(bj_lastCreatedUnit)] = 0
call GroupAddUnit(udg_FadeGroup, bj_lastCreatedUnit)
set j = j - 1
endloop
endif
set i = i - 1
endloop
return false
endfunction
function InitTrig_CallSpawn takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterTimerEvent(t, SpawnInterval(), true)
call TriggerAddCondition(t, Condition(function RunSpawn))
set udg_Index = 0
set udg_Counter = 0
set t = null
endfunction