"GroupEnumUnitsInRangeCounted" not working ? :S

Komaqtion

You can change this now in User CP.
Reaction score
469
Hi!

I was just making a small spell for some1, and he only wanted 1 - 2 - 3 units to be affected, so I thought I'd use the "GroupEnumUnitsInRangeCounted" native...

I haven't actually used this native before (XD) but I though it'd do exactly what it says, only add a max amount of units to the group, but that doesn't seem to work :(

Here's the code atm, and now it's only supposed to add 1 unit to the group, right ? :S

Well, the debug msg is showing 8 !?

How can that happen ? :S

Here's the code:
JASS:
scope Spell initializer Init

    globals
        private constant integer SPELL_ID = 'A00H'
        private constant integer BUFF_ID = 'B000'
        private constant integer THUNDER_ID = 'A00I'
        private constant integer DUMMY_ID = 'dmmy'
        
        private group enum = CreateGroup()
        private unit cast
    endglobals
    
    private function Filters takes nothing returns boolean
        return IsUnitType( GetFilterUnit(), UNIT_TYPE_STRUCTURE ) != true and IsUnitAlly( GetFilterUnit(), GetOwningPlayer( cast ) ) != true and GetWidgetLife( GetFilterUnit() ) >= 0.405
    endfunction
    
    private function Spell_Check takes nothing returns boolean
        return GetSpellAbilityId() == SPELL_ID and GetUnitAbilityLevel( GetTriggerUnit(), BUFF_ID ) > 0
    endfunction
    
    private function ForGroup_Actions takes nothing returns nothing
        local unit u = GetEnumUnit()
        local player p = GetOwningPlayer ( u )
        local real x = GetUnitX( u )
        local real y = GetUnitY( u )
        local unit d = CreateUnit( p, DUMMY_ID, x, y, bj_UNIT_FACING )
        local real dur = 1.0
        local integer lvl = GetUnitAbilityLevel( cast, SPELL_ID )
        
        call UnitApplyTimedLife( d, 'BTLF', dur )
        call UnitAddAbility( d, THUNDER_ID )
        call SetUnitAbilityLevel( d, THUNDER_ID, lvl )
        call IssueImmediateOrder( d, "thunderclap" )
        
        set u = null
        set d = null
    endfunction
    
    private function Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local integer lvl = GetUnitAbilityLevel( u, SPELL_ID )
        local real x = GetUnitX( u )
        local real y = GetUnitY( u )
        local real radius = I2R( ( 100 * lvl ) + 500 )
        
        set cast = u
        
        call GroupEnumUnitsInRangeCounted( enum, x, y, radius, Filter( function Filters ), 1 )
        
        call BJDebugMsg( I2S( CountUnitsInGroup( enum ) ) )
        
        call ForGroup( enum, function ForGroup_Actions )
        
        set u = null
    endfunction

//===========================================================================
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        
        loop
            exitwhen i >= 11
            call TriggerRegisterPlayerUnitEvent( t, Player( i ), EVENT_PLAYER_UNIT_SPELL_EFFECT, null )
            
            set i = i + 1
        endloop
        
        call TriggerAddCondition( t, Condition( function Spell_Check ) )
        call TriggerAddAction( t, function Actions )
    endfunction

endscope


Any ideas, or have I done something wrong ? :S
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
An other Not Yet Implanted i guess, GUI don't use it at all where it could be used easily (blizzard.j).
I suspect it's exactly the same function with a different name and one more argument not already (and will never be) used, that's all.

Don't use it.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, I now have this, but the debug message now show up 6 times, when there are 8 units nearby, and also they first show 8 three times, and then 0 three times...

So, it doesn't seem that "return" stops the entire "ForGroup" thread, only the current "ForGroup" function...

