- Joined
- Mar 25, 2016
- Messages
- 1,327
JASS:
scope UnitSpawn initializer Init
globals
private group barracks
private integer counter
private integer creepCount
endglobals
private function CreepSpawn takes nothing returns nothing
if(GetOwningPlayer(GetTriggerUnit()) == Player( PLAYER_NEUTRAL_AGGRESSIVE ) ) then
set creepCount = creepCount + 1
endif
endfunction
private function CreepDeath takes nothing returns nothing
local group g
local unit u
local boolean noCreeps = TRUE
set creepCount = creepCount -1
if(creepCount == 0) then
call GroupClear( barracks )
set g = CreateGroup()
call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
call GroupRemoveUnit(g, u)
if(GetUnitTypeId(u)=='hfoo' or GetUnitTypeId(u)=='hrif') then
call SetUnitExploded(u, true)
call KillUnit(u)
endif
endloop
call DisplayTextToForce(bj_FORCE_ALL_PLAYERS, "You won!")
call DestroyGroup(g)
endif
set u = null
set g = null
endfunction
private function Group takes nothing returns nothing
local unit u = GetEnumUnit()
local unit spawn
local integer spawntype
set counter = counter + 1
if(GetRandomInt(0,1)==0) then
set spawntype = 'hfoo'
else
set spawntype = 'hrif'
endif
if(GetWidgetLife(u)<0.405) then
call GroupRemoveUnit(barracks, u)
else
set spawn = CreateUnit(GetOwningPlayer(u), spawntype, GetUnitX(u), GetUnitY(u), 0)
call IssuePointOrder(spawn, "attack", 0, 0)
endif
set u = null
endfunction
private function Periodic takes nothing returns nothing
local timer t = GetExpiredTimer()
set counter = 0
call ForGroup(barracks, function Group)
if( counter == 0 ) then
call PauseTimer(t)
call DestroyTimer(t)
endif
set t = null
endfunction
private function Init takes nothing returns nothing
local integer i = 0
local real x = 0
local real y = 0
local timer t
local trigger trg = CreateTrigger()
local region r = CreateRegion()
call TriggerRegisterPlayerUnitEvent(trg, Player( PLAYER_NEUTRAL_AGGRESSIVE ), EVENT_PLAYER_UNIT_DEATH, null)
call TriggerAddAction(trg, function CreepDeath)
set trg = CreateTrigger()
call RegionAddRect(r, bj_mapInitialPlayableArea)
call TriggerRegisterEnterRegion(trg, r, null)
call TriggerAddAction(trg, function CreepSpawn)
loop
exitwhen i>=20
call CreateUnit(Player( PLAYER_NEUTRAL_AGGRESSIVE ), ChooseRandomCreep(-1), x, y, 0)
set i = i + 1
endloop
set creepCount = 0
set barracks = CreateGroup()
set x = 3000
call GroupAddUnit( barracks, CreateUnit(Player(0), 'hbar', x, y, 0))
set x = - 3000
call GroupAddUnit( barracks, CreateUnit(Player(2), 'hbar', x, y, 0))
set y = - 3000
set x = 0
call GroupAddUnit( barracks, CreateUnit(Player(1), 'hbar', x, y, 0))
set y = 3000
call GroupAddUnit( barracks, CreateUnit(Player(3), 'hbar', x, y, 0))
set t = CreateTimer()
call TimerStart(t, 2.5, TRUE, function Periodic)
endfunction
endscope
Took longer than expected, because I had to track the amount of living enemy units, because of reincarnation.