// requires Unit Indexer and dummy unit
globals
//-------------------------------------------------------------
//configure following 3 lines:
constant boolean SET_ACQUIRE_RANGE = true
constant real ACQUIRE_RANGE = 220.00
constant real RESPAWN_TIME = 30.00 //seconds
//-------------------------------------------------------------
constant integer DUMMY = 'n000'
//---
unit array g_hostileU
integer array g_hostileId
real array g_hostileX
real array g_hostileY
real array g_hostileFace
real array g_hostileRepawnTime
real array g_hostileLife
integer g_hostileTotal = 0
group g_hostileGroup
timer spellTimer
real array spellDuration
integer array spellHostileUnitNr
endglobals
//===============================================
//-------------------------------------------------------------------------------
//----find unique number for each hostile unit ----------------------------
//-------------------------------------------------------------------------------
function Hostile_GetUnitNumber takes unit u returns integer
local integer i = 0
loop //find in array unit u, its number will be "i"
exitwhen (i > g_hostileTotal) or (u == g_hostileU[i])
set i=i+1
endloop
if i>g_hostileTotal then
return -1
endif
return i
endfunction
//================================================
function Hostile_LoopEnum takes nothing returns nothing
local unit d = GetEnumUnit()
local integer id = GetUnitUserData(d)
local integer i = spellHostileUnitNr[id]
if spellDuration[id] == 4.00 then
call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Orc\\Reincarnation\\ReincarnationTarget.mdl", g_hostileX[i], g_hostileY[i]))
elseif spellDuration[id] == 3.00 then
set g_hostileU[i] = CreateUnit(Player(12), g_hostileId[i], g_hostileX[i], g_hostileY[i], g_hostileFace[i])
static if SET_ACQUIRE_RANGE then
call SetUnitAcquireRange(g_hostileU[i], ACQUIRE_RANGE)
endif
endif
//---
set spellDuration[id] = spellDuration[id] - 1.00
if spellDuration[id] <= 0.00 then // Clean up any data attached to this spell
call GroupRemoveUnit(g_hostileGroup, d)
call RemoveUnit(d)
if FirstOfGroup(g_hostileGroup) == null then
call PauseTimer(spellTimer)
endif
endif
set d=null
endfunction
//-------------------------------------------------------------------------------
function Hostile_Loop takes nothing returns nothing
call ForGroup(g_hostileGroup, function Hostile_LoopEnum)
endfunction
//-------------------------------------------------------------------------------
function Hostile_OnDeath takes nothing returns boolean // EVENT_PLAYER_UNIT_DEATH
local integer i = Hostile_GetUnitNumber(GetDyingUnit())
local integer id
if i == -1 then
return false
endif
set bj_lastCreatedUnit = CreateUnit(Player(15), DUMMY, g_hostileX[i], g_hostileY[i], 0.00)
set id = GetUnitUserData(bj_lastCreatedUnit)
set spellHostileUnitNr[id] = i
set spellDuration[id] = g_hostileRepawnTime[i]
//---
if FirstOfGroup(g_hostileGroup) == null then
call TimerStart(spellTimer, 1.00, true, function Hostile_Loop)
endif
call GroupAddUnit(g_hostileGroup, bj_lastCreatedUnit)
return false
endfunction
//===============================================
//===============================================
function Hostile_CountPreplaced takes nothing returns nothing
//Count preplaced Hostile units
local unit u = null
local integer i=0
local group ug = CreateGroup()
call GroupEnumUnitsInRect(ug, bj_mapInitialPlayableArea, null)
loop
set u = FirstOfGroup(ug)
exitwhen u == null
if GetOwningPlayer(u) == Player(12) and (not IsUnitType(u, UNIT_TYPE_STRUCTURE)) then
set g_hostileU[i] = u
set g_hostileId[i] = GetUnitTypeId(u)
set g_hostileX[i] = GetUnitX(u)
set g_hostileY[i] = GetUnitY(u)
set g_hostileFace[i] = GetUnitFacing(u)
set g_hostileRepawnTime[i] = RESPAWN_TIME // you can use point value of unit-type to diffrentiate respawn time
static if SET_ACQUIRE_RANGE then
call SetUnitAcquireRange(u, ACQUIRE_RANGE)
endif
set i=i+1
endif
call GroupRemoveUnit(ug, u)
endloop
call GroupClear(ug)
set g_hostileTotal = i
set g_hostileGroup = CreateGroup()
set spellTimer = CreateTimer()
call DestroyGroup(ug)
set ug=null
set u=null
endfunction
//===================================================================
function InitTrig_HostileRespawn takes nothing returns nothing
local trigger t = CreateTrigger()
set gg_trg_HostileRespawn = CreateTrigger( )
call TriggerRegisterTimerEvent(gg_trg_HostileRespawn, 0.00, false) //at 0sec of the game
call TriggerAddAction( gg_trg_HostileRespawn, function Hostile_CountPreplaced)
//---
call TriggerRegisterPlayerUnitEvent(t, Player(12), EVENT_PLAYER_UNIT_DEATH, null)
call TriggerAddCondition(t, Condition(function Hostile_OnDeath))
set t=null
endfunction