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

[Trigger] AI Works but then again doesn't ..

Status
Not open for further replies.
Level 5
Joined
Feb 5, 2021
Messages
89
Hey there, been a while ..

So recently i picked up an idea and the map itself is no problem, but i have started getting into AI and trying to incorporate it with triggers cause the AI Editor will not work for my purpose.

Well story aside this is the first of probably many triggers but i have already encountered a problem where it will start to do what it is supposed to do and then just ... stop ..
Im guessing it's because the "position of unit" is not large enough for the building and thus it can not build it, any suggestions?

  • BotBuild
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Player Group - Pick every player in BotGroup and do (Actions)
        • Loop - Actions
          • Set VariableSet BotCheckBuildable = (Position of BotBuilder[(Player number of (Picked player))])
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Terrain type at BotCheckBuildable) Equal to Lordaeron Summer - Rock
            • Then - Actions
              • Unit - Order BotBuilder[(Player number of (Picked player))] to Move To StartUnitPoints[(Player number of (Picked player))]
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • BotBuilding[(Player number of (Picked player))] Equal to False
                • Then - Actions
                  • Unit - Order BotBuilder[(Player number of (Picked player))] to build a Barracks at (Position of BotBuilder[(Player number of (Picked player))])
                • Else - Actions
          • Custom script: call RemoveLocation(udg_BotCheckBuildable)
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
Possible reasons:
1) It cannot afford the Barracks.
2) It cannot build the Barracks because something is blocking the build position. Perhaps the builder itself?
3) The Barracks is missing from it's construction list.

I would first confirm that none of these are the case and then I would try to get the Builder to do something else like cast Blizzard or Shockwave at the Point just to prove it is working. Or better yet, just create a Special Effect at the build Point to confirm that the trigger is reaching the stage where the Builder attempts to create the Barracks.

Also, you can optimize this trigger a lot and avoid a leak by doing this:
  • BotBuild
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Player Group - Pick every player in BotGroup and do (Actions)
        • Loop - Actions
          • Set VariableSet BotPN = (Player number of (Picked player))
          • Set VariableSet BotCheckBuildable = (Position of BotBuilder[BotPN])
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Terrain type at BotCheckBuildable) Equal to Lordaeron Summer - Rock
            • Then - Actions
              • Unit - Order BotBuilder[BotPN] to Move To StartUnitPoints[BotPN]
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • BotBuilding[BotPN] Equal to False
                • Then - Actions
                  • Unit - Order BotBuilder[BotPN] to build a Barracks at BotCheckBuildable
                • Else - Actions
          • Custom script: call RemoveLocation(udg_BotCheckBuildable)
 
Level 5
Joined
Feb 5, 2021
Messages
89
Possible reasons:
1) It cannot afford the Barracks.
2) It cannot build the Barracks because something is blocking the build position. Perhaps the builder itself?
3) The Barracks is missing from it's construction list.

I would first confirm that none of these are the case and then I would try to get the Builder to do something else like cast Blizzard or Shockwave at the Point just to prove it is working. Or better yet, just create a Special Effect at the build Point to confirm that the trigger is reaching the stage where the Builder attempts to create the Barracks.

Also, you can optimize this trigger a lot and avoid a leak by doing this:
  • BotBuild
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Player Group - Pick every player in BotGroup and do (Actions)
        • Loop - Actions
          • Set VariableSet BotPN = (Player number of (Picked player))
          • Set VariableSet BotCheckBuildable = (Position of BotBuilder[BotPN])
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Terrain type at BotCheckBuildable) Equal to Lordaeron Summer - Rock
            • Then - Actions
              • Unit - Order BotBuilder[BotPN] to Move To StartUnitPoints[BotPN]
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • BotBuilding[BotPN] Equal to False
                • Then - Actions
                  • Unit - Order BotBuilder[BotPN] to build a Barracks at BotCheckBuildable
                • Else - Actions
          • Custom script: call RemoveLocation(udg_BotCheckBuildable)

Thank you for the quick reply, i've checked all of your points sort of

