- Joined
- Jun 19, 2009
- Messages
- 556
vJASS:
scope Spawn initializer Init
globals
hashtable hash = InitHashtable()
integer creeps = 0
endglobals
private function Creeps takes nothing returns nothing
local integer c = 0
loop
exitwhen c > 19
set c = c + 1
call CreateUnit(Player(PLAYER_NEUTRAL_AGGRESSIVE), ChooseRandomCreep(GetRandomInt(1,10)),0,0,GetRandomReal(0,360))
set creeps = creeps + 1
endloop
endfunction
private function Alliance takes nothing returns nothing
local integer p1 = 0
local integer p2 = 0
loop
exitwhen p1 > 3
loop
exitwhen p2 > 3
call SetPlayerAllianceStateAllyBJ(Player(p1),Player(p2),true)
set p2 = p2 + 1
endloop
set p2 = 0
set p1 = p1 + 1
endloop
endfunction
private function Barracks takes nothing returns nothing
local integer p = 0
local real a = 0
local location s = GetRectCenter(GetPlayableMapRect())
local location l
local unit b
loop
exitwhen p > 3
set l = PolarProjectionBJ(s,3000,a)
set b = CreateUnitAtLoc(Player(p),'hbar',l,bj_UNIT_FACING)
call SaveUnitHandle(hash,0,GetHandleId(Player(p)),b)
set a = a + 90
set p = p + 1
endloop
call RemoveLocation(l)
call RemoveLocation(s)
set b = null
endfunction
private function CreepCount takes nothing returns boolean
if creeps > 0 then
return true
endif
return false
endfunction
private function Spawn takes nothing returns nothing
local integer p = 0
local integer r = 0
local real x
local real y
local unit b
local unit u
loop
exitwhen p > 3
set b = LoadUnitHandle(hash,0,GetHandleId(Player(p)))
set x = GetUnitX(b)
set y = GetUnitY(b)
set r = GetRandomInt(0,1)
if IsUnitAliveBJ(b) then
if r > 0 then
set u = CreateUnit(Player(p),'hfoo',x,y,bj_UNIT_FACING)
else
set u = CreateUnit(Player(p),'hrif',x,y,bj_UNIT_FACING)
endif
call IssuePointOrder(u,"attack",0,0)
endif
set p = p + 1
endloop
set b = null
set u = null
endfunction
private function Owner takes nothing returns boolean
if (GetOwningPlayer(GetTriggerUnit()) == Player(PLAYER_NEUTRAL_AGGRESSIVE) and IsUnitType(GetTriggerUnit(),UNIT_TYPE_SUMMONED) == false) then
return true
endif
return false
endfunction
private function Type takes nothing returns boolean
return IsUnitType(GetEnumUnit(),UNIT_TYPE_STRUCTURE) == false
endfunction
private function Kill takes nothing returns nothing
call ExplodeUnitBJ(GetEnumUnit())
endfunction
private function Death takes nothing returns nothing
local group g
set creeps = creeps - 1
if creeps == 0 then
set g = GetUnitsInRectMatching(GetPlayableMapRect(), Condition(function Type))
call ForGroup(g,function Kill)
call DisplayTextToForce(GetPlayersAll(),"You won!")
endif
call DestroyGroup(g)
endfunction
private function Init takes nothing returns nothing
local trigger trg = CreateTrigger()
call TriggerRegisterTimerEvent(trg, 0.2, false)
call TriggerAddAction(trg, function Creeps)
call TriggerAddAction(trg, function Alliance)
call TriggerAddAction(trg, function Barracks)
set trg = CreateTrigger()
call TriggerRegisterTimerEvent(trg,2.5,true)
call TriggerAddCondition(trg, Condition(function CreepCount))
call TriggerAddAction(trg, function Spawn)
set trg = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(trg,EVENT_PLAYER_UNIT_DEATH)
call TriggerAddCondition(trg, Condition(function Owner))
call TriggerAddAction(trg,function Death)
set trg = null
endfunction
endscope