Snippet Emulating Pick Every X Functions

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
Emulating Pick Every Functions

This is a brief introduction on picking every player/unit/w.e u want to pick without using the actual functions
Essentially what the pick every unit function does, is it goes down a list of the units in a group doing a set of actions for each one. What we will do here is emulate this effect through the use of integer loops and variables, here is an example of a very basic one:
Trigger:
  • Emulated Pick Every unit
    • Events
      • A Unit casts an ability
    • Conditions
      • Ability being cast is equal to Stomp (a triggered spell that deals damage in an aoe)
    • Actions
      • Set Damaged_Units (our unit group) = Units within 300 range of casting unit matching conditions (Owner of matching unit is an enemy of Owner of casting unit)
      • For each Integer A from 1 to (number of units in Damaged_Units) do actions.
        • Loop Actions
          • Set Picked_Unit = Random Unit from Damaged_Units
          • Unit Group - Remove Picked_Unit from Damaged_Units
          • Unit - Cause Casting Unit to damage Picked_Unit for X damage
      • Custom Script: Calldestroygroup(UDG_Damaged_Units)
As you can see there, what I did was set the group that i would have used in the Pick every unit function and instead used an Integer Loop, setting the "Picked unit" to a random unit in that group and then removing it until all units have been removed

This is best for use with picking every unit inside a picked unit function IE: a spell that deals damage to the enemies around your nearby allies, a spell like earthshaker's ult (a seismic wave that hits enemies in an aoe hit then hits nearby enemies for a lesser ammount)

Here is an example of this:
Trigger:
  • Echo-Slam
    • Events
      • A unit finishes casting an ability
    • Conditions
      • Ability being cast is equal to Echo-Slam
    • Actions
      • Set Temp_GRP[1] = Units within 300 range of casting unit matching conditions (owner of matching unit is an enemy of owner of casting unit)
      • Unit Group - Pick every unit in Temp_GRP[1] and do actions
        • Loop Actions
          • Unit - Cause Casting unit to damage Picked unit for 150 damage
          • Set Temp_GRP[2] = Units within 300 range of picked unit matching conditions (Owner of matching unit is an enemy of owner of casting unit)
          • For Each Integer A from 1 to (Number of units in Temp_GRP[2]) do actions
            • Loop Actions
              • Set Picked_Unit = Random unit in Temp_GRP[2]
              • Unit Group - Remove Picked_Unit from temp_GRP[2]
              • Unit - Cause Casting Unit to damage Picked_Unit for 75 Damage
          • Custom Script: Calldestroygroup(UDG_Temp_GRP[2])
      • Custom Script: Calldestroygroup(UDG_Temp_GRP[1]
In this example the caster deals damage to enemies in 300 range for 150 damage, then deals damage to enemies within 300 range of them for 75 damage, creating a sort of chain aoe effect. The nice thing about using an effect like this with an Integer A loop is that you if you want to have a picked unit in a picked unit in a picked unit, you can do it as many times as you want with just the A loop, changing indexes for the stored units every level or dimension, this is because you dont actually use Integer A in your actions.

Any questions/comments you can pm or post here :)
 

Dirac

22710180
Reaction score
147
Well i have one question:
Speaking in GUI terms how is this useful? you can always pick groups inside group picking, i've done it several times before back when i did GUI coding.
Looks like much more overhead for GUI users to go this way, however in JASS it's the easiest way to do it
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
i did some reasearch and it appeared that using that method causes glitches with what unit is the picked unit, is that incorrect?
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
Hm looks like the gui version of first of group iteration except both number of units and random unit call ForGroup/Pick unit =).

It's kinda strange that unit groups don't know their size...
 

tooltiperror

Super Moderator
Reaction score
231
This isn't really a tutorial on its own.

You could submit a tutorial on all kinds of group management, or make a demo map showing a bunch of stuff about using groups well or whatever. This itself does not merit a tutorial.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top