• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] How to detect enemy units within range?

Status
Not open for further replies.
Level 17
Joined
Jun 2, 2009
Messages
1,137
Hello everyone. I have created AI system for my map and now i want to detect enemy heroes around AI heroes and attack or cast spells onto them.

First of all i am setting TempPoint to location of the Computer 8-9-10-11-12 and i have a Booleans that detects AI is running away from creeps, heroes, towers or going back to the base for the regeneration.

  • BotHeroBul Copy Copy
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 8 to 12, do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in zUG_HerolarAIReaper and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (zU_AIHero[(Integer A)] is in zUG_RegenReaper) Equal to False
                  • zBool_AIKaciyor_Creepten[(Player number of (Owner of (Picked unit)))] Equal to False
                  • zBool_AIKaciyor_Herodan[(Player number of (Owner of (Picked unit)))] Equal to False
                  • zBool_AIKaciyor_Kuleden[(Player number of (Owner of (Picked unit)))] Equal to False
                • Then - Actions
                  • Game - Display to (All players) for 1.00 seconds the text: (Name of (Picked unit))
                  • Set TempPoint = (Position of (Picked unit))
I can set the location like this but here is the trouble begins.

  • Set TempPoint = (Position of (Picked unit))
  • Set TempGroup = (Units within 800.00 of TempPoint matching (((Matching unit) is in DevilHerolariHepsi) Equal to True))
If i do that correctly, i am able to find all enemy heroes within DevilHerolariHepsi unit group within 800 range.
Now i want to do that.


  • If - Conditions
    • (Percentage life of (Picked unit)) Less than or equal to 25.00
    • Then - Actions
I am thinking about it but i don't know how to do that. How can i detect enemy heroes below 25% health percentage or something like this?

By the way you can suggest anything different instead of my system.

My objective is detect enemy units within range matching conditions
 

Wrda

Spell Reviewer
Level 26
Joined
Nov 18, 2012
Messages
1,887
I don't understand your issue, since you have "And condition" when you're trying to use the "matching conditions", you can add more than one condition.
OR
You simply pick every unit in TempGroup, make an if then else statement and add the condition you want.
You literally made this on the trigger above, so how's this any different?
 
Level 17
Joined
Jun 2, 2009
Messages
1,137
I don't understand your issue, since you have "And condition" when you're trying to use the "matching conditions", you can add more than one condition.
OR
You simply pick every unit in TempGroup, make an if then else statement and add the condition you want.
You literally made this on the trigger above, so how's this any different?

Pick every enemy heroes within temp range
Unit is enemy
Unit is hero
Unit is alive bla bla bla

Order - AIHERO to Attack or Cast spell of picked unit.

I cannot pick the unit. Or i am missing something easy.
 
