1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Solved] How to Group unit without uses boolenexplr

Discussion in 'Triggers & Scripts' started by ALTELMA, Apr 20, 2012.

  1. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    GroupEnumUnitsInRange(g,x,y,r,filter)

    g: group, it is the group that the picked unit will be added to.
    x: real, the X coordinate of the centre point of the picking circle.
    y: real, the Y coordinate of the centre point of the picking circle.
    r: real, is the radius the circle that the function will pick units from.
    filter: boolexpr, if you want the unit to has special condition, but we regularly avoid this to prevent creation of another thread so we use FirstOfGroup and match the unit one by one.
     
  2. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,372
    Resources:
    1
    JASS:
    1
    Resources:
    1
    With Cohadar's jasshelper :

    Instead of :

    Code (vJASS):
        call GroupEnumUnitsInRange(g, 0, 0, 1000000000, null)
       
        loop
            set u = FirstOfGroup(g)
            exitwhen u == null
                if(GetUnitTypeId(u) == 'hf00')then
                    set unitCount =unitCount + 1
                    call BJDebugMsg(I2S(unitCount))
                endif
                call GroupRemoveUnit(g,u)
        endloop


    ->

    Code (vJASS):
        call GroupEnumUnitsInRange(g, 0, 0, 1000000000, null)
       
        for u in g

            if(GetUnitTypeId(u) == 'hf00')then
                set unitCount =unitCount + 1
                call BJDebugMsg(I2S(unitCount))
            endif

        endfor


    When the vJass code will be converted to jass code the result will be exactly the same, but it is simply less verbose and error prone.
     
  3. ALTELMA

    ALTELMA

    Joined:
    Jan 4, 2009
    Messages:
    113
    Resources:
    0
    Resources:
    0
    If I don't want use vJass, but I want use basic jass my Code is OK?
     
  4. Spartipilo

    Spartipilo

    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Resources:
    0
    Resources:
    0
    Yes it's
     
  5. ALTELMA

    ALTELMA

    Joined:
    Jan 4, 2009
    Messages:
    113
    Resources:
    0
    Resources:
    0
    Ahh I'try use that code to count unit on group, but It's doesn't work, why and How I can do fixed it.

    Code (vJASS):

    function Trig_CountUnitGroup_Actions takes nothing returns nothing
       
        local unit u
        local group g =CreateGroup()
        local integer unitCount
        local integer i
       
        call GroupEnumUnitsInRange(g, 0, 0, 1000000000, null)
       
        loop
            set u = FirstOfGroup(g)
            exitwhen u == null
            set i = i + 1
                if(GetUnitTypeId(u) == 'hf00')then
                    set unitCount =unitCount + 1
                    call BJDebugMsg("COUNT IS : "+I2S(unitCount))
                else
                    call BJDebugMsg("LOOP :"+I2S(i))
                endif
                call GroupRemoveUnit(g,u)
        endloop
    endfunction

    //===========================================================================
    function InitTrig_CountUnitGroup takes nothing returns nothing
        set gg_trg_CountUnitGroup = CreateTrigger()
        call TriggerRegisterPlayerChatEvent(gg_trg_CountUnitGroup, Player(0), "-uc", true)
        call TriggerAddAction( gg_trg_CountUnitGroup, function Trig_CountUnitGroup_Actions )
    endfunction


     



    Tell me plz!!
     
  6. Spartipilo

    Spartipilo

    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Resources:
    0
    Resources:
    0
    Are the 'hf00' units in the map? else it wont do anything.

    Also, you have to destroy g and null u.
     
  7. ALTELMA

    ALTELMA

    Joined:
    Jan 4, 2009
    Messages:
    113
    Resources:
    0
    Resources:
    0
    Code (vJASS):

    function Trig_CountUnitGroup_Actions takes nothing returns nothing
       
        local unit u
        local group g =CreateGroup()
        local integer unitCount
        local integer i
       
        call GroupEnumUnitsInRange(g, 0, 0, 1000000000, null)
       
        loop
            set u = FirstOfGroup(g)
            exitwhen u == null
            set i = i + 1
                if(GetUnitTypeId(u) == 'hf00')then
                    set unitCount =unitCount + 1
                    call BJDebugMsg("COUNT IS : "+I2S(unitCount))
                endif
                call GroupRemoveUnit(g,u)
        endloop
       
        call DestroyGroup(g)
        set g -= null
    endfunction

    //===========================================================================
    function InitTrig_CountUnitGroup takes nothing returns nothing
        set gg_trg_CountUnitGroup = CreateTrigger()
        call TriggerRegisterPlayerChatEvent(gg_trg_CountUnitGroup, Player(0), "-uc", true)
        call TriggerAddAction( gg_trg_CountUnitGroup, function Trig_CountUnitGroup_Actions )
    endfunction
     


    I don't know why don't display text in loop or loop is infinite?

    'hfoo' is footman they have really.
     
  8. Spartipilo

    Spartipilo

    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Resources:
    0
    Resources:
    0
    'hf00' is nothing.
    'hfoo' is footman.

    Also (I just noticed this) If the local integer variable has no value it will mess the whole thing. It's probably doing the Enum but not displaying any message, since the message to display contains "null", which I tough should be naturally 0 but now noticed that isnt.

    Code (vJASS):

        local unit u
        local group g =CreateGroup()
        local integer i = 0
       
        call GroupEnumUnitsInRange(g, 0, 0, 1000000000, null)
       
        loop
            set u = FirstOfGroup(g)
            exitwhen u == null
                set i = i + 1
                if(GetUnitTypeId(u) == 'hfoo')then
                    set i = i + 1
                    call BJDebugMsg("COUNT IS : " + I2S(i))
                endif
            call GroupRemoveUnit(g,u)
        endloop
       
        call DestroyGroup(g)
     
     
  9. ALTELMA

    ALTELMA

    Joined:
    Jan 4, 2009
    Messages:
    113
    Resources:
    0
    Resources:
    0
    OK I get it all,Thanks a lot...
     
    Last edited: May 4, 2012