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

AI Script Difficulties

Hey, I am experiencing some difficulty eliciting certain behaviours from a custom AI Script for a project I've been working on. Currently, @SgtWinter and I have successfully gotten the AI to function to a certain extent, but at certain points the AI decides to expand constantly while not seeming to recognise new gold mines they have built at as being an expansion (or, at least, something they can mine from). Initially, the AI would mass expand before doing anything, so this is, believe it or not, an improvement.

This behaviour seems to emerge when the AI has one or two gold mines collapse. I have attached the ".wai" file we are using - the project does not use heroes, so these are not of any concern to us. Any help in determining what is causing this problem would be appreciated, especially since custom AI scripts are an area we're not overly familiar with.
 
Oh that's annoying, I specifically added it, I will need to try again >.<

EDIT: Rather annoyingly I don't seem to be able to upload .wai files, and if I upload it as a .ai then it won't be able to be opened in the AI Editor

The best I seem to be able to do is to upload a map containing the file
 

Attachments

  • AI Script.w3m
    178.3 KB · Views: 12
Or just upload the .ai anyway, the AI editor is kinda bad. Tbh I would make any AI scripts just using a text editor/syntax highlighter, the AI editor does weird stuff.
I guess I'm going with the AI Editor at the moment since the alternative is... very difficult for me to edit personally, but it does seem to do some things very strangely. Hell, it's probably doing something that I've not even recognised as yet.

I'm also wondering if it's partly responsible for a game lagging when I was observing a cluster of 5 AIs playing against each other at the same time. It was done in multiplayer with another player at the time, so the multiplayer aspect may have been a factor, but seeing so much action on the map at once seemed to have caused some processing complications from an observer stand point - reckon AI Editor would be adding some unnecessary details which could be partly responsible for causing this?
 
I guess I'm going with the AI Editor at the moment since the alternative is... very difficult for me to edit personally, but it does seem to do some things very strangely. Hell, it's probably doing something that I've not even recognised as yet.

I'm also wondering if it's partly responsible for a game lagging when I was observing a cluster of 5 AIs playing against each other at the same time. It was done in multiplayer with another player at the time, so the multiplayer aspect may have been a factor, but seeing so much action on the map at once seemed to have caused some processing complications from an observer stand point - reckon AI Editor would be adding some unnecessary details which could be partly responsible for causing this?
I have heard that there has sometimes been lag spikes associated with Ai's and expansions. I've never encountered it myself so I don't know if it's a myth or something actually to do with the expansion AI functions or something else entirely that's coincidental. Is this meant to be similar to a regular melee AI? Because if so it might be worth working from the OG vanilla AI's and simply editing and adjusting them to suit whatever new faction or system you have :)
 
I have heard that there has sometimes been lag spikes associated with Ai's and expansions. I've never encountered it myself so I don't know if it's a myth or something actually to do with the expansion AI functions or something else entirely that's coincidental. Is this meant to be similar to a regular melee AI? Because if so it might be worth working from the OG vanilla AI's and simply editing and adjusting them to suit whatever new faction or system you have :)
Unfortunately not, it's more akin to a Starcraft-like in terms of gameplay, so there's a higher volume of units and potentially even more expanding than you would normally see in melee (I believe, although AI can do whatever we want in melee as well I suppose lol).
Funnily enough, though, the base AI was originally developed from looking at the GruntMaster.wai and WyrmMonger.wai AI Scripts as a sort of basis to work from, with some adjustments being made to accommodate the new style of gameplay.
 
Ah well then maybe the actual melee scripts might be a better starting point and just add more expansions etc, the number of units as well isn't really much of an issue.

In terms of the lag like I said I'm not sure, I can't think of what loops in an AI would be particularly lag inducing but I'm also not that familiar with what's going on under the hood in Warcraft and AIs sorry!
 