I cannot pick the unit. Or i am missing something easy.
Kind of, yes.
Store the previous "picked unit" (if you need it later) in another variable, set a group-variable to units within X range of some point, do another loop with that group and then destroy that group and start that for-each-unit-in-group with an if-block to filter enemy heroes (because that's what you wanted?)
 

Wrda

Spell Reviewer
Level 26
Joined
Nov 18, 2012
Messages
1,887
I cannot pick the unit. Or i am missing something easy.
And what does this mean you "can't pick the unit"? You can't use "Picked Unit" option on any of the conditions? You can't order a unit to cast a spell on "Picked Unit"?
You've already used this function in the trigger you've posted. Specify exactly what you want to do and achieve.
I can't imagine what you're trying to do at this point, are you trying to iterate units through 2 layers of "pick every unit" action?
 
Level 17
Joined
Jun 2, 2009
Messages
1,137
@Wrda @ThompZon

  • Events
    • Time - Every 1.00 seconds of game time
  • Conditions
  • Actions
    • For each (Integer A) from 8 to 12, do (Actions)
      • Loop - Actions
        • Unit Group - Pick every unit in zUG_HerolarAIReaper and do (Actions)
          • Loop - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (zU_AIHero[(Integer A)] is in zUG_RegenReaper) Equal to False
                • zBool_AIKaciyor_Creepten[(Player number of (Owner of (Picked unit)))] Equal to False
                • zBool_AIKaciyor_Herodan[(Player number of (Owner of (Picked unit)))] Equal to False
                • zBool_AIKaciyor_Kuleden[(Player number of (Owner of (Picked unit)))] Equal to False
              • Then - Actions
                • Game - Display to (All players) for 1.00 seconds the text: (Name of (Picked unit))
                • Set TempPoint = (Position of (Picked unit))
                • Set TempGroup = (Units within 800.00 of TempPoint matching (((Matching unit) is in DevilHerolariHepsi) Equal to True))
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • (Percentage life of (Picked unit)) Less than or equal to 25.00
                  • Then - Actions
                    • Unit - Order aiHero[(Integer A)] to Attack (Picked unit)
                    • Custom script: call DestroyGroup (udg_TempGroup)
                    • Custom script: call RemoveLocation (udg_TempPoint)
                    • Game - Display to (All players) for 1.00 seconds the text: (Name of (Picked unit))
                  • Else - Actions
                    • Custom script: call RemoveLocation (udg_TempPoint)
                    • Custom script: call DestroyGroup (udg_TempGroup)
                    • Game - Display to (All players) for 1.00 seconds the text: (Name of (Picked unit))
              • Else - Actions
Ok then why this isn't working?
My hero is in DevilHerolariHepsi
My Hit Point went below 25%

  • If - Conditions
    • (Percentage life of (Picked unit)) Less than or equal to 25.00
  • Then - Actions
    • Unit - Order aiHero[(Integer A)] to Attack (Picked unit)
This is what i am trying to ask.
How can i make it detect my hero within 800 of it's range when my health goes below 25% percentage
Picked Unit is the enemy hero who should check it's 800 range. Not the enemy. I want to select enemy and go for the actions.
I believe the solution is ultra easy but my brain not working properly for now.

Update: Ok ok it was funny. I wasn't remembered that we can pick every unit within tempgroup. Ok it is solved.

  • Unit Group - Pick every unit in TempGroup and do (Actions)
    • Loop - Actions
Thank you guys.
 
Last edited:
Level 17
Joined
Jun 2, 2009
Messages
1,137
@ThompZon @Wrda Hmmm no, it is not working. I tought it has.

  • SkillAtDeneme
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 8 to 12, do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in zUG_HerolarAIReaper and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (zU_AIHero[(Integer A)] is in zUG_RegenReaper) Equal to False
                  • zBool_AIKaciyor_Creepten[(Player number of (Owner of (Picked unit)))] Equal to False
                  • zBool_AIKaciyor_Herodan[(Player number of (Owner of (Picked unit)))] Equal to False
                  • zBool_AIKaciyor_Kuleden[(Player number of (Owner of (Picked unit)))] Equal to False
                • Then - Actions
                  • Set TempPoint = (Position of (Picked unit))
                  • Set TempGroup = (Units within 1500.00 of TempPoint matching (((Matching unit) is in DevilHerolariHepsi) Equal to True))
                  • Unit Group - Pick every unit in TempGroup and do (Actions)
                    • Loop - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Percentage life of (Picked unit)) Less than or equal to 80.00
                        • Then - Actions
                          • Unit - Order zU_AIHero[(Integer A)] to Orc Far Seer - Chain Lightning (Picked unit)
                          • Set TempLoc = (Center of CurrentTarget[(Integer A)])
                          • Unit - Order zU_AIHero[(Integer A)] to Attack-Move To TempLoc
                          • Game - Display to (All players) for 1.00 seconds the text: (PlayerNames[(Player number of (Player((Integer A))))] + (Name of zU_AIHero[(Integer A)]))
                          • Game - Display to (All players) for 1.00 seconds the text: (Name of (Picked unit))
                          • Custom script: call DestroyGroup (udg_TempGroup)
                          • Custom script: call RemoveLocation (udg_TempPoint)
                        • Else - Actions
                          • Custom script: call RemoveLocation (udg_TempPoint)
                          • Custom script: call DestroyGroup (udg_TempGroup)
                • Else - Actions
      • Custom script: call RemoveLocation (udg_TempPoint)
      • Custom script: call DestroyGroup (udg_TempGroup)
I can see the name of Picked Unit (my hero axe master) and zU_AIHero[(Integer A)] but it cannot cast Chain Lightning?
And somehow i can see the name of all AI heroes i don't know why. They are far away from 1500 range.
What can cause this? Hero has Chain Lightning ability and it is learning when entered the map

Untitled Trigger 002
Events
Unit - A unit enters (Entire map)
Conditions
Or - Any (Conditions) are true
Conditions
((Triggering unit) is in zUG_HerolarAIDevil) Equal to True
((Triggering unit) is in zUG_HerolarAIReaper) Equal to True
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Unit-type of (Triggering unit)) Equal to Thundercaller Pollon
Then - Actions
Hero - Learn skill for (Triggering unit): Chain Lightning //POLLON
Else - Actions
 

