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

How to Pick Unit from unit group?

Status
Not open for further replies.
Level 4
Joined
Aug 18, 2013
Messages
71
Hey Guys, I'm working on a Hero Bot System for my map. And I'm working on a target find system.

I was using a unit group, but unit groups are unreliable due to several facts.
  • Can't pick a specific unit from unit group (Ex. pick unit 1 in unit group)
  • lots of leaks
  • basically the above

But I can't logic a way to use a unit array, adding nearby enemy units within a range of my bot.

Can someone get me on the right track, via showing me what vars I'll need, or sending me a tutorial. thanks
 
Level 15
Joined
Oct 29, 2012
Messages
1,474
to pick a specific a unit from unit group , use conditions , for example
  • Set TempGroup = All Units Owned by (Player 1) which is human
  • Unit - Pick Every Unit in TempGroup and Do - Actions
    • Loop - Actions :
      • If And/All Conditions are true
        • (Unit Type of (picked unit)) Equal to Footmen
        • Kill (Picked Unit)
  • HERE REMOVE LEAKS
  • Custom script: call DestroyGroup(udg_TempGroup)
 
Level 4
Joined
Aug 18, 2013
Messages
71
to pick a specific a unit from unit group , use conditions , for example
  • Set TempGroup = All Units Owned by (Player 1) which is human
  • Unit - Pick Every Unit in TempGroup and Do - Actions
    • Loop - Actions :
      • If And/All Conditions are true
        • (Unit Type of (picked unit)) Equal to Footmen
        • Kill (Picked Unit)
  • HERE REMOVE LEAKS
  • Custom script: call DestroyGroup(udg_TempGroup)

The issue with this system, is that there will be multiple units of the same unit type in the group. I need a dynamical system similar to an array, where I can check conditions to each unit in the unit group (For ex. if unit 7 from unit group Health % < 8%, order bot to attack that unit. )

EDIT: A better way is with a for loop.

For(int i) 0 to numOfUnits[Int] in unit group(Picked units)
if(unit from unit group(i)) HP % less than 8%)
then
Order bot to attack unit from unitgroup(i)
else
---
 
Level 4
Joined
Aug 18, 2013
Messages
71
JASS:
local unit FoG
loop
    set FoG = FirstOfGroup(udg_Group)
    exitwhen FoG == null 
    //Do some stuff
endloop

Not sure what this is? or what it does. Its jass for picking the first unit from a unit group? that too would be as useful as random unit from unit group.
 
Level 15
Joined
Oct 29, 2012
Messages
1,474
  • Unit - Pick Every Unit in TempGroup
    • Loop - Actions
      • Set TempInteger = (TempInteger + 1)
      • If Conditions :
        • Conditions
          • TempInteger = 7
        • Actions
          • Set PickedUnit[TempInteger] = (Picked Unit)
          • If Conditions :
            • Conditions :
              • (Life of PickedUnit[TempInteger]) Less than or Equal to (((Max Life Of PickedUnit[TempInteger]) x 8 ) / 100 )
              • Actions :
                • COMMENT : YOUR STUFF
 
Level 28
Joined
Sep 26, 2009
Messages
2,520
TBH AI shouldn't pick random unit in a group (e.g. unit 5 in a group), as that would lead to unintentional behavior - like there is a group of enemies and he picks up the furthest one (that being the unit 5 of that group), so he has to go through the whole mob of creeps... of course those creeps try to attack him as well, so they move to him, thus blocking him even more - in the end, before the AI-forced hero gets to his target, he will loose a lot of health.

Basically, I think you should periodically pick every unit nearby the hero, filter through them to find a corresponding target and then just order that hero to attack that target.
 
Level 4
Joined
Aug 18, 2013
Messages
71
I know, The Ai checks the following.
It runs through possible targets in this order.

unit has less then 7% hp and if unit is not a hero
unit has less then 15% hp and unit is within 600 range
distance between BOT and picked unit is less than etc. -> This picks closest enemy
 
Status
Not open for further replies.
Top