• 🏆 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!

[AI] Turret AI works well most of the time but freezes now and then?

Status
Not open for further replies.
Level 4
Joined
Jun 10, 2019
Messages
69
Hello all,

I'm most of the way there on this one, but I can't quite figure out the last bit.

My map is similar to League of Legends - there are lanes that you go down, destroying turrets on the way.

Like League of Legends, I want the turrets' AI to prioritize attacking minions/non-hero units over hero units. The trigger I made works pretty well, but sometimes the turrets just freeze up. I'm guessing they're being issued too many orders in a small period of time? I'm not sure how to get around that (and I'm not even sure if that's right).

The trigger is:

  • Turret AI
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Set VariableSet Turret_AI_TempPoint[1] = (Position of (Dying unit))
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • Set VariableSet Turret_AI_TempPoint[2] = (Position of (Picked unit))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Life of (Triggering unit)) Less than 700.00
              • (Distance between Turret_AI_TempPoint[1] and Turret_AI_TempPoint[2]) Less than or equal to 700.00
            • Then - Actions
              • Custom script: set bj_wantDestroyGroup = true
              • Unit Group - Pick every unit in (Units within 700.00 of Turret_AI_TempPoint[2].) and do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked unit) is A Hero) Equal to False
                      • ((Picked unit) is alive) Equal to True
                    • Then - Actions
                      • Unit Group - Add (Picked unit) to Turret_AI_UnitGroup
                    • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Turret_AI_UnitGroup is empty) Equal to True
                • Then - Actions
                  • Unit - Order (Picked unit) to Attack (Random unit from Turret_AI_UnitGroup)
                  • Unit Group - Remove all units from Turret_AI_UnitGroup.
                • Else - Actions
              • Custom script: call DestroyGroup(udg_Turret_AI_UnitGroup)
            • Else - Actions
Thanks for reading! Any help would be greatly appreciated!

Edit: I forgot to remove the points. I added those custom scripts into the real trigger.

Edit2: I realized that there are a myriad of errors in this trigger, so I rewrote it:

  • Turret AI Exp
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (Unit-type of (Killing unit)) Equal to Sentry Tower (Invulnerable)
              • (Unit-type of (Killing unit)) Equal to Sentry Tower (Vulnerable)
        • Then - Actions
          • Set VariableSet Turret_AI_Turret = (Killing unit)
          • Set VariableSet Turret_AI_TempPoint[1] = (Position of Turret_AI_Turret)
        • Else - Actions
          • Custom script: set bj_wantDestroyGroup = true
          • Set VariableSet Turret_AI_TempPoint[2] = (Position of (Killing unit))
          • Unit Group - Pick every unit in (Units within 900.00 of Turret_AI_TempPoint[2].) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Or - Any (Conditions) are true
                    • Conditions
                      • (Unit-type of (Picked unit)) Equal to Sentry Tower (Invulnerable)
                      • (Unit-type of (Picked unit)) Equal to Sentry Tower (Vulnerable)
                • Then - Actions
                  • Set VariableSet Turret_AI_Turret = (Picked unit)
                  • Set VariableSet Turret_AI_TempPoint[1] = (Position of Turret_AI_Turret)
                • Else - Actions
      • Custom script: set bj_wantDestroyGroup = true
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Dying unit) belongs to an enemy of (Owner of Turret_AI_Turret).) Equal to True
        • Then - Actions
          • Unit Group - Pick every unit in (Units within 700.00 of Turret_AI_TempPoint[1].) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) belongs to an enemy of (Owner of Turret_AI_Turret).) Equal to True
                  • ((Picked unit) is A Hero) Equal to False
                  • ((Picked unit) is alive) Equal to True
                • Then - Actions
                  • Unit Group - Add (Picked unit) to Turret_AI_UnitGroup
                • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Turret_AI_UnitGroup is empty) Equal to False
            • Then - Actions
              • Unit - Order Turret_AI_Turret to Attack (Random unit from Turret_AI_UnitGroup)
            • Else - Actions
        • Else - Actions
      • Unit Group - Remove all units from Turret_AI_UnitGroup.
      • Custom script: call RemoveLocation(udg_Turret_AI_TempPoint[1])
      • Custom script: call RemoveLocation(udg_Turret_AI_TempPoint[2])
Any thoughts/comments would still be appreciated!
 
Last edited:
Level 4
Joined
Jun 10, 2019
Messages
69
@GIMLI_2 I'm not explicitly filtering for dummy units, but all of my dummies have the locust ability, which I believe prevents them from being added to the Turret_AI_UnitGroup (although I'm not sure about that and I'll do some googling for confirmation).

I'll also see if I can add something like "Unit has ability Locus = False" to the conditions of being added to the unit group.

Thanks for the suggestion!

Edit: yeah, the googling confirms that locust units are not selectable with "Pick every unit in range."

I think the problem may be that if too many units die at roughly the same time, it overloads the turrets with orders.

I have an idea. I'm going to report back and try it out.
 
Level 17
Joined
Mar 21, 2011
Messages
1,597
Just so you get the idea, you need to adjust the code and remove leaks etc..
that is how i would do it in gui


  • Events
    • Unit - A unit Is attacked
  • Conditions
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • current_target[(Custom value of (Attacking unit))] equal to No unit
        • ((Attacking unit) is in Turret_Group Equal to True
      • Then - Actions
        • Set VariableSet current_target[(Custom value of (Attacking unit))] = (Attacked unit)
      • Else - Actions

  • Events
    • Unit - A unit Dies
  • Conditions
  • Actions
    • Unit Group - Pick every unit in Turret_Group and do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • current_target[(Custom value of (Picked unit))] Equal to (Triggering unit)
          • Then - Actions
            • set TempGroup - Units in 500 AoE bla bla..
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • TempGroup is empty equal to True
                • Then - Actions
                  • set current_target[(Custom value of (Picked unit))] = No Unit
                • Else-Actions
                  • Unit - Attack random Unit in TempGroup
          • Else - Actions



You need a unit indexer for this
GUI Unit Indexer 1.4.0.0
 
Level 4
Joined
Jun 10, 2019
Messages
69
Thanks for the comment! I'll see if I can get it working and report back!

Edit: I got it working! Thank you so much!

I suppose there's still a technical bug about 'what if the target moves out of range? It didn't die, so a new order won't be issued,' but I can solve that one later. What I now have will work 99% of the time, and that's good enough for me!

Thank you again! :D

Edit2: Actually, if anyone has any ideas on how to solve that 'move out of range' problem, I'd appreciate it haha.

The only thing I can think of right now is to check the distance between a turret and its corresponding target every X seconds (with X being something pretty small), and then doing the same stuff as if the unit had died if the distance is greater than 700 units (The range of the turret).

Thanks!
 
Last edited:
Status
Not open for further replies.
Top