Building an AI

Tutorial for Generals Gen

Avatar of Calamity_Jones

Calamity_Jones

Category: Code
Level: Expert
Created: Wednesday July 29, 2009 - 7:24
Updated: Sunday October 11, 2009 - 8:10
Views: 2731
Summary: A step by step guide to building an AI for your mod.
Rating
  • Staff-
  • Members-
  • Average-

0 votes

Page 1 2 3 4 5 6 7 8
I've found that a lot of mods for ZH and Generals don't have an AI due to the difficulty in finding people who are capable of making an AI, and willing to do so. It's time consuming, dull, frustrating and difficult, so you can see why :p I'm making an AI for the All Stars mod, and whilst I do it, I'll add parts to this post, showing the process of building the AI bit by bit.

Another note is that THIS IS NOT EASY. You cannot simply copy another AI to make it work for your mod. You NEED to play around with scripts until you have a good understanding of the basics. If you have never used worldbuilder before, close this webpage. Read this tutorial and go make a few maps. Once you know how wb works and feel comfortable, make a plain map, add a player, and mess around with scripts... try to make some units spawn, move the camera, things like that.


####Part 1####

This first part describes a few ideas and things like that. Stuff you'll need to know if you're building an AI. Firstly, we'll look at the files that are required:

-AIData.INI ... everyone seems to thing this is the AI and nothing else... actually it just tells the AI where to build, what to build and what generals powers to use as well as a few other tidbits of information.)

-SkirmishScripts.scb ... THIS is the AI, once you have scripted your AI, you need to export your scripts to a file with this name and place it in Data.

-Trigger areas and waypoints on every map ... These tell the AI where to go basically.

Now, by far the most difficult bit of AI making is the scripts as you need a pretty damn good grip on how to script to make an AI. I'll only focus on the scripts as that's the bit people need help with. There are many ways to make an AI, this is just how I did it.

1) Script General Knowledge

A script is a small chunk of Boolean algebra that tells to computer to carry out an operation once a certain condition has been met. You could make it do something like "IF (my enemy has 3 tanks) THEN (build 5 rocket soldiers)" Simple huh? Scripts have several variants that are simply made by checking tickboxes:

-Subroutines are scripts that are assigned to teams and are executed when the team reaches a condition and the script reaches its condition.

-Active scripts will check their conditions constantly until they are met, then execute and either shut off or continue executing. Therefore an inactive script will do nothing at all even if its conditions are met untill it's activated by another script.

-Deactivate on success makes the script turn off once it has met its condition and executed. If you deselect this, the script will keep executing until its condition isn't met anymore. These kind of scripts are the stuff for build conditions.

-Evaluation, this determines how often the computer checks to see if a scripts conditions have been met. The default is every frame, but can be changed for every n seconds.

-A sequential script is the same as any other script, except that another script tells the computer to run the script sequentially. This means it will execute the first action, then the second, then the thrid etc one after the other until the end or forever if you so wish.

In the example above, the script that says "IF (my enemy has 3 tanks) THEN (build 5 rocket soldiers)" would be a deactivating subroutine as it would check all the time to see if the enemy has three tanks, and as soon as it does, it would tell the AI to build a team of 5 rocket soldiers then switch off.

2) Team General Knowledge

A team is a group of units that the AI builds to attack you with, they can be assigned a huge plethora of scripts and conditions that alter them in certain ways. I'll take you through the various panels of a teams window. First, the Identity window:

-You need to select the unit types in this window, and the AI will make a random number of the selected units (if it can) between the minimum and maximum numbers set. Naturally, if you set the same number for min and max, it'll produce the same numbers every time.

-The priority of a team tells the AI how important a team is to it to be built, the success and failiure amounts are what the teams priority is reduced or increased by. A script needs to do this as the AI needs to know what is counted as success and failiure!

-The production condition is what determines wether the AI should build a team, these and all scripts that a team runs must be subroutines.

-The execute associated actions checkbox tells the AI to run the scripts on the generic tab.

Now the Reinforcement one:

-If you write a script that tells the computer to spawn a team somewhere, you can tell it to drop them off in a transport vehicle.

The Behaviour tab:

-This tab runs scripts when a condition is met by the team as well as setting their attitude.

Generic:

-These scripts will only run if the "execute associated actions" checkbox is ticked on identity.

For example, the 5 rocket soldiers would be a team of, say min:5, max: 5 AmericaInfantryMissileDefender. the script that says "IF (my enemy has 3 tanks) THEN (build 5 rocket soldiers)" would be the production condition. You would then set a priority script to run on the generic tab which would tell the AI to look for tanks, and instructions to hunt or something along them lines on the "on create" line in behaviour.

Return to top