"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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top