• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

EnumUnitsInRange() loop

Status
Not open for further replies.
Level 20
Joined
Jul 14, 2011
Messages
3,213
<< EDIT >>
Sorry, wrong place to post. This should be in trigger section.

Hi!

I'm rmking my bomberman map (Signature) and I'm improving the way the bomb explodes. In the past 4 dummies were being created and moved in each direction, but handling so many units is slow, so, I decided to do it with a Group

Every point of STR increases the explotion range in each direction by 128.00, so I loop from 1 to current str of the unit, and increase/reduce the X/Y based on the direction (using 4 loops, one for each direction) and checking if the point is pathable and else.

This is what I have so far.
JASS:
// Unit Kill
function GroupKill takes unit u returns nothing
    local unit a
    loop
        set a = FirstOfGroup(udg_TGroup)
        call UnitDamageTarget(u, a, 5000, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
        call GroupRemoveUnit(udg_TGroup, a)
        exitwhen a == null
    endloop
endfunction

    // Up
    set bj_forLoopAIndex = 0
    loop
        exitwhen bj_forLoopAIndex > str
        set y = y + 128
        if IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY) == false then
            call DestroyEffect(AddSpecialEffect("FireLordDeathExplode.mdl", x, y))            
            call GroupEnumUnitsInRange(udg_TGroup, x, y, 128, null)
            call GroupKill(udg_Bomber[pi])
        else
            set bj_forLoopAIndex = str
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex+1
    endloop
    set y = GetUnitY(u)
    // Down
        set bj_forLoopAIndex = 0
    loop
        exitwhen bj_forLoopAIndex > str
        set y = y - 128
        if IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY) == false then
            call DestroyEffect(AddSpecialEffect("FireLordDeathExplode.mdl", x, y))            
            call GroupEnumUnitsInRange(udg_TGroup, x, y, 128, null)
            call GroupKill(udg_Bomber[pi])
        else
            set bj_forLoopAIndex = str
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex+1
    endloop
    set y = GetUnitY(u)
    // Right
    set bj_forLoopAIndex = 0
    loop
        exitwhen bj_forLoopAIndex > str
        set x = x + 128
        if IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY) == false then
            call DestroyEffect(AddSpecialEffect("FireLordDeathExplode.mdl", x, y))            
            call GroupEnumUnitsInRange(udg_TGroup, x, y, 128, null)
            call GroupKill(udg_Bomber[pi])
        else
            set bj_forLoopAIndex = str
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex+1
    endloop
    set x = GetUnitX(u)
    // Left
    set bj_forLoopAIndex = 0
    loop
        exitwhen bj_forLoopAIndex > str
        set x = x - 128
        if IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY) == false then
            call DestroyEffect(AddSpecialEffect("FireLordDeathExplode.mdl", x, y))            
            call GroupEnumUnitsInRange(udg_TGroup, x, y, 128, null)
            call GroupKill(udg_Bomber[pi])
        else
            set bj_forLoopAIndex = str
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex+1
    endloop

Is there a way to improve it?

<< EDIT >>

Updated the Script several times.
 
Last edited:
Level 20
Joined
Jul 14, 2011
Messages
3,213
So, should I damage everytime I enum units...

<< Edited the main script.>>

It works now, kills, explodes, everything, but I'd like to know if there's a way to improve it. Seems a little "repetitive"
 
Level 26
Joined
Aug 18, 2009
Messages
4,099
So, should I damage everytime I enum units...

You can push the units to another group. Of course can it be condensed. Only the x/y modifiers change per direction. You may put them into an array to directly attach them to a loop iteration or determine them via ifs.

Code:
for each direction
    for each length
        ...
 
Status
Not open for further replies.
Top