Must Have Campaign AI Programming Techniques

Hello!

I was writing a couple of AIs for a Warcraft III Campaign, and came up some very important techniques that have not been discussed in any of the tutorials I've seen.

1. Place your common AI code and globals to a custom common.ai

If you are programming a lot of custom code for the AIs and not using Blizzard's functions in common.ai, you may end up writing all the way the same code into many AI files. I came up with a good technique to avoid that. Instead of writing duplicate code, you should place all your common code into a custom common.ai file.
  1. First, extract the original Scripts\common.ai from war3x.mpq
  2. Place it into your working directory and rename it to common2.ai (or whatever you like)
  3. Now, you may edit the common2.ai file as much as you like
  4. Place your custom globals into the globals sections at the start of the file
  5. Place your custom functions at the end of the file
  6. Then, import it into your campaign and set its path to Scripts\common.ai
  7. Now, Warcraft III loads your custom common.ai instead of the original file, and you get to share your code across all AI files and across all maps in the campaign.
Very handy!

2. Check AI errors with PJASS

PJASS is an excellent tool to spot errors in your AI. When you are writing an AI, it is a tremendous help, if you can use it to spot all errors before importing your AI file to your map.
  1. Download pjass.exe from the above link. Be sure to get the latest version.
  2. Place pjass.exe into your working directory.
  3. Export common.j from war3x.mpq to your working directory.
  4. Place all your custom AI files into your working directory.
  5. Open Windows Powershell in your working directory (File Explorer -> File -> Open Windows PowerShell)
  6. Run .\pjass.exe .\common.j .\common2.ai .\custom.ai
  7. This checks both your common code in common2.ai and all your code in your custom.ai for errors (where custom.ai is the name of your custom ai file that you want to check for errors)
Great! No more starting Warcraft III to check if you made any syntax errors in your AI file!

Regards,
Tommi
 
Top