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

My Hashtable for controlling AI not working.

Status
Not open for further replies.
Level 7
Joined
Sep 9, 2007
Messages
253
It's a kodo tag map (original I know) but with teams. Players can't attack each other but they can spawn kodos to chase the enemy team. There are also neutral kodos which will chase any player.

I want the AI to target a player and constantly chase him. They should only target buildings if there is no path to the player they have targetted. I'm trying to save a target into the hashtable for each kodo on the map and ordering them to attack that target every 0.1 seconds.

With the triggers below it looks like the kodos are selecting a new random target every 0.1 seconds because they just stand in one place constantly changing direction.

So I've never really used hashtables before so I'm guessing I'm not doing it correctly.

  • Spawn Kodo Top Left
    • Events
    • Conditions
    • Actions
      • -------- TOP LEFT --------
      • Set aaTempPoint = (Point(-8050.00, 5100.00))
      • Unit - Create 1 Kodo_Spawn_Type for Player 12 (Brown) at aaTempPoint facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_aaTempPoint)
      • Hashtable - Save 0 as 1 of (Key (Last created unit)) in KodoHashtable /////// this integer indicates weather this kodo will target any player (0) target team 1 (2) or target team 2 (1)
      • Hashtable - Save 0 as 2 of (Key (Last created unit)) in KodoHashtable /////// this integer indicates weather or not this kodo has a target. has target (1) or does not have target (0)..... I tried integer coz boolean wasnt working.


  • targetting Hashtable
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • Set Kodo_Group = (Units owned by Player 12 (Brown))
      • Unit Group - Pick every unit in Kodo_Group and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Load 1 of (Key (Picked unit)) from KodoHashtable) Equal to 0
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Load 2 of (Key (Picked unit)) from KodoHashtable) Equal to 1 \\\\\\\ This condition doesn't seem to work because the actions below are always running even though 2 of picked unit is changed to 1 (ie does have target)
                • Then - Actions
                  • Unit - Order (Picked unit) to Attack (Load 3 of (Key (Picked unit)) in KodoHashtable)
                • Else - Actions
                  • Set aaTempUnit = (Random unit from UnitGroup_Runners)
                  • Unit - Order (Picked unit) to Attack aaTempUnit
                  • Hashtable - Save 1 as 2 of (Key (Picked unit)) in KodoHashtable
                  • Hashtable - Save Handle OfaaTempUnit as 3 of (Key (Picked unit)) in KodoHashtable
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Load 1 of (Key (Picked unit)) from KodoHashtable) Equal to 1
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Load 2 of (Key (Picked unit)) from KodoHashtable) Equal to 1
                    • Then - Actions
                      • Unit - Order (Picked unit) to Attack (Load 3 of (Key (Picked unit)) in KodoHashtable)
                    • Else - Actions
                      • Set aaTempUnit = (Random unit from UnitGroup_Runners_team2)
                      • Unit - Order (Picked unit) to Attack aaTempUnit
                      • Hashtable - Save 1 as 2 of (Key (Picked unit)) in KodoHashtable
                      • Hashtable - Save Handle OfaaTempUnit as 3 of (Key (Picked unit)) in KodoHashtable
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Load 2 of (Key (Picked unit)) from KodoHashtable) Equal to 1
                    • Then - Actions
                      • Unit - Order (Picked unit) to Attack (Load 3 of (Key (Picked unit)) in KodoHashtable)
                    • Else - Actions
                      • Set aaTempUnit = (Random unit from UnitGroup_Runners_team1)
                      • Unit - Order (Picked unit) to Attack aaTempUnit
                      • Hashtable - Save 1 as 2 of (Key (Picked unit)) in KodoHashtable
                      • Hashtable - Save Handle OfaaTempUnit as 3 of (Key (Picked unit)) in KodoHashtable
      • Custom script: call DestroyGroup(udg_Kodo_Group)

note. before turning to hashtables I was using the trigger below but the kodos change focus to towers when the towers attack them. I want the kodos to taget buildings only if there is no route to their target.

  • targetting
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • Set Kodo_Group = (Units owned by Player 12 (Brown) matching ((Current order of (Matching unit)) Equal to (Order(none))))
      • Unit Group - Pick every unit in Kodo_Group and do (Actions)
        • Loop - Actions
          • Set aaTempUnit = (Random unit from UnitGroup_Runners)
          • Unit - Order (Picked unit) to Attack aaTempUnit
      • Custom script: call DestroyGroup(udg_Kodo_Group)
Thanks so much for any help.
 
Did you create KodoHashtable in an initialization trigger? If not, make sure you have a trigger like this:
  • Initialization
    • Events
      • Map Initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set KodoHashtable = (Last created hashtable)
If the hashtable isn't created, then that might explain why the values aren't being saved (and why it is being repeatedly asked to target different units). On my first skim, it looked okay to me.
 
Level 7
Joined
Sep 9, 2007
Messages
253
thanks, embarrasing.
Actually I did have it but it was disabled.

The problem now is that when there is no route to the target the kodos just stand there. I understand why they do this but is there a way to check if there no valid path and then allow the kodos to attack the structures which are in the way?
 
Level 13
Joined
Mar 24, 2013
Messages
1,105
When a unit "gives up" looking for a path, its order changes to null. You can try checking whether not the kodos order is null and if so sets it's individual state to allow it to attack buildings.

Also you should save things like picked unit into a variable for speed and easier reading
 
Level 7
Joined
Sep 9, 2007
Messages
253
Every 2 seconds a trigger picks all kodos and orders them to attack their target (which is stored in the hashtable). The same trigger also checks if they currently have order(none) and if so removed them from the group thus allowing them to attack the nearest structure (although the same target is still saved in the hashtable) When a kodo destroys a structure it will again be given an attack target order.

The problem with this is that on some occasions they try for too long to find a path by going backwards and forwards. There is also some inefficiencies when a kodo has more than 1 building to destory.

Is there a way to check weather or not a Kodo has a viable path to its target? I mean as an event that I can detect as soon as it happens rather than waiting for the game AI pathing to figure it out?

thanks.

Also, I have used what p0ke said but is the following correct? when I write null it comes up as empty string.
  • (Current order of (Picked unit)) Equal to (Order(<Empty String>))
Edit: Realised I should post this in trigger forum.
 
Last edited:
Status
Not open for further replies.
Top