Attachments

  • Untitled.png
    Untitled.png
    329.4 KB · Views: 11

Wrda

Spell Reviewer
Level 26
Joined
Nov 18, 2012
Messages
1,887
What can cause this? Hero has Chain Lightning ability and it is learning when entered the map

Untitled Trigger 002
Events
Unit - A unit enters (Entire map)
Conditions
Or - Any (Conditions) are true
Conditions
((Triggering unit) is in zUG_HerolarAIDevil) Equal to True
((Triggering unit) is in zUG_HerolarAIReaper) Equal to True
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Unit-type of (Triggering unit)) Equal to Thundercaller Pollon
Then - Actions
Hero - Learn skill for (Triggering unit): Chain Lightning //POLLON
Else - Actions
Look at this trigger and think: how can a unit that has just entered the map be already in a unit group without ever adding to the group first? This doesn't make any sense, this will never fire, remove your unit group condition checks.
 
Level 17
Joined
Jun 2, 2009
Messages
1,137
Look at this trigger and think: how can a unit that has just entered the map be already in a unit group without ever adding to the group first? This doesn't make any sense, this will never fire, remove your unit group condition checks.

I forgot the show this. This is running before.

  • HeroSectirme
    • Events
      • Time - Elapsed game time is 2.00 seconds
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Player((Integer A))) controller) Equal to Computer
              • BotHeroSecti[(Integer A)] Equal to False
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Player number of (Player((Integer A)))) Less than or equal to 6
                • Then - Actions
                  • Set BotHeroSecti[(Integer A)] = True
                  • Unit - Create 1 BotHerolar[(Random integer number between 1 and 1)] for (Player((Integer A))) at (Center of GameGuideDevil <gen>) facing Default building facing degrees
                  • Set zU_AIHero[(Integer A)] = (Last created unit)
                  • Hero - Modify Strength of (Last created unit): Add 10
                  • Hero - Modify Agility of (Last created unit): Add 10
                  • Hero - Modify Intelligence of (Last created unit): Add 10
                  • Unit Group - Add (Last created unit) to zUG_HerolarAIDevil
                  • Unit Group - Add (Last created unit) to BotDevilHepsi
                  • Unit Group - Add (Last created unit) to BotHepsi
                  • Unit Group - Add (Last created unit) to HerolarALL
                  • Unit Group - Add (Last created unit) to DevilHerolariHepsi
                  • Player Group - Add (Player((Integer A))) to ClanDevilPlayers
                  • Player Group - Add (Player((Integer A))) to ClanDevilBotlar
                  • Player Group - Add (Player((Integer A))) to Botlar
                  • Unit - Set the custom value of (Last created unit) to 0
                  • Set HeroCountDevil = (HeroCountDevil + 1)
                • Else - Actions
                  • Set BotHeroSecti[(Integer A)] = True
                  • Unit - Create 1 BotHerolar[(Random integer number between 1 and 1)] for (Player((Integer A))) at (Center of GameGuideReaper <gen>) facing Default building facing degrees
                  • Set zU_AIHero[(Integer A)] = (Last created unit)
                  • Hero - Modify Strength of (Last created unit): Add 10
                  • Hero - Modify Agility of (Last created unit): Add 10
                  • Hero - Modify Intelligence of (Last created unit): Add 10
                  • Unit Group - Add (Last created unit) to zUG_HerolarAIReaper
                  • Unit Group - Add (Last created unit) to BotReaperHepsi
                  • Unit Group - Add (Last created unit) to BotHepsi
                  • Unit Group - Add (Last created unit) to HerolarALL
                  • Unit Group - Add (Last created unit) to ReaperHerolariHepsi
                  • Player Group - Add (Player((Integer A))) to ClanReaperPlayers
                  • Player Group - Add (Player((Integer A))) to ClanReaperBotlar
                  • Player Group - Add (Player((Integer A))) to Botlar
                  • Unit - Set the custom value of (Last created unit) to 0
                  • Set HeroCountReaper = (HeroCountReaper + 1)
            • Else - Actions
If they will never run, how can the game detect this one?

  • Game - Display to (All players) for 1.00 seconds the text: (PlayerNames[(Player number of (Player((Integer A))))] + (Name of zU_AIHero[(Integer A)]))
And not this one?

  • Unit - Order zU_AIHero[(Integer A)] to Orc Far Seer - Chain Lightning (Picked unit)
Both of are looking for zU_AIHero [Integer A]

Update: Ok i have solved it. One of my triggers was interfering...
 
Last edited:
Status
Not open for further replies.
Top