So far that's what we've tried doing, more or less, but at the moment it's hard to pinpoint why the AI can get a bit fixated on expanding endlessly. Originally it started by doing this without deviating towards anything else in its build order for a while, but what's more perplexing to me is that a lot of these expansions that the AI takes doesn't seem to recognize that it can (and maybe should) send workers to mine gold from them. Like it's not registering that they can do that, for some reason. I'll see them send workers to harvest wood from these expansions, but they'll often ignore the gold - I've managed to get this behaviour to only really occur in the later stages of the game of late, but I don't know why it happens at all.
 
Weirdly enough, after downloading the map, there's still no way to open the .wai file, I see it in the asset manager but we can't export it to then open it in the AI editor... <<
Oh for real? That's annoying, I wonder if it has anything to do with the version I'm using? I'm running it on Reforged, although I don't know how much that impacts things like AI Scripts
 
Level 21
Joined
Mar 16, 2008
Messages
955
There are multiple functions to make ai scripts build expansions and not over expand. The method I went with I think was the that I explained in this post, using conditions: [JASS] - Help with custom race melee Ai.

Edit: you can do this with GUI too.
1725844457853.png

...I don't know if melee AI makes enough calls for this to matter.
In tests with debug messages, it seems to pretty much spam the entire script every few seconds.
 
Last edited:
My editor is running the reforged version too, so at least that's not a version incompatibility

It's weird that .wai files can't be uploaded here out of all things, perhaps the pastebin would allow? (https://www.hiveworkshop.com/pastebin/add) It's pretty much the same interface but who knows :smile:
Ah I tried the pastebin and had the same experience there, unfortunately. I think best I can do potentially is the .ai file, maybe?
Or... there might be a relatively simpler solution. Don't know why I didn't consider using winrar for them before, that should hopefully work better :D
common.ai has handles leaking and if the performance (FPS) suddenly starts to get progressively worse (when you have exhausted all free time between frames for compute) then the issues are caused by the leaks. This is definitely a problem but I don't know if melee AI makes enough calls for this to matter.
Oh thank you, I should check those to see if any of those issues are apparent in the processing. Although in my case, the player who didn't have full vision of the map seemed to experience appropriate FPS rates, so it might have just been my observing so much happening all at once. I'd still like to be sure, though.

There are multiple functions to make ai scripts build expansions and not over expand. The method I went with I think was the that I explained in this post, using conditions: [JASS] - Help with custom race melee Ai.

Edit: you can do this with GUI too.


In tests with debug messages, it seems to pretty much spam the entire script every few seconds.
Oh this might just be right up the alley of what I was looking for, thank you very much! :)
Yeah we've been using conditions, but we might have done something weird with them since we've not seen this issue in similar (but much "simpler") scripts we dabbled with previously. It might be something we added that is causing this sort of behaviour.
 

Attachments

  • Knight_CavalryAITest11.rar
    75.3 KB · Views: 3
What if it's simply a "allow change home" option problem. Because they might be fixed to the collapsed gold mine? Hmm IDK.
It sounds like it makes a lot of sense, tbh, and it's an area I'd never considered before 😲
Half the trouble has been that they don't seem to use new gold mines even when they set up for them... damn I think that might be it! I'll give it a crack, see if that fixes the issue :D

NOTE: Sometimes, sometimes the AI does seem to use a new Gold Mine, but it's super inconsistent. I think this could still be an issue fixable by what you described, though.


UPDATE: I checked the Script and apparently the "Allow Change Home" was already checked, unfortunately.
1725931092542.png

There must be something else that I'm either not noticing or just not aware of :/
 
Last edited:
Level 21
Joined
Mar 16, 2008
Messages
955
Maybe look into force-changing the start location to a new spot. I remember from my tests that the AIs target these when attacking. IDK just taking guesses at this point.

Maybe also just wait a bit. Once you turn on expansions it seems they keep doing them but sometimes takes a minute. I think there must be a lot of stuff running in the background that basic mappers like us aren't aware of. I'd just keep trying to do a few tests.
 
Maybe look into force-changing the start location to a new spot. I remember from my tests that the AIs target these when attacking. IDK just taking guesses at this point.

Maybe also just wait a bit. Once you turn on expansions it seems they keep doing them but sometimes takes a minute. I think there must be a lot of stuff running in the background that basic mappers like us aren't aware of. I'd just keep trying to do a few tests.
How do I go about force-changing the start location? Is that in triggers, or the AI Editor?

For testing I've often waited a long while to about the end point where the AI is no longer especially active. By then, they usually take all of the Gold Mines that they can and the majority of them they use as expansion points for harvesting lumber exclusively, for some strange reason. I would definitely love to see some of what the AI is trying to run in the background, just enough to get a general idea of how it processes things 🤔
 
Level 21
Joined
Mar 16, 2008
Messages
955
I'm not sure it's possible to change the start location. I've left the realm of sharing what I know about AI, now I'm just trying to make a guess to help your situation. Maybe some custom script or JASS command could change the start location.

One thing I did in my map when the AI scripting just got too advanced is just to order units around controlled by neutral player. Perhaps have a neutral peasant build the structure with triggers then when/if it completes transfer ownership to the AI. This is pretty much how I have the AI do 'item crafting recipes' in one of the maps.

Not really sure. Just keep testing and seeing how the AI behaves.
 
I'm not sure it's possible to change the start location. I've left the realm of sharing what I know about AI, now I'm just trying to make a guess to help your situation. Maybe some custom script or JASS command could change the start location.

One thing I did in my map when the AI scripting just got too advanced is just to order units around controlled by neutral player. Perhaps have a neutral peasant build the structure with triggers then when/if it completes transfer ownership to the AI. This is pretty much how I have the AI do 'item crafting recipes' in one of the maps.

Not really sure. Just keep testing and seeing how the AI behaves.
Hmm it does seem like it is a lot of trial and error, although lately we have been able to get more effective results out of the AI. Thank you for sharing what you can!

One thing I find myself wondering about more lately, now, is how do attack waves work? From what I can gather, setting up the Attack Waves in the AI Editor seems to be limited - something I would like, for example, would be for the AI to send an attack wave of a main fighting force, but then send some units in another attack wave simultaneously separate to the main attack force, potentially to a different target. Do you know much about setting up AI to not just deathball?
 
Hmm it does seem like it is a lot of trial and error, although lately we have been able to get more effective results out of the AI. Thank you for sharing what you can!

One thing I find myself wondering about more lately, now, is how do attack waves work? From what I can gather, setting up the Attack Waves in the AI Editor seems to be limited - something I would like, for example, would be for the AI to send an attack wave of a main fighting force, but then send some units in another attack wave simultaneously separate to the main attack force, potentially to a different target. Do you know much about setting up AI to not just deathball?
All this kind of stuff is handled by attack "captains" now you can control an attack group as long as there is a "captain" the problem being you are limited to two: attack captain and defence captain. So the moment you create a new attack group you lose control of the previous one. Somebody experimented with captains in AI ages ago but I dont think they got anywhere or ever finished it.
 
Level 28
Joined
Dec 3, 2020
Messages
970
Hmm it does seem like it is a lot of trial and error, although lately we have been able to get more effective results out of the AI. Thank you for sharing what you can!

One thing I find myself wondering about more lately, now, is how do attack waves work? From what I can gather, setting up the Attack Waves in the AI Editor seems to be limited - something I would like, for example, would be for the AI to send an attack wave of a main fighting force, but then send some units in another attack wave simultaneously separate to the main attack force, potentially to a different target. Do you know much about setting up AI to not just deathball?
I recommend not using the AI editor to make AI scripts for the bots.

Also I do not think that it's possible to do what you want (2 attack waves at once from same AI).
You can create another AI for that. What you can do there is interesting. You can tell the AI to attack suicide its units against a specific player. I do recommend finding a good approach to creating units for the AI if you do that, but what I am talking about is that you can:
Make 1 "suicide" script where you tell the AI which unit types attack a specific player (you can make it attack ALL the desired players you want it to attack).

function main takes nothing returns nothing
call CampaignAI(BURROW,null) // can be burrow or farm, doesn't matter
call GroupTimedLife(true) // set this to true just in case
call SetPeonsRepair( true ) // set this to true if you want their peons to repair structures and mech units
//SetTargetHeroes(false) // i usually set this to false (i think default is false, at least for easy and normal difficulties)
//SetHeroesFlee(false) // i suggest setting this and the other 2 below to false
//SetUnitsFlee(false)
//SetGroupsFlee(false)

loop
call SuicideUnitEx( 1, 'hfoo', 0 )
call SuicideUnitEx( 1, 'h001', 1 )
call SuicideUnitEx( 1, 'h002', 2 )
call Sleep(0.1)
endloop
endfunction

Here a footman "hfoo" unit-type will suicide attack into player 1 (Red), footman "h001" unit-type into player 2 (Blue) and "h003" into player 3 (Teal).
So if main AI is attacking player 4 (Purple) for example, you can create footmen (for example) for this AI player to attack the desired players.
You do have to check when the main AI will send its attacks though.
And sometimes the AI attacks the wrong player. So index "1" in the attack function is supposed to be player 2 (Blue) but the AI will attack player 1 (Red), so just change the index to 2. So keep that in mind.

PS: "hfoo" is the original footman unit-type, but "h001" and so on are custom units that you create in the object editor. In this example, "h001" and "h002" are supposed to be footmen.
 
Last edited:
Level 28
Joined
Dec 3, 2020
Messages
970
I think you might be able to do multiple groups but it's personally something i've never experimented with

Hmm I shall test out soon if it is possible with a jass script.
To be honest I have never tried so don't take my word for granted.
Maybe giving the 2nd attack a 0 seconds delay would do the trick. It might still go out around 20 seconds later than the main attack though cause of WC3 AI.
 
You can definitely do multiple attacks, however once the attack captain gets reassigned to the other group you will no longer be able to control or direct the previous one unless you are able to grab those units again and put them back into an attack group with an attack captain.
 
All this kind of stuff is handled by attack "captains" now you can control an attack group as long as there is a "captain" the problem being you are limited to two: attack captain and defence captain. So the moment you create a new attack group you lose control of the previous one. Somebody experimented with captains in AI ages ago but I dont think they got anywhere or ever finished it.
Damn, and there's no way to create more captains? That is rough
I recommend not using the AI editor to make AI scripts for the bots.

Also I do not think that it's possible to do what you want (2 attack waves at once from same AI).
You can create another AI for that. What you can do there is interesting. You can tell the AI to attack suicide its units against a specific player. I do recommend finding a good approach to creating units for the AI if you do that, but what I am talking about is that you can:
Make 1 "suicide" script where you tell the AI which unit types attack a specific player (you can make it attack ALL the desired players you want it to attack).

function main takes nothing returns nothing
call CampaignAI(BURROW,null) // can be burrow or farm, doesn't matter
call GroupTimedLife(true) // set this to true just in case
call SetPeonsRepair( true ) // set this to true if you want their peons to repair structures and mech units
//SetTargetHeroes(false) // i usually set this to false (i think default is false, at least for easy and normal difficulties)
//SetHeroesFlee(false) // i suggest setting this and the other 2 below to false
//SetUnitsFlee(false)
//SetGroupsFlee(false)

loop
call SuicideUnitEx( 1, 'hfoo', 0 )
call SuicideUnitEx( 1, 'h001', 1 )
call SuicideUnitEx( 1, 'h002', 2 )
call Sleep(0.1)
endloop
endfunction

Here a footman "hfoo" unit-type will suicide attack into player 1 (Red), footman "h001" unit-type into player 2 (Blue) and "h003" into player 3 (Teal).
So if main AI is attacking player 4 (Purple) for example, you can create footmen (for example) for this AI player to attack the desired players.
You do have to check when the main AI will send its attacks though.
And sometimes the AI attacks the wrong player. So index "1" in the attack function is supposed to be player 2 (Blue) but the AI will attack player 1 (Red), so just change the index to 2. So keep that in mind.

PS: "hfoo" is the original footman unit-type, but "h001" and so on are custom units that you create in the object editor. In this example, "h001" and "h002" are supposed to be footmen.
Oh that could be handy, so when you suicide the units, they can't be collected in another control group? I might have to keep that in mind, although there does seem to be a lot to learn about how attack waves are handled. I've sort of been hoping I can create an attack group out of one group of units (for example, Footmen), send them on an attack wave, and then select another attack group of another unit (for example, Riflemen) and send them separately. But as soon as those orders come in, barring suiciding them, do they get joined together in the same attack group? It does seem strange that Blizzard would limit their attack waves so much.
Is it possile to run multiple AIs for the same player? 🤔
I think you might be able to do multiple groups but it's personally something i've never experimented with

Oh we've absolutely been using multiple groups, but hoping to get them to send as separate attack waves which is... not seeming like a possibility.
One thing I have learned from the GUI side of things when converting to Jass is that attack waves are handled linearly, where they will get to the final attack wave and just repeat that indefinitely. Warcraft 3 AI is phenomenally simplistic like that, to the point that it revolves primarily around deathballing. Trying to get it to change this behaviour is... proving to be challenging, to put it mildly.
 
Level 28
Joined
Dec 3, 2020
Messages
970
Damn, and there's no way to create more captains? That is rough

Oh that could be handy, so when you suicide the units, they can't be collected in another control group? I might have to keep that in mind, although there does seem to be a lot to learn about how attack waves are handled. I've sort of been hoping I can create an attack group out of one group of units (for example, Footmen), send them on an attack wave, and then select another attack group of another unit (for example, Riflemen) and send them separately. But as soon as those orders come in, barring suiciding them, do they get joined together in the same attack group? It does seem strange that Blizzard would limit their attack waves so much.
Is it possile to run multiple AIs for the same player? 🤔

Oh we've absolutely been using multiple groups, but hoping to get them to send as separate attack waves which is... not seeming like a possibility.
One thing I have learned from the GUI side of things when converting to Jass is that attack waves are handled linearly, where they will get to the final attack wave and just repeat that indefinitely. Warcraft 3 AI is phenomenally simplistic like that, to the point that it revolves primarily around deathballing. Trying to get it to change this behaviour is... proving to be challenging, to put it mildly.
So...
  • Note that the script I provided will tell the AI to always send the specified unit types to attack the enemy. Meaning that instantly upon training or creating such units, they will immediately go attack the enemy.
  • What you can do is make the AI have a footman unit type that will not attack any enemies. Then replace it (the group of footmen that you have selected through triggers) with a trigger with a footman unit type that will suicide attack. Same for riflemen or any other unit.
  • It can get a bit tricky and tiresome though, so keep that in mind.
  • You can add as many Suicide functions in that loop in the script btw. Like you can put 100 different unit types in there.
  • They won't join together as long as they are given different players to attack. You can also have 2 riflemen groups that will attack players A and B and another footman group that will attack player C simultaneously.
  • I have yet to experiment if multiple AI scripts can work on a single AI player, but I'm a bit lazy. I do wanna see what happens though so if I do it I will let you know
 
Damn, and there's no way to create more captains? That is rough
At this point you could always help all of us out by doing some testing and deep dive on this. My memory might be faulty but if you try to index more captains it crashes (although it has been a while since I've read up on this). Theoretically yes you can have more captains and there's JASS functions for handling the captains, however the extent of how to implement and use these captains beyond the initial two, reference them etc is something far beyond anything I've dealt with or have knowledge on. IIRC the "captains" are referenced via an index so defence captain is 1 and attack captain is 2 or something like that which does leave open the possibility of more captains assigned to 3,4 etc but again this is all in theory and I have no experience or idea about the practicalities of it.

Addendum: As I make campaigns and nothing too far out there in terms of AI requirements don't hold your breath on me ever deep diving into this or testing any of it myself since I don't think I'll ever need to :p call SuicideOnPlayerEx() is my King.
 
So...
  • Note that the script I provided will tell the AI to always send the specified unit types to attack the enemy. Meaning that instantly upon training or creating such units, they will immediately go attack the enemy.
  • What you can do is make the AI have a footman unit type that will not attack any enemies. Then replace it (the group of footmen that you have selected through triggers) with a trigger with a footman unit type that will suicide attack. Same for riflemen or any other unit.
  • It can get a bit tricky and tiresome though, so keep that in mind.
  • You can add as many Suicide functions in that loop in the script btw. Like you can put 100 different unit types in there.
  • They won't join together as long as they are given different players to attack. You can also have 2 riflemen groups that will attack players A and B and another footman group that will attack player C simultaneously.
  • I have yet to experiment if multiple AI scripts can work on a single AI player, but I'm a bit lazy. I do wanna see what happens though so if I do it I will let you know
So in my own brief experiments, I had the original AI, and I had a modified one to only have one attack wave. Initially, I used the original AI and provided a command string to "apply" the new, more limited AI that followed the same build order but only would attack with one unit. Upon applying, no changes were observed.

So to be sure it wasn't compiling the attack patterns together, I reversed the order - this time, the AI started with only the attack wave of one unit type, but would then apply the AI that had more detail. Similarly, however, there was no observable change. It seems that any attempts to add another AI to the same player does not demonstrate any meaningful change, indicating that perhaps it is just not loading at all.

At this point you could always help all of us out by doing some testing and deep dive on this. My memory might be faulty but if you try to index more captains it crashes (although it has been a while since I've read up on this). Theoretically yes you can have more captains and there's JASS functions for handling the captains, however the extent of how to implement and use these captains beyond the initial two, reference them etc is something far beyond anything I've dealt with or have knowledge on. IIRC the "captains" are referenced via an index so defence captain is 1 and attack captain is 2 or something like that which does leave open the possibility of more captains assigned to 3,4 etc but again this is all in theory and I have no experience or idea about the practicalities of it.

Addendum: As I make campaigns and nothing too far out there in terms of AI requirements don't hold your breath on me ever deep diving into this or testing any of it myself since I don't think I'll ever need to :p call SuicideOnPlayerEx() is my King.
Ah man, I'll certainly do what I can to experiment around with this and see what I can uncover, but my Jass knowledge is rather limited and some stuff is just so hard coded that I doubt we'll be able to edit it meaningfully. Some of those parameters that have multiple indexes can be dodgy - for example, changing the attack range of units is an interesting endeavour. You have the option of saying which attack type you want to edit, the first one or the second one. Now, in some cases, they refer to 1 as 0 and 2 as 1, pretty standard fair - until they don't, and then 1 is 1 and 2 is 2. Or, rather, in one of those instances, 2 is not able to be referenced. I found I could add attack range to both attack types, I believe it was, but I could not subtract. It was a strangely busted command prompt that works purely for attack 1.

Similarly, we might experience something similar with attack captains. There might just be no real way of adding anything to these parameters, but maybe there's something to find - I would love to know if we can, at any point, "unhide" these widgets, although I doubt that's ever going to be possible. I actually struggled to get messages to appear in AI Script - I followed some direction from another thread, and in my own tests I found the AI just wouldn't run, while in Winter's tests the AI would run, it just wouldn't display any messages.
 
Top