HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Simple Unit Group Question

12-09-2006, 06:42 AM#1
Pyrogasm
A simple question regarding unit groups: If I use a periodic trigger to add units to a unit group variable such as this:
Trigger:
Add
Collapse Events
Time - Every 0.50 seconds of game time
Conditions
Collapse Actions
Set Festering_Presence_Group[1] = (Units in (Playable map area) matching (((Triggering unit) has buff Festering Presence (Level 1)) Equal to True))
Set Festering_Presence_Group[2] = (Units in (Playable map area) matching (((Triggering unit) has buff Festering Presence (Level 2)) Equal to True))
Set Festering_Presence_Group[3] = (Units in (Playable map area) matching (((Triggering unit) has buff Festering Presence (Level 3)) Equal to True))
Will it re-add units to the unit group that were already in it, thus making the group exponentially large? If that's the case, could I fix this by adding a DestroyGroup custom script for each of the groups at the beginning of the trigger? For more information, the buff comes from an Aura.

EDIT: Is there any advantage to setting a unit's life versus making the unit damage itself. Is one faster/more efficient/less drain on system memory? I know about the credit for kills thing, but for having units take damage over time and that sort of stuff.
12-09-2006, 07:54 AM#2
xombie
First of all, doing what you do is extremely leaky. Each time you set the variables you are disbanding a group without destroying or clearing it, and this happens every 0.50 seconds. 3 leaks every 0.50 seconds can add up. To answer your question more specifically, it will set this variable to a completely new group with only the newly designated units in it. To answer your other question, it depends what you want to do. Setting unit life actually subtracts an exact amount from the unit's HP (if thats how you are using it), whereas damage-unit uses resistances and things to get its damage across. In terms of speed, setting the unit's life I believe is quicker, but less effective. For what you are doing, I would use damage-unit. Also, here is a way to fix your memory leaks:

Collapse JASS:
function Trig_Add_Actions takes nothing returns nothing
    local group temp = CreateGroup()
    local rect map = bj_mapInitialPlayableArea
    local unit u

    call GroupEnumUnitsInRect( temp, map, null )
    // if you want the group to reset itself each time, use this code, otherwise delete it.
    call GroupClear( udg_Festering_Presence_Group[1] )
    call GroupClear( udg_Festering_Presence_Group[2] )
    call GroupClear( udg_Festering_Presence_Group[3] )

// if it is impossible that one unit has both buffs, use this code.
    loop
        set u = FirstOfGroup( temp )
        exitwhen ( u == null )
        if ( GetUnitAbilityLevel( u, <buff raw code lvl1> ) > 0 ) then
            call GroupAddUnit( udg_Festering_Presence_Group[1], u )
        elseif ( GetUnitAbilityLevel( u, <buff raw code lvl2> ) > 0 ) then
            call GroupAddUnit( udg_Festering_Presence_Group[2], u )
        elseif ( GetUnitAbilityLevel( u, <buff raw code lvl3> ) > 0 ) then
            call GroupAddUnit( udg_Festering_Presence_Group[3], u )
        endif
        call GroupRemoveUnit( temp, u )
    endloop

// if it is possible that one unit has both buffs, use this code.
    loop
        set u = FirstOfGroup( temp )
        exitwhen ( u == null )
        if ( GetUnitAbilityLevel( u, <buff raw code lvl1> ) > 0 ) then
            call GroupAddUnit( udg_Festering_Presence_Group[1], u )
        endif
        if ( GetUnitAbilityLevel( u, <buff raw code lvl2> ) > 0 ) then
            call GroupAddUnit( udg_Festering_Presence_Group[2], u )
        endif
        if ( GetUnitAbilityLevel( u, <buff raw code lvl3> ) > 0 ) then
            call GroupAddUnit( udg_Festering_Presence_Group[3], u )
        endif
        call GroupRemoveUnit( temp, u )
    endloop

    call DestroyGroup( temp )
    set temp = null
    set map = null
endfunction

function InitTrig_Add takes nothing returns nothing
    set gg_trg_Add = CreateTrigger()
    call TriggerRegisterTimeEvent( gg_trg_Add, 0.50, true )
    call TriggerAddActions( gg_trg_Add, function Trig_Add_Actions )
endfunction

This is all done off the top of my head, so if anybody else notices anything wrong please say so.

<buff raw code lvlX> is the raw code of he desired buff. Simply go to where the buff is located, and press ctrl+D and it will convert everything to raw code. You should see a number such as: 'B000' if it a custom buff. Simply replace (including the ' marks) <buff raw code lvlX> with that buffcode.
12-09-2006, 08:26 AM#3
Pyrogasm
So (as I had said above) I could fix it by doing this, right?
Trigger:
Add
Collapse Events
Time - Every 0.50 seconds of game time
Conditions
Collapse Actions
Custom Script: call DestroyGroup( udg_Festering_Presence_Group[1] )
Custom Script: call DestroyGroup( udg_Festering_Presence_Group[2] )
Custom Script: call DestroyGroup( udg_Festering_Presence_Group[3] )
Set Festering_Presence_Group[1] = (Units in (Playable map area) matching (((Triggering unit) has buff Festering Presence (Level 1)) Equal to True))
Set Festering_Presence_Group[2] = (Units in (Playable map area) matching (((Triggering unit) has buff Festering Presence (Level 2)) Equal to True))
Set Festering_Presence_Group[3] = (Units in (Playable map area) matching (((Triggering unit) has buff Festering Presence (Level 3)) Equal to True))
The buff is applied by an aura, so the unit will be re-added again when the trigger runs again, I would assume.
12-09-2006, 07:19 PM#4
xombie
Yea, that should fix it, just put a GroupClear before you destroy the group incase that makes any difference at all.
12-09-2006, 08:29 PM#5
Pyrogasm
Does clearing it before it's destroyed really matter? If so, I've been leaking horrendously...
12-09-2006, 08:33 PM#6
wyrmlord
I don't think it matters. I've never done it that way and my maps have been fine.
12-09-2006, 10:34 PM#7
Anitarf
I have no recollection of anyone ever suggesting that groups should be cleared before being destroyed. The code should be fine as it is.

Just understand this: you are not adding units to your existing unit group, that function creates a new unit group every time. You might know that now but you originaly said that you were adding units and nobody has yet replied to correct you on that specificaly.
12-09-2006, 11:11 PM#8
Pyrogasm
Oh, thanks for clarifying.