JASS:
scope Spell initializer Init

    globals
        private constant integer SPELL_ID = 'A00H'
        private constant integer BUFF_ID = 'B000'
        private constant integer THUNDER_ID = 'A00I'
        private constant integer DUMMY_ID = 'dmmy'
        
        private group enum = CreateGroup()
        private unit cast
        private integer int = 0
    endglobals
    
    private function Filters takes nothing returns boolean
        return IsUnitType( GetFilterUnit(), UNIT_TYPE_STRUCTURE ) != true and IsUnitAlly( GetFilterUnit(), GetOwningPlayer( cast ) ) != true and GetWidgetLife( GetFilterUnit() ) >= 0.405
    endfunction
    
    private function Spell_Check takes nothing returns boolean
        return GetSpellAbilityId() == SPELL_ID and GetUnitAbilityLevel( GetTriggerUnit(), BUFF_ID ) > 0
    endfunction
    
    private function ForGroup_Actions takes nothing returns nothing
        local unit u = GetEnumUnit()
        local player p = GetOwningPlayer ( u )
        local real x = GetUnitX( u )
        local real y = GetUnitY( u )
        local unit d = CreateUnit( p, DUMMY_ID, x, y, bj_UNIT_FACING )
        local real dur = 1.0
        local integer lvl = GetUnitAbilityLevel( cast, SPELL_ID )
        
        set int = int + 1
        
        if int >= 3 then
            call GroupClear( enum )
            
            set int = 0
            
            return
        endif
        
        call UnitApplyTimedLife( d, 'BTLF', dur )
        call UnitAddAbility( d, THUNDER_ID )
        call SetUnitAbilityLevel( d, THUNDER_ID, lvl )
        call IssueImmediateOrder( d, "thunderclap" )
        
        call BJDebugMsg( I2S( CountUnitsInGroup( enum ) ) )
        
        set u = null
        set d = null
    endfunction
    
    private function Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local integer lvl = GetUnitAbilityLevel( u, SPELL_ID )
        local real x = GetUnitX( u )
        local real y = GetUnitY( u )
        local real radius = I2R( ( 100 * lvl ) + 500 )
        
        set cast = u
        
        call GroupEnumUnitsInRange( enum, x, y, radius, Filter( function Filters ) )        
        call ForGroup( enum, function ForGroup_Actions )
        
        set u = null
    endfunction

//===========================================================================
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        
        loop
            exitwhen i >= 11
            call TriggerRegisterPlayerUnitEvent( t, Player( i ), EVENT_PLAYER_UNIT_SPELL_EFFECT, null )
            
            set i = i + 1
        endloop
        
        call TriggerAddCondition( t, Condition( function Spell_Check ) )
        call TriggerAddAction( t, function Actions )
    endfunction

endscope
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
No i mean inside the filter, use an if/then/else.

JASS:
scope Spell initializer Init

    globals
        private constant integer SPELL_ID = 'A00H'
        private constant integer BUFF_ID = 'B000'
        private constant integer THUNDER_ID = 'A00I'
        private constant integer DUMMY_ID = 'dmmy'
        
        private group enum = CreateGroup()
        private unit cast
        private integer Counted
    endglobals
    
    private function Filters takes nothing returns boolean
        if Counted <= 0 then //the maximum of units are already be added
            return false
        endif
        if IsUnitType( GetFilterUnit(), UNIT_TYPE_STRUCTURE ) != true and IsUnitAlly( GetFilterUnit(), GetOwningPlayer( cast ) ) != true and GetWidgetLife( GetFilterUnit() ) >= 0.405 then
            set Counted = Counted-1
            return true
        else
            return false
        endif
    endfunction
    
    private function Spell_Check takes nothing returns boolean
        return GetSpellAbilityId() == SPELL_ID and GetUnitAbilityLevel( GetTriggerUnit(), BUFF_ID ) > 0
    endfunction
    
    private function ForGroup_Actions takes nothing returns nothing
        local unit u = GetEnumUnit()
        local player p = GetOwningPlayer ( u )
        local real x = GetUnitX( u )
        local real y = GetUnitY( u )
        local unit d = CreateUnit( p, DUMMY_ID, x, y, bj_UNIT_FACING )
        local real dur = 1.0
        local integer lvl = GetUnitAbilityLevel( cast, SPELL_ID )
        
        call UnitApplyTimedLife( d, 'BTLF', dur )
        call UnitAddAbility( d, THUNDER_ID )
        call SetUnitAbilityLevel( d, THUNDER_ID, lvl )
        call IssueImmediateOrder( d, "thunderclap" )
        
        set u = null
        set d = null
    endfunction
    
    private function Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local integer lvl = GetUnitAbilityLevel( u, SPELL_ID )
        local real x = GetUnitX( u )
        local real y = GetUnitY( u )
        local real radius = I2R( ( 100 * lvl ) + 500 )
        
        set cast = u
        
        set Counted = 5 // when 5 units following the conditions inside the filter has been added to the group, no more units will be added
        
        call GroupEnumUnitsInRange( enum, x, y, radius, Filter( function Filters ))
        
        call BJDebugMsg( I2S( CountUnitsInGroup( enum ) ) )
        
        call ForGroup( enum, function ForGroup_Actions )
        
        set u = null
    endfunction

//===========================================================================
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        
        loop
            exitwhen i >= 11
            call TriggerRegisterPlayerUnitEvent( t, Player( i ), EVENT_PLAYER_UNIT_SPELL_EFFECT, null )
            
            set i = i + 1
        endloop
        
        call TriggerAddCondition( t, Condition( function Spell_Check ) )
        call TriggerAddAction( t, function Actions )
    endfunction

endscope


But yes in fact it's not "increase" but "decrease" :)
 

Xorifelse

I'd love to elaborate about discussions...........
Reaction score
87
And if you only wanted the first unit inside the group..

JASS:
call GroupEnum*( g, etc.. )
set u = FirstOfGroup( g )


