# How to detect when a unit group is dead?

Status
Not open for further replies.

#### Cakiabo

Level 2
I need to make a quest be completed when a unit group is dead I try to make but I dont know what event must put. What event i put?

#### millzy

Level 15
a unit dies

unit is in ur group

remove from group

if number of units in ur group is = 0 do ur actions

#### ap0calypse

Level 28
I'm nitpicking here, but using an integer to count the amount of units in a group is way faster.

• Unit Group - Add {Unit} to unitGroup
• Set unitsInGroup = (unitsInGroup + 1)
• Unit Group - Remove {Unit} from unitGroup
• Set unitsInGroup = (unitsInGroup - 1)
• Conditions
• unitsInGroup Equal to 0
This is easier in JASS, but can be done in GUI as well (sometimes, not always).
In your current trigger, it can be done (as millzy already said: remove unit from the group when he's dead, and also decrease the integer variable - then check if the integer variable is 0).

#### millzy

Level 15
why do u need the int vairable when u can just check when the group is emptY?

#### GangSpear

Level 13
If the group empty,we can turn off the trigger? O_O

#### ap0calypse

Level 28
why do u need the int vairable when u can just check when the group is emptY?
I'm nitpicking here, but using an integer to count the amount of units in a group is way faster.

Below, I will put the 3 options in JASS.
First we have the 'bad' options: "Unit group is empty" and "Amount of units in Unit Group equal to 0".
Then we have my option, with the integer, at the end.

Check it for yourself, and if you know sufficient JASS, you should immediately know why the integer variable is so extremely awesomely useful in this case.

Checking if the unit group is empty: (Boolean comparison - Unit group is empty)
JASS:
``````function IsUnitGroupEmptyBJEnum takes nothing returns nothing
set bj_isUnitGroupEmptyResult = false
endfunction

function IsUnitGroupEmptyBJ takes group g returns boolean
// If the user wants the group destroyed, remember that fact and clear
// the flag, in case it is used again in the callback.
local boolean wantDestroy = bj_wantDestroyGroup
set bj_wantDestroyGroup = false

set bj_isUnitGroupEmptyResult = true
call ForGroup(g, function IsUnitGroupEmptyBJEnum)

// If the user wants the group destroyed, do so now.
if (wantDestroy) then
call DestroyGroup(g)
endif
return bj_isUnitGroupEmptyResult
endfunction

function Trig_Melee_Initialization_Conditions takes nothing returns boolean
if ( not ( IsUnitGroupEmptyBJ(Group) == true ) ) then
return false
endif
return true
endfunction``````

Amount of units in unit group = 0: (Integer comparison - Count units in Unit Group)
JASS:
``````function CountUnitsInGroupEnum takes nothing returns nothing
set bj_groupCountUnits = bj_groupCountUnits + 1
endfunction

function CountUnitsInGroup takes group g returns integer
// If the user wants the group destroyed, remember that fact and clear
// the flag, in case it is used again in the callback.
local boolean wantDestroy = bj_wantDestroyGroup
set bj_wantDestroyGroup = false

set bj_groupCountUnits = 0
call ForGroup(g, function CountUnitsInGroupEnum)

// If the user wants the group destroyed, do so now.
if (wantDestroy) then
call DestroyGroup(g)
endif
return bj_groupCountUnits
endfunction

function Trig_Melee_Initialization_Conditions takes nothing returns boolean
if ( not ( CountUnitsInGroup(Group) == 0 ) ) then
return false
endif
return true
endfunction``````

Integer equal to 0: (Integer comparison - Variable)
JASS:
``````function Trig_Melee_Initialization_Conditions takes nothing returns boolean
if ( not ( udg_unitsInGroup == 0 ) ) then
return false
endif
return true
endfunction``````

This is what the trigger could look like:
• Group Actions
• Events
• Unit - A unit Dies
• Conditions
• ((Triggering unit) is in yourGroup) Equal to True
• Actions
• Set unitsInGroup = (unitsInGroup - 1)
• Unit Group - Remove (Triggering unit) from yourGroup
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• unitsInGroup Equal to 0
• Then - Actions
• -------- All units in the group are dead, place actions here --------
• Else - Actions

Status
Not open for further replies.

Replies
18
Views
945
Replies
6
Views
995
Replies
10
Views
1K
Replies
10
Views
2K
Replies
10
Views
1K