HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

PickRandomUnit

02-14-2007, 11:19 PM#1
StockBreak
Hi all, for one of my spells I need to pick a random unit from units in a fixed range. What is the best way to do this?
I used:
Collapse JASS:
call GroupEnumUnitsInRangeCounted( g, x, y, range, Condition( function Spell_Group_Conditions ), 1 )

but, for some reason, it doesn't work (it picks ALL the units in range), why?

I also tried to use:
Collapse JASS:
call GroupEnumUnitsInRange( g, x, y, range, Condition( function Spell_Group_Conditions ) )
set u = FirstOfGroup( g )

But the unit is not chosen random, it's always the same. Any Help? Thanks.
02-15-2007, 02:07 AM#2
Pyrogasm
Do this:
Collapse JASS:
call GroupEnumUnitsInRange( g, x, y, range, Condition( function Spell_Group_Conditions ) )
set u = GroupPickRandomUnit(g)
//...

That should work for you.
02-15-2007, 08:59 AM#3
StockBreak
Quote:
Originally Posted by Pyrogasm
Do this:
Collapse JASS:
call GroupEnumUnitsInRange( g, x, y, range, Condition( function Spell_Group_Conditions ) )
set u = GroupPickRandomUnit(g)
//...

That should work for you.
Yes, I saw that BJ function when I was making some GUI tests, is it the only way to get a random unit from a group? Thanks BTW.
02-15-2007, 12:00 PM#4
Rising_Dusk
Nah, but it's the easiest.
If you do it without the BJ, you need to monitor the % chance, reduce with each passing unit in the group, etc.
The BJ was made to make life easier, and it does. :P

Just use the BJ, it's not like it leaks.
02-15-2007, 12:57 PM#5
StockBreak
Ok, so I think I will use that function; but why GroupEnumUnitsInRangeCounted doesn't work? Thanks!
02-16-2007, 09:13 AM#6
PandaMine
Quote:
Originally Posted by Rising_Dusk
Nah, but it's the easiest.
If you do it without the BJ, you need to monitor the % chance, reduce with each passing unit in the group, etc.
The BJ was made to make life easier, and it does. :P

Just use the BJ, it's not like it leaks.

Some BJ's are utter crap though, like the BJFunctions which do the exact same thing as the functions they call