• 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.

Filter just # unit...

Status
Not open for further replies.
Level 20
Joined
Jul 6, 2009
Messages
1,885
You can use
JASS:
local unit u
local group g = GroupEnumUnitsInRange(g,x,y,radius,filter)
set u = FirstOfGroup(g)
call DestroyGroup(g)
If you don't think FirstOfGroup() is reliable, you can make your own randomizer:
-Add all units from a group to a unit array, set an integer's value to a random value between 1 and number of units in group and return the unit from unit array with random integer as index.
-Filter through units in range, if filter unit's type equals to wanted type then give it a chance to be the randomized unit. If unit amount hits 1, return the last unit.
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
GetRandomUnitFromGroup action in GUI is pretty much overcomplicated version of FirstOfGroup.
The GetRandomSubGroup is based off my second suggestion for a randomizer
-Filter through units in range, if filter unit's type equals to wanted type then give it a chance to be the randomized unit. If unit amount hits 1, return the last unit.
You can see this if you open JASSCraft and look for that BJ.
 
JASS:
//udg_GroupMax is an integer and should always start with the value zero

function Filterthem takes nothing returns boolean
   if udg_GroupMax <= max number of units for the group then
      set udg_GroupMax = udg_GroupMax + 1
      return true
  endif
  //Now it will only add the units into the group if the group hasn't reached the
  //amount that you want
  return false
endfunction

function Main takes nothing returns nothing
    set udg_GroupMax = 0
    call GroupEnumUnitsInRange(udg_TempGroup, GetUnitX(udg_LC_Cloud), GetUnitY(udg_LC_Cloud), 700, Filter(function Filterthem))
endfunction
 
So GroupEnumUnitsInRange takes dummy group which is udg_TempGroup and filters them...now since the Enum will pick all units within 700 of XY, then that's why there is GroupMax coz the first unit it picked will be the one who will get lightning cast...hmmm...interesting...

Im testing it with this...and it worked!

JASS:
function Filterthem takes nothing returns boolean
    local unit u = GetFilterUnit()
    if udg_LC_GroupMax <=0 then
      set udg_LC_GroupMax = udg_LC_GroupMax + 1
      //call IssueTargetOrder(udg_LC_Cloud, "chainlightning", u) 
      call KillUnit(u)
    endif
    set u = null
endfunction
 
yeah, but 1 less FC...

you could also add a randomization filter (GetRandomInt(1,100) < something) to the function if you want to really randomize the units (meaning the group could have anything berween 0 to the max number of members)

remove the local, it actually makes it less optimized since you only used the unit once (since the other one is commented)
 
Status
Not open for further replies.
Top