scope merge initializer init
globals
private integer abilityid = 'Aens'
private group g
endglobals
private function forgroup takes nothing returns nothing
if GetUnitTypeId(GetEnumUnit()) == GetUnitTypeId(GetTriggerUnit()) then
call UnitAddAbility(GetEnumUnit(), abilityid)
call UnitAddAbility(GetTriggerUnit(), abilityid)
endif
endfunction
private function select takes nothing returns boolean
local group gr = CreateGroup()
if IsUnitInGroup(GetTriggerUnit(), g) then
return false
endif
set gr = g
call GroupRemoveUnit(gr, GetTriggerUnit())
call ForGroup(gr, function forgroup)
call GroupAddUnit(g, GetTriggerUnit())
call GroupClear(gr)
call DestroyGroup(gr)
set gr = null
return false
endfunction
private function deselect takes nothing returns boolean
call GroupRemoveUnit(g, GetTriggerUnit())
call UnitRemoveAbility(GetTriggerUnit(), abilityid)
return false
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
local trigger tt = CreateTrigger()
local integer i = 0
set g = CreateGroup()
loop
exitwhen i > 12
call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SELECTED, null)
call TriggerRegisterPlayerUnitEvent(tt, Player(i), EVENT_PLAYER_UNIT_DESELECTED, null)
set i = i + 1
endloop
call TriggerAddCondition(t, Condition(function select))
call TriggerAddCondition(tt, Condition(function deselect))
endfunction
endscope