Must Have Campaign AI Programming Techniques


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

If you are programming a lot of custom code for the AIs and not using Blizzard's functions in, 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 file.
  1. First, extract the original Scripts\ from war3x.mpq
  2. Place it into your working directory and rename it to (or whatever you like)
  3. Now, you may edit the 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\
  7. Now, Warcraft III loads your custom 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 .\ .\
  7. This checks both your common code in and all your code in your for errors (where 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!