1. This barracks is a custom one and has no resource cost
2. It does start building, when it starts to construct it just moves the builder out of the way but stops when it cannot go further right so when the builder is on the top instead of to the right of the building it stops working.
3. Made sure its there (double checked)👍

Im guessing it has something to do with how the "push worker on construction" works

Any ideas?
 
Level 5
Joined
Feb 5, 2021
Messages
89
1) Order the worker to continue construction after it stops. I believe you use the Repair ability for this.
2) Disable collision on the worker.
3) Make the Barracks automatically construct itself like Undead buildings.
Thank you again for the quick reply

I think there might have been a misunderstanding, the buildings are being fully constructed, when it builds them, it just stops making new ones, sometimes it builds 1 or 2 and other times it builds 11, hence my confusion.

The collision on i will try though thanks
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
Oh, then that narrows it down, possible issues:
1) You're removing the Player from BotGroup.
2) You're turning off the BotBuild trigger somewhere.
3) You're failing to manage BotBuilding[] properly. If it remains True the Bot will never build.
4) The Computer AI kicks in and says "NO MORE BARRACKS!".

You may want to change the Computer player to the Unused status so that it's AI doesn't interfere.
However, I think it's more likely that BotBuilding doesn't get Set to False and that's the cause of the issue.
 
Level 5
Joined
Feb 5, 2021
Messages
89
Oh, then that narrows it down, possible issues:
1) You're removing the Player from BotGroup.
2) You're turning off the BotBuild trigger somewhere.
3) You're failing to manage BotBuilding[] properly. If it remains True the Bot will never build.
4) The Computer AI kicks in and says "NO MORE BARRACKS!".

You may want to change the Computer player to the Unused status so that it's AI doesn't interfere.
However, I think it's more likely that BotBuilding doesn't get Set to False and that's the cause of the issue.
You sure are quick on the responses, i appreciate that alot, also you have a bunch of valid points.

1. I have nothing that removes the Player from the BotGroup
2. Again, nothing will turn this one off unless there is a hidden mechanic i am unaware of at this point in time since nothing has been made to turn it off, also when i run it with 5 different "Bots" they all vary in how many buildings they produce so it seems rather random.
3. Nothing sets it to true, yet .. i had something but removed it altogether, though i may just remove the whole variable until i get it working without it. worth a shot atleast.
4. There should be no apparent AI on unless there is some sort of default built in AI? :)

I will try changing it to unused and see what happens, thank you again for the quick replies.
 
Level 5
Joined
Feb 5, 2021
Messages
89
I think i just found out, i tried applying "myself" as a bot to see what happens if i move around the builder and it seems like it gets fucked from the way the building works with "position of unit" since this building uses 4 "squares" to build, it places the builder in the top right corner of the "squares" and then it determines from there wether or not it is able to build, this opens up possibilities, even though this may be to hard to me as a beginner to figure out i had a lot to think about and work with from your replies, thank you very much! :)

EDIT: I previously thought that if i built on position it would place the building sort of in the middle from the builder, but apparently not :)
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
Ah, yeah, buildings snap to the grid using their Pathing Texture as the pathing requirement. You'll need to find a spot that's actually buildable, but that shouldn't mean that the Builder completely stops forever. Wouldn't they just fail and then try again somewhere else?

A possible solution would be this:
Create a Barracks at the BotCheckBuildable Point, it will automatically get shifted to the nearest pathable location by the pathing system, then store it's position in another Point variable. Then Remove the building from the game and order the Builder to build at that new Point.

  • Then - Actions
    • Unit - Turn collision OFF for BotBuilder[BotPN]
    • Unit - Create 1 Barracks at BotCheckBuildable
    • Set Variable BotBuildPoint = Position of (Last created unit)
    • Unit - Remove (Last created unit)
    • Unit - Turn collision ON for BotBuilder[BotPN]
    • Unit - Order BotBuilder[] to build a Barracks at BotBuildPoint
    • Custom script: call RemoveLocation(udg_BotBuildPoint)
 
