• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • ✅ HD Level Design Contest #1 POLL is now OPEN! Check out the stunning visuals of the final entries. 🔗Click here to cast your vote!

How to detect when a unit group is dead?

Status
Not open for further replies.
Level 2
Joined
Nov 21, 2009
Messages
16
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?
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
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).
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
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.
Top