However, if you want to count to a larger number I suggest using this loop instead of filters.

JASS:
loop
    set u = FirstOfGroup( g )
    set i = i + 1
    exitwhen u == null or i > 1
    call GroupRemoveUnit( g, u )
    

    // Do your things..
endloop


No i mean inside the filter, use an if/then/else.
This is rather a senseless way to do it, what if the unit group contains 1000 units. The filter function is called 1000 times while only the first "5" units are usefull. This loop is in this case the better way.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
This is rather a senseless way to do it, what if the unit group contains 1000 units. The filter function is called 1000 times while only the first "5" units are usefull. This loop is in this case the better way.

No.

You can't avoid each enum ok,but it only adds one check in the filter (X+1), and when it's true one setting of variable added.

When units all needed are added, there is only one check, instead of X, and it returns false, doesn't seems senseless for me.

It's definitely better than adding 1000 useless units and only use 5 inside it.

Also if you need the group for an instant, without any wait between the enum and the use, like this example in fact.
You can code directly inside the enum and always return false, never true, best way ever.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, so I did this now instead but now the message shows 0 ... :(

JASS:
scope Spell initializer Init

    globals
        private constant integer SPELL_ID = 'A00H'
        private constant integer BUFF_ID = 'B000'
        private constant integer THUNDER_ID = 'A00I'
        private constant integer DUMMY_ID = 'dmmy'
        
        private group enum = CreateGroup()
        private unit cast
        private integer int = 0
    endglobals
    
    private function Filters takes nothing returns boolean
        local unit u
        local player p
        local real x
        local real y
        local unit d
        local real dur
        local integer lvl
        
        set int = int + 1
        if IsUnitType( GetFilterUnit(), UNIT_TYPE_STRUCTURE ) != true and IsUnitAlly( GetFilterUnit(), GetOwningPlayer( cast ) ) != true and GetWidgetLife( GetFilterUnit() ) >= 0.405 and int <= 3 then
            set u = GetFilterUnit()
            set p = GetOwningPlayer ( u )
            set x = GetUnitX( u )
            set y = GetUnitY( u )
            set d = CreateUnit( p, DUMMY_ID, x, y, bj_UNIT_FACING )
            set dur = 1.0
            set lvl = GetUnitAbilityLevel( cast, SPELL_ID )
            
            call UnitApplyTimedLife( d, 'BTLF', dur )
            call UnitAddAbility( d, THUNDER_ID )
            call SetUnitAbilityLevel( d, THUNDER_ID, lvl )
            call IssueImmediateOrder( d, "thunderclap" )
        
            //call BJDebugMsg( I2S( CountUnitsInGroup( enum ) ) )
        else
            set int = 0
        endif
        
        set d = null
        set u = null
        
        return false
    endfunction
    
    private function Spell_Check takes nothing returns boolean
        return GetSpellAbilityId() == SPELL_ID and GetUnitAbilityLevel( GetTriggerUnit(), BUFF_ID ) > 0
    endfunction
    
    private function Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local integer lvl = GetUnitAbilityLevel( u, SPELL_ID )
        local real x = GetUnitX( u )
        local real y = GetUnitY( u )
        local real radius = I2R( ( 100 * lvl ) + 500 )
        
        set cast = u
        
        call GroupEnumUnitsInRange( enum, x, y, radius, Filter( function Filters ) )        
        
        call BJDebugMsg( I2S( CountUnitsInGroup( enum ) ) )
        
        set u = null
    endfunction

//===========================================================================
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        
        loop
            exitwhen i >= 11
            call TriggerRegisterPlayerUnitEvent( t, Player( i ), EVENT_PLAYER_UNIT_SPELL_EFFECT, null )
            
            set i = i + 1
        endloop
        
        call TriggerAddCondition( t, Condition( function Spell_Check ) )
        call TriggerAddAction( t, function Actions )
    endfunction

endscope
 

chobibo

Level 1 Crypt Lord
Reaction score
48
You're not adding any unit to the group that's why, look at the filterfunc, it always returns false, which means it adds no units, which equates to the group having nothing stored into it.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Tested just now. The native does not work, but I sure it worked before when I was working on my TD map.

Temporary Fix :
JASS:
private function LimitUnitsInGroup takes group whichGroup, integer limit returns nothing
    local integer i = CountUnitsInGroup(whichGroup)
    local unit u
    loop
        set u = FirstOfGroup(whichGroup)
    exitwhen i <= limit
        call GroupRemoveUnit(whichGroup,u)
        set i = i - 1
    endloop
    set u = null
endfunction
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Well, I'm going to use Troll-Brain's suggestion, as I don't really like using the "FirstOfGroup" approach...
 

Komaqtion

You can change this now in User CP.
Reaction score
469
I have, and it works ;)

Thanks all :thup:

Now I just need to come up with a few more spells to demonstrate my SUM system...

Any ideas ? :eek:
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top