Level 5
Joined
Feb 5, 2021
Messages
89
Ah, yeah, buildings snap to the grid using their Pathing Texture as the pathing requirement. You'll need to find a spot that's actually buildable, but that shouldn't mean that the Builder completely stops forever. Wouldn't they just fail and then try again somewhere else?

A possible solution would be this:
Create a Barracks at the BotCheckBuildable Point, it will automatically get shifted to the nearest pathable location by the pathing system, then store it's position in another Point variable. Then Remove the building from the game and order the Builder to build at that new Point.

  • Then - Actions
    • Unit - Turn collision OFF for BotBuilder[BotPN]
    • Unit - Create 1 Barracks at BotCheckBuildable
    • Set Variable BotBuildPoint = Position of (Last created unit)
    • Unit - Remove (Last created unit)
    • Unit - Turn collision ON for BotBuilder[BotPN]
    • Unit - Order BotBuilder[] to build a Barracks at BotBuildPoint
    • Custom script: call RemoveLocation(udg_BotBuildPoint)

God damn, only a couple minutes, impressive with both a reply and a possible solution :eek:

This solution slightly puzzles me, because you are right, it will shift the worker when i build "on him" but as said it all depends on where he gets shifted as to wether he will be able to keep building or not.

In your solution you i feel like its counter intuitive since it also looks like it will be removing the barracks is that correct?
Cause i need the builder to keep building several of them so removing it everytime i "build a new" one would be .. pointless?
OBS!: i may not fully understand your solution ;)
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
That created Barracks is only there to find you a spot where your Builder can actually begin constructing the real structure. Notice how I Create it, Store it's position, and then Remove it. The player won't even know it was ever there because it's created/removed all in the same frame.

Also, you can try to force the Builder to finish building:
The Builder starts construction -> The constructing building pushes the Builder away, cancelling the build process -> You then Order your Builder to Repair the structure.

You may need to add a short delay before issuing the Repair order. A 1 frame delay should be all that's needed so a 0.00 second Timer would work.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
Here's a demo map that I managed to get working. I created it on the latest patch so you'll need to be up to date to open it. Otherwise, here are the triggers:
  • Bot Builder Setup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Player Group - Add Player 2 (Blue) to Bot_PlayerGroup
      • Set VariableSet Bot_Builder[2] = Peasant 0001 <gen>
  • Bot Builder AI
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Player Group - Pick every player in Bot_PlayerGroup and do (Actions)
        • Loop - Actions
          • Set VariableSet Bot_PN = (Player number of (Picked player))
          • -------- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Current order of Bot_Builder[Bot_PN]) Equal to (Order(<Empty String>))
            • Then - Actions
              • -------- The number 10 in the For Loop represents the maximum number of attempts that will be made to find a safe Point: --------
              • For each (Integer Bot_Loop) from 1 to 10, do (Actions)
                • Loop - Actions
                  • Set VariableSet Bot_Point = (Random point in (Playable map area))
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Terrain pathing at Bot_Point of type Buildability is off) Equal to False
                    • Then - Actions
                      • Game - Display to (All players) for 1.00 seconds the text: |cff00ff00Point fou...
                      • Custom script: exitwhen true
                    • Else - Actions
                      • Game - Display to (All players) for 1.00 seconds the text: |cffff0000Point was...
                      • Custom script: call RemoveLocation(udg_Bot_Point)
              • -------- --------
              • -------- This created Barracks should help guarantee that the Builder is ordered to build somewhere pathable: --------
              • Custom script: if udg_Bot_Point != null then
              • Unit - Create 1 Barracks for Neutral Passive at Bot_Point facing Default building facing degrees
              • Custom script: call RemoveLocation(udg_Bot_Point)
              • Set VariableSet Bot_Point = (Position of (Last created unit))
              • Unit - Remove (Last created unit) from the game
              • Unit - Order Bot_Builder[Bot_PN] to build a Barracks at Bot_Point
              • Custom script: call RemoveLocation(udg_Bot_Point)
              • Custom script: endif
            • Else - Actions
The idea here is that we check the current order of the Builder to figure out whether it should be building or not. If the order is <Empty String>, also known as (null), that means the Builder isn't doing anything and is free to go build somewhere. I then use a For Loop in order to test several random points around the map at once in hopes of finding a pathable one. The higher you increase the number 10 here, the more attempts that will be made. Don't make the number too large or you may see performance issues. Finally, I create a "dummy" Barracks at the pathable point (IF one was found) which then allows Warcraft 3's pathing system to kick in, which SHOULD push the Barracks to the nearest pathable Point automatically. We can then get this nearest pathable point by getting the position of the dummy Barracks. After this whole process is done we should be left with a truly pathable Point that we can then Order the Builder to build on.

You can delete those Text Messages, I left them there to help visualize what was happening in the trigger.
 

Attachments

  • Bot Building.w3m
    23.6 KB · Views: 2
Last edited:
Level 5
Joined
Feb 5, 2021
Messages
89
Aha! Now it makes perfect sense, also it is quite neat and i will def try it out as soon as i get on my pc!

Thank you so much for your time!
This just made my day!
 
Level 5
Joined
Feb 5, 2021
Messages
89
Here's a demo map that I managed to get working. I created it on the latest patch so you'll need to be up to date to open it. Otherwise, here are the triggers:
  • Bot Builder Setup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Player Group - Add Player 2 (Blue) to Bot_PlayerGroup
      • Set VariableSet Bot_Builder[2] = Peasant 0001 <gen>
  • Bot Builder AI
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Player Group - Pick every player in Bot_PlayerGroup and do (Actions)
        • Loop - Actions
          • Set VariableSet Bot_PN = (Player number of (Picked player))
          • -------- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Current order of Bot_Builder[Bot_PN]) Equal to (Order(<Empty String>))
            • Then - Actions
              • -------- The number 10 in the For Loop represents the maximum number of attempts that will be made to find a safe Point: --------
              • For each (Integer Bot_Loop) from 1 to 10, do (Actions)
                • Loop - Actions
                  • Set VariableSet Bot_Point = (Random point in (Playable map area))
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Terrain pathing at Bot_Point of type Buildability is off) Equal to False
                    • Then - Actions
                      • Game - Display to (All players) for 1.00 seconds the text: |cff00ff00Point fou...
                      • Custom script: exitwhen true
                    • Else - Actions
                      • Game - Display to (All players) for 1.00 seconds the text: |cffff0000Point was...
                      • Custom script: call RemoveLocation(udg_Bot_Point)
              • -------- --------
              • -------- This created Barracks should help guarantee that the Builder is ordered to build somewhere pathable: --------
              • Custom script: if udg_Bot_Point != null then
              • Unit - Create 1 Barracks for Neutral Passive at Bot_Point facing Default building facing degrees
              • Custom script: call RemoveLocation(udg_Bot_Point)
              • Set VariableSet Bot_Point = (Position of (Last created unit))
              • Unit - Remove (Last created unit) from the game
              • Unit - Order Bot_Builder[Bot_PN] to build a Barracks at Bot_Point
              • Custom script: call RemoveLocation(udg_Bot_Point)
              • Custom script: endif
            • Else - Actions
The idea here is that we check the current order of the Builder to figure out whether it should be building or not. If the order is <Empty String>, also known as (null), that means the Builder isn't doing anything and is free to go build somewhere. I then use a For Loop in order to test several random points around the map at once in hopes of finding a pathable one. The higher you increase the number 10 here, the more attempts that will be made. Don't make the number too large or you may see performance issues. Finally, I create a "dummy" Barracks at the pathable point (IF one was found) which then allows Warcraft 3's pathing system to kick in, which SHOULD push the Barracks to the nearest pathable Point automatically. We can then get this nearest pathable point by getting the position of the dummy Barracks. After this whole process is done we should be left with a truly pathable Point that we can then Order the Builder to build on.

You can delete those Text Messages, I left them there to help visualize what was happening in the trigger.

This template works like a charm! love it! now i can get to making the parameters for all the basic things! thank you so much for you help!!
 
Status
Not open for further replies.
Top