globals
group g = CreateGroup()
endglobals
// ===========================================================
function MatchingUnit takes unit u returns boolean
return u == UNIT_TYPE_HERO // this is just an example you will have to set your own filter
endfunction
function example takes real x, real y, real radius returns nothing
local unit u
call GroupEnumUnitsInRange(g,x,y,radius,null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
if MatchingUnit(u) then @/*EDIT:you could also apply the filter here and no need for another function call*/@
// Do stuff here
endif
call GroupRemoveUnit(g,u)
endloop
endfunction
bj_lastCreatedGroup
is fine than creating a group...if the loop is instant,bj_lastCreatedGroup
is fine than creating a group....
bj_lastCreatedGroup
but I assumed the loop is not instant when I wrote this example.Optimization is great and all, but sometimes just write clean code...if the loop is instant,bj_lastCreatedGroup
is fine than creating a group...
about X seconds, you could use timers instead then pause the timer if you dont use the function...
... just use a boolexpr, there's really no reason not to)
call GroupEnumUnitsInRange(g,x,y,radius,null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
if (First comparison) and (Second comparison) and (Third comparison), etc. then
// Do stuff here
endif
call GroupRemoveUnit(g,u)
endloop
endfunction
function Trig_CountUnitGroup_Actions takes nothing returns nothing
local unit u
local group g =CreateGroup()
local integer unitCount
call GroupEnumUnitsInRange(g, 0, 0, 1000000000, null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
if(GetUnitTypeId(u) == 'hf00')then
set unitCount =unitCount + 1
call BJDebugMsg(I2S(unitCount))
endif
call GroupRemoveUnit(g,u)
endloop
endfunction
//===========================================================================
function InitTrig_CountUnitGroup takes nothing returns nothing
set gg_trg_CountUnitGroup = CreateTrigger()
call TriggerRegisterPlayerChatEvent(gg_trg_CountUnitGroup, Player(0), "-uc", true)
call TriggerAddAction( gg_trg_CountUnitGroup, function Trig_CountUnitGroup_Actions )
endfunction
call GroupEnumUnitsInRange(g, 0, 0, 1000000000, null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
if(GetUnitTypeId(u) == 'hf00')then
set unitCount =unitCount + 1
call BJDebugMsg(I2S(unitCount))
endif
call GroupRemoveUnit(g,u)
endloop
call GroupEnumUnitsInRange(g, 0, 0, 1000000000, null)
for u in g
if(GetUnitTypeId(u) == 'hf00')then
set unitCount =unitCount + 1
call BJDebugMsg(I2S(unitCount))
endif
endfor
Yes it's
function Trig_CountUnitGroup_Actions takes nothing returns nothing
local unit u
local group g =CreateGroup()
local integer unitCount
local integer i
call GroupEnumUnitsInRange(g, 0, 0, 1000000000, null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
set i = i + 1
if(GetUnitTypeId(u) == 'hf00')then
set unitCount =unitCount + 1
call BJDebugMsg("COUNT IS : "+I2S(unitCount))
else
call BJDebugMsg("LOOP :"+I2S(i))
endif
call GroupRemoveUnit(g,u)
endloop
endfunction
//===========================================================================
function InitTrig_CountUnitGroup takes nothing returns nothing
set gg_trg_CountUnitGroup = CreateTrigger()
call TriggerRegisterPlayerChatEvent(gg_trg_CountUnitGroup, Player(0), "-uc", true)
call TriggerAddAction( gg_trg_CountUnitGroup, function Trig_CountUnitGroup_Actions )
endfunction
function Trig_CountUnitGroup_Actions takes nothing returns nothing
local unit u
local group g =CreateGroup()
local integer unitCount
local integer i
call GroupEnumUnitsInRange(g, 0, 0, 1000000000, null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
set i = i + 1
if(GetUnitTypeId(u) == 'hf00')then
set unitCount =unitCount + 1
call BJDebugMsg("COUNT IS : "+I2S(unitCount))
endif
call GroupRemoveUnit(g,u)
endloop
call DestroyGroup(g)
set g -= null
endfunction
//===========================================================================
function InitTrig_CountUnitGroup takes nothing returns nothing
set gg_trg_CountUnitGroup = CreateTrigger()
call TriggerRegisterPlayerChatEvent(gg_trg_CountUnitGroup, Player(0), "-uc", true)
call TriggerAddAction( gg_trg_CountUnitGroup, function Trig_CountUnitGroup_Actions )
endfunction
Are the 'hf00' units in the map?
local unit u
local group g =CreateGroup()
local integer i = 0
call GroupEnumUnitsInRange(g, 0, 0, 1000000000, null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
set i = i + 1
if(GetUnitTypeId(u) == 'hfoo')then
set i = i + 1
call BJDebugMsg("COUNT IS : " + I2S(i))
endif
call GroupRemoveUnit(g,u)
endloop
call DestroyGroup(g)