scope TownHallFix initializer Init
//===========================================================================
globals
private group TmpGroup
endglobals
//===========================================================================
private function Conditions takes nothing returns boolean
return IsUnitType(GetTriggerUnit(), UNIT_TYPE_STRUCTURE) == true or IsUnitType(GetTriggerUnit(), UNIT_TYPE_PEON) == true
endfunction
//===========================================================================
private function Enum takes nothing returns boolean
return GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0.405
endfunction
//===========================================================================
private function Actions takes nothing returns nothing
local player trig = GetOwningPlayer(GetTriggerUnit())
local player death = GetOwningPlayer(GetDyingUnit())
local integer Count = 0
local unit f
call GroupEnumUnitsOfPlayer(TmpGroup, death, Condition(function Enum))
loop
set f = FirstOfGroup(TmpGroup)
exitwhen f == null
set Count = Count + 1
call GroupRemoveUnit(TmpGroup, f)
endloop
if Count <= 0 then
call CustomDefeatBJ(death, "Defeat!")
endif
if GetPlayers() <= 1 then
call CustomVictoryBJ(trig, true, true)
endif
endfunction
//===========================================================================
private function Init takes nothing returns nothing
local trigger tri = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(tri, EVENT_PLAYER_UNIT_DEATH)
call TriggerAddCondition(tri, Condition(function Conditions))
call TriggerAddAction(tri, function Actions)
set TmpGroup = CreateGroup()
endfunction
endscope