In this tutorial I'm gonna show you how to make a good melee AI using the AI Editor, I'm not gonna talk about how the editor works since there are other good tutorials made for that purpose, like Av3n's "The AI Editor".

What you must know to understand and use correctly this tutorial?

1. How does the AI Editor work, if you don't know that, see Av3n's tutorial then come back here later.
2. How do conditions work in GUI Triggering

Another thing: I didn't post any screen of the editor because I have the italian version so it won't help you much, and it may cause side effects like: confusion or learning some italian (both things to avoid xD).
However Sunwarrior25 provided me some screens that will do the job...

I'm gonna base this tutorial on making an AI for a normal Human Race, if it's not what you want (very probably) then adapt this explaination to your needings.

Ok, let's start. We're gonna use the AI Editor page by page, the first page is General,
here we set:

Name: Write the name of the AI here only if you want it to have a different name from the normal "Player 2, Player 10, Player X"

Race: we'll set it to Human (That's Important! if you create a custom race you have to set it to Custom, because with another value you can't change the settings for: Base Building (Hall), Mine Building (Needed only for Haunted Mines), Gold Worker and Lumber Worker in the Building page.)

Set Player Name: Check this only if you wrote a custom name.

Defend Users: This will cause this AI to help its allies when they have enough military units, I suggest you to check it only if you want to have the "United Squads" feature of your map always activated, or if you want this AI to do kamikaze attacks to creeps.

Allow Home Changes: Check this only if you want them to have another chance to stay in the game after their base has been destroyed.

Then I suggest you to check all the other fields, except for "Random Paths" and "Slow Harvesting".

Custom Data: IMPORTANT! The race you're gonna use is a normal race or it has been made modifying the object data? In the first case skip this zone, in the second case, you have to import in the AI editor the .w3o file containing the custom Object Data.

Conditions: Here you set the conditions you're gonna use more that one time in the next pages (except Heroes page), I suggest you to set at least these two conditions:

Attack Possible: (((Total number of Footman units completed) Bigger or Equal to 4) And ((Total number of Rifleman units completed) Bigger or Equal to 3) Or ((Total number of Spellbreaker units completed) Bigger or Equal to 3) And ((Total number of Rifleman units completed) Bigger or Equal to 3))

It's a sequence of "Integer", "And" and "Or" conditions. Why do we have to write all of this? We're gonna set this as the main parameter the AI must use to know when it can attack. Change the underlined fields of this trigger to match it with your race:

(((Total number of T1 Melee units completed) Bigger or equal to X) And ((Total numer of Ranged units completed) Bigger or equal to Y) Or (((Total number of T2 Melee units completed) Bigger or equal to Z) And ((Total numer of Ranged units completed) Bigger or equal to Y)

T1 Melee:
Footman, Ghoul: X = 4
Grunt, Huntress: X = 3

Ranged:
Archer, Headhunter: Y = 4
Rifleman, Crypt Spider: Y = 3

T2 Melee:
Spellbreaker, Raider: Z = 3

Night-Elves and Undead don't have a T2 Melee unit, so skip the second part of the condition if you use them, or set at its place the T3 Melee unit.

Hall: (Food Produced) Minor of 60

(60 is the number of food you have after having upgraded the hall to Tier 2 in my example)
(That's not an important condition normally, but if you use Orcs or Humans, expecially Humans (they have Spellbreakers, that are better than Footmen, while Grunts and Raiders have pretty similar statistics), you can write down this condition and use it later to disable the training of T1 Melee units when the food is more than 59, in this way the AI will have more food to train stronger units (10 in this example))

(However, in the case of Undead and Night-Elves, this trigger could need to be adapted (to the number of food produced after upgrading the hall to Tier 3) or removed, due to conflicts that could happen with the "Attack Possible" condition, so remember that if you use these two conditions, they are strictly linked, so if you change the first, you probably should change also the second and vice-versa)

Another condition that is essential, if you use units that are upgraded to others: (like Siege Machines (Humans) or Troll Headhunters)

This example will be on Siege Machines:

Siege: (Upgrade level of Scatter Rockets) Equal to 0

If that's not clear, here is the example with the Headhunter:

Headhunter: (Upgrade level of Berserker) Equal to 0

(You must set this condition to all the units that are affected by that power-up then, after making the AI use that power-up, set the building queue of all the units of the new type that should be trained)

(If you don't set this, at the moment of the upgrade the AI won't find the non-upgraded unit to be trainable, thus blocking all the AI unit training)

Ok, we finished with the first page, and we can go to the second one, Heroes:

Used heroes: Here you set the number and the kind of heroes.

Normal values in Training Order in each field per hero number:

1 Hero: 100% (5 fields disabled)

2 Heroes: 50%, 50% (4 fields disabled)

3 Heroes: 17%, 17%, 16%, 17%, 17%, 16% (all fields activated)

In the case of 3 heroes, write the values this way, for each field the AI Editor will try to set them in another way, so you have to correct the wrong fields until the result is what you see above.

Skill selection: There's not much to say, here you choose how will AI's heroes learn each skil.

Another thing, if your hero has custom abilities and are not shown in this zone, open the object editor, copy the "Hero Skills" field, return the field to its default values, then paste the "Hero Skills" field and export the Object Data again and import it again in your AI editor.
If this method doesn't work, retry a couple of times and it should, if it doesn't work even after 3 attempts, feel free to PM me the map and the ".wai" file and I'll try to fix it...

Third page (CAUTION! This is the hardest part, some wrong inputs in this page and you'll face a high number of bugs), Building:

First parameters:

Base Building: Put here the Tier 1 Building of your race

Mine Building: Usually this is set to nothing, change it only if you use a Haunted Gold Mine or a Mine based on the Haunted Gold Mine (no, Entagled Gold Mines don't have to be set)

Gold Worker: Simple, harvests gold

Lumber Worker: Usually it's the same value of the Gold Worker but, if you (example) use Undead, here you'll set "Ghoul"

*In the case of a custom hall, maybe it's better to add a condition: (unless you want them to have a bunch of unused T1 Halls in their base)

((Total number of T2 Hall units) equal to 0) And (Total number of T3 Hall units) equal to 0)

Obviously, set T2 Hall and T3 Hall with the buildings you have for Tier 2 Hall and Tier 3 Hall.

** These are the starting units for the AI, so change them with EXACTLY the same units this AI must have at the map init. And, this way, if those workers are killed, they'll be trained by the hall with an active mine, in this way the AI is more efficient.

*** Remember, this only if you don't want them to continue training Footmen when they have Spellbreakers and then Knights

**** In the case of a custom hall, maybe it's better to add a condition: (unless you want them to have a T2 Hall and a T3 in their base at the same time)

(Total number of T3 Hall units) equal to 0)

***** Here you may think: "What the hell can I do with 6 food?" You're wrong, if you used the Hall condition, you have 16 food avaiable now, also if AI Editor tells you the opposite.

****** When The food needed for the queue exceeds the food created by the AI the lines are written in red, but don't worry since, as I explained before, the AI Editor is wrong now.

---------------------------------------------

Finally the third page (and the most difficult) is ended, now the fourth, Attacking:

The first thing to do is to set Attack Groups, 2 attack groups are needed:

Minimum Attack:
This is the minimum of army that the AI will use, I'd base it this way:

* "Why this?" Because this way the AI will always have at least 1 mine and, if you're gonna play as an ally of this AI, won't try to steal every mine YOU clear.

** Not an important priority, if you want, you can also kick it out

---------------------------------------------

FINALLY! The End!

After this, this AI Step-by-Step is completed, feel free to use it as a base for your custom AI.

Only one thing: remember to save this AI and then export the ".ai" script, never import the ".wai" file in your map, it works but it contains also the custom object data you used for your AI, so the 90% of its size is useless to the map, import the ".ai" file instead.

Thanks to Sunwarrior25 for the screenshots of the AI Editor.

Edited because: 28-02-10: Fixed a typo and modified the Target Priorities in order to be... better.

No, the ".wai" file is created only by the AI Editor when you save your AI, it is the AI script + custom data. To have an ".ai" file you have to save first, then use the command "Export Script". (or some similar name)

Though, as I said above, both work, the ".ai" file is space saving... :)

EDIT: Found the best way to get rid of the "Hero Skills" bug, updated the main post!

FURTHER EDIT: Just found out that moyack already did a tutorial like this...

Good point, my bad, turns out the .ai file is imported/created if you import the .wai file. Sorry 'bout that. You were right.

Anyhoo, I made a Custom AI based on my entry for the contest. When I changed the object editor data to include a new spell for the hero (Kyrbi0's "Look Out, Sir!"), it keeps trying to reference the old spell (Howl of Terror). The actual strategy hasn't changed. Any ideas?

EDIT: You could change the tutorial to try to reference a custom race. As far as I know, the AI will automatically use any abilities it has (though I think it might have to be run a few times to get the hang of it). I've also noticed that even if you have 4 computer players with the same exact AI, each on different teams, they'll each behave a little differently.

__________________

Table:

Currently:
- Fooling around with various things.
- Staying up WAY too late.
- Fooling around with various things.

Anyhoo, I made a Custom AI based on my entry for the contest. When I changed the object editor data to include a new spell for the hero (Kyrbi0's "Look Out, Sir!"), it keeps trying to reference the old spell (Howl of Terror). The actual strategy hasn't changed. Any ideas?

Was the strategy this?

Quote:

Originally Posted by Recently Added In The Tutorial

Another thing, if your hero has custom abilities and are not shown in this zone, open the object editor, copy the "Hero Skills" field, return the field to its default values, then paste the "Hero Skills" field and export the Object Data again and import it again in your AI editor.

If you tried this and it didn't work, send me a PM with the map and the ".wai" file and I'll give it a check...

Quote:

Originally Posted by Sunwarrior25

EDIT: You could change the tutorial to try to reference a custom race. As far as I know, the AI will automatically use any abilities it has (though I think it might have to be run a few times to get the hang of it). I've also noticed that even if you have 4 computer players with the same exact AI, each on different teams, they'll each behave a little differently.

For the first point I think that referencing to a custom race could cause a little confusion, but maybe I could attach a map to make people see how does it work...

For the second one, the same AI acts differently depending on different in-game situations, creep positions, mines owned, number of units owned etc.
That's a good thing, because it means that the AI won't act always in the same way, so the map won't have a always-the-same boring AI...

Some handy hints:
1. putting number of unit = number of unit completed as a condition for all your units helps to make sure the building is producing that unit constantly instead of waiting endlessly for the piroties above to be finished

it's better then staggering your units i.e

peasent
footmen
peasent
footmen
peasent
footmen etc

cause what happens if one of your footment gets killed? the ai will try to replace your footmen and delay the production of the peasent.

2. having Creep Camp (0-9) as a first attack piroty will make the ai creap out ALL Creep Camp (0-9) on the map before it attacks the enemy even when you have 100 food. really bad if you face an AI which techs up first gets better units then you then attacks you in one wave wiping out your tier 1 units all in one. Baring in mind your AI doesn't kill it's own units so you end up with loads of footmen at 100 food

3. in the above AI, all uou have to do is make sure you kill enough to make it have less then 10 peasents and it won't build anything else until it replaces it's peasents. Blademaster wind walk haress combined with you're producing units and it's not

1. That doesn't matter because when the AI has got the barracks will train both peasants and footmen at the same time.
The priority list is not that strict, after the AI has issued the order with the highest priority, will issue all the other possible orders in the list at the same time.

2. For creep camps you're right, I'll probably add some conditions, but normally this AI loses all the footmen above even before arriving to have a Castle, thanks to attacks to creep camps or fights between other AIs, and if it doesn't, 5 Footmen (10 food) is not that great problem, believe me.

3. in this AI you're assuming that the AI can train only a unit at a time... if a Blademaster kills all the peasants, be sure that the AI will train both peasants and footmen/spellbreakers/knights at the same time, depending on existing buildings and on research values etc.

However, thanks for the tips, I'll see what to modify for the 2nd point.

I just found out today, that you can add the AI to the map without doing most of the export stuff. Just click 'File > Add to map' and specify what path you want it to be. It'll add the AI to whatever map is open in the WE. Still, if all you need is the .ai file, then just delete the .wai file that appears as normal...

Just thought I'd post that bit of info. It's still a smart Idea to save the map, in case you need to change something later. (I dunno, is it possible to do what I just said in... say... 1.21?)

__________________

Table:

Currently:
- Fooling around with various things.
- Staying up WAY too late.
- Fooling around with various things.

I just found out today, that you can add the AI to the map without doing most of the export stuff. Just click 'File > Add to map' and specify what path you want it to be. It'll add the AI to whatever map is open in the WE. Still, if all you need is the .ai file, then just delete the .wai file that appears as normal...

Just thought I'd post that bit of info. It's still a smart Idea to save the map, in case you need to change something later. (I dunno, is it possible to do what I just said in... say... 1.21?)

Ha! I got so accustomed to "no new replies" for this thread that I didn't check it in a while, sorry...

And... funny, I never ever seen that command (yes, it works on 1.21b), but it seems it imports the AI Data (.wai file), so I won't suggest that. If someone wants to use it, it's in the AI Editor anyway. :P

Originally posted by Rising_DuskYour spells are mostly ignored because they are not very cool so we aren't very excited to review/approve them, but you are incredibly persistent and won't give us an excuse to graveyard it. That is generally what results in a resource being ignored for a long time.

Originally posted by Kyrbi0Huh. Almost makes me wish I had a girlfriend, to take advantage of today (wait, no, that's not what I meant... I mean, take advantage of the fact that it is international women's day... gah, never mind).

Quote:

Originally posted by PyrogasmRome may not have been built in a day, but the Romans sure as hell didn't say "look at this great city we built guys!" when they had nothing more than a bit of stone and some cottages.