Tutorial 1: The Basics

Let's start with something simple. Imagine we are playing Protoss and we have only 1 probe left. A lost pylon somewhere saves us from defeat, for now. The first thing we need to do is build a new nexus. When it finishes we can start building our probes again. The following piece of code builds 1 nexus, waits for it to finish and then builds up to 4 probes.


build 1 nexus 150
wait_build 1 nexus
build 4 probe 130
wait_build 4 probe


The code above is pretty self explanatory, apart from the numbers 150 and 130. The number at the end of the build command indicates the priority at which the building (or probe/Scv/Drone) should be constructed. 150 and 130 are very high priorities. Normally 80 is used for a building.

Note: changing the priority becomes an issue when expanding. When an AI creates an expansion it tries to manage the expansion and the main base at the same time. It can, however, only perform one build action at a time. The next build action is chosen based on the priority. By lowering the priority of the build commands for an expansion to 60, you can make sure the build up in the main base is not slowed down. On the other hand, the nexus of the expansion needs a very high priority (e.g. 150), otherwise the expansion is postponed unnecessarily.

Now let's get back to our in-game situation. We now have 1 nexus and 4 probes. What we need are some more probes and a pylon.


build 5 probe 80
wait_buildstart 5 probe
build 6 probe 80
wait_buildstart 6 probe
build 1 pylon 80
wait_buildstart 1 pylon
build 7 probe 80
wait_buildstart 7 probe
build 8 probe 80
wait_buildstart 8 probe


The most important difference to our last piece of code is the use of the wait_buildstart command. In case of wait_build we had to wait until the building was finished. Now, we only have to wait until the construction is started. Then we proceed to the next command. Another thing that needs our attention is the amount of probes we build by using the build and wait_buildstart commands. When we state "build 5 probe 80" and "wait_buildstart 5 probe" we actually build probes until we are starting the construction of the 5th. This means that we don't build 5 extra probes.

Now that we have some probes and also have started to build a pylon, we can start thinking about offense/defense.


wait_build 1 pylon
build 1 gateway 80
wait_buildstart 1 gateway
build 2 pylon 80
wait_buildstart 2 pylon
wait_build 1 gateway
train 1 zealot
build 3 gateway 80
wait_build 3 gateway
train 4 zealot


In the code above we tell the AI to wait for at least one pylon to be finished. Then it builds a gateway and another pylon. When the gateway finishes construction we use the train command to tell the AI to start training the 1st zealot.

Note: when the AI is training a unit it can still proceed with the build order, provided there are enough resources. You should be cautious however about including too many train commands early on: it does slow down the build up. Also note that the AI performs better when small groups are trained at a time.

Let's presume we are dealing with a groundmap (i.e. the enemy is reachable without the use of an air transport). An airmap would need a different build up, we deal with such a case later on. On this groundmap we tell the AI to continue building gateways until it has a total of 3. Once the 3rd gateway finishes it should train zealots until it commands a total of 4. We now have enough zealots to hold off on early rush. Let's build some more probes and pylons.

Building pylons can be tiresome. Luckily SCAIEdit provides us with a command which lets the AI build pylons when needed:


farms_timing


Note: the command farms_timing lets the AI build pylons/overlords/supply depots automatically, but the AI generally builds them too early. This is not a problem later on, but at the start of the game the build order is crucial. That's why you should turn this option on only after the 2nd or 3rd (or even later) pylon/overlord/supply depot (i.e. farm).


build 9 probe 80
wait_buildstart 9 probe
build 10 probe 80
wait_buildstart 10 probe
build 1 assimilator 80
wait_buildstart 1 assimilator


Now we have a total of 10 probes and we also started to create an Assimilator. It's time to create a forge, or even better: 2 forges. Using 2 forges we can research up to 2 forge upgrades (ground attack/armor or shield) at the same time.


wait_build 1 pylon
build 2 forge 80
wait_buildstart 2 forge


Note: strictly speaking we don't really need the "wait_build 1 pylon" command here, because we already know we have already build one (needed to build the gateway). However, there is a good reason to include it: now you can change the order to first building the forges and then the gateways without having to change much. Personally, I prefer to create small pieces of code that will keep working when moved.

We continue by building an additional probe.


build 11 probe 80
wait_buildstart 11 probe


Now comes the part where we strike out at our opponent. Here we tell the AI to train 6 zealots and to attack:


:repeatrush

wait_build 1 gateway
train 6 zealot
attack_add 6 zealot
attack_prepare
attack_do
attack_clear

goto repeatrush


The attack part is rather easy. It always starts with the train command. Then we add the trained units to our attack group by using the attack_add command. We finish the attack part with the next set of commands: attack_prepare, attack_do and attack_clear. These three commands tell the AI to use the units we trained and attack the (or an, in case of multiple opponents) enemy.

The ":repeatrush" and "goto repeatrush" commands are a bit more advanced. These two commands together define a loop. The : is always followed by a unique identifier, in this case "repeatrush". It defines a location where we can jump to from anywhere in the script by using the goto command. In our example it is used to make the AI attack with 6 zealots over and over again. Our script is executed by the AI line by line, until it reaches the "goto repeatrush" statement. There it jumps back to ":repeatrush". It then continues to train another 6 zealots, attack and jumps back again to ":repeatrush". This continues until either the opponents are defeated or the AI is defeated.

Lets combine the previous pieces of code into our first script file "Protoss Expansion Custom Level.asc3":


; ASC3 File generated by ScAIEdit III
;
; Script name : Protoss Expansion Custom Level
;
; Protoss Basic Script - Created by [M_K]
;

script_name Protoss Expansion Custom Level
script_id PMCx

; === STARTUP COMMANDS ===
start_town
transports_off
farms_notiming

; === DEFINE MAX PER UNIT ===
define_max 100 probe
define_max 100 zealot
define_max 100 dragoon
define_max 100 reaver
define_max 100 scout
define_max 100 shuttle
define_max 100 carrier
define_max 100 observer
define_max 100 corsair
define_max 100 high_templar
define_max 100 dark_archon
define_max 100 archon
define_max 100 arbiter
define_max 100 dark_templar

; === START ===
build 1 nexus 150
wait_build 1 nexus
build 4 probe 130
wait_build 4 probe

build 5 probe 80
wait_buildstart 5 probe
build 6 probe 80
wait_buildstart 6 probe
build 1 pylon 80
wait_buildstart 1 pylon
build 7 probe 80
wait_buildstart 7 probe
build 8 probe 80
wait_buildstart 8 probe

wait_build 1 pylon
build 1 gateway 80
wait_buildstart 1 gateway
build 2 pylon 80
wait_buildstart 2 pylon
wait_build 1 gateway
train 1 zealot
build 3 gateway 80
wait_build 3 gateway
train 4 zealot

farms_timing

build 9 probe 80
wait_buildstart 9 probe
build 10 probe 80
wait_buildstart 10 probe
build 1 assimilator 80
wait_buildstart 1 assimilator

wait_build 1 pylon
build 2 forge 80
wait_buildstart 2 forge

build 11 probe 80
wait_buildstart 11 probe

:repeatrush

wait_build 1 gateway
train 6 zealot
attack_add 6 zealot
attack_prepare
attack_do
attack_clear

goto repeatrush


As you can see, using a ; at the start of a line we can add comments to our code. This improves readability a lot. Here is a brief explanation of some of the new commands:

  • script_name: the name of the script. Protoss Expansion Custom Level, Terran Expansion Custom Level or Zerg Expansion Custom Level for the standard build-in scripts.
  • script_id: the id of the script. PMCx, TMCx, ZMCx for the standard build-in scripts.
  • start_town: tells the AI to start a new base (i.e. town). Also used for expansions.
  • transports_off: used in case of a groundmap. If this is commented out, the AI starts with creating an assimilator asap (as it should in case of an airmap).
  • farms_notiming: turns the automatic farm (i.e. pylon/overlord/supply depot) building off.
  • define_max: defines the max amount of units per unit type the AI can build/train.

Here are some screens of the basic Protoss script in action:

Basic Protoss Buildup
Protoss buildup.

Basic zealot Attack
Protoss 6 zealot attack.

How to test the newly created script

This is explained in the SCAIEdit III help (section Testing new AI Scripts in StarCraft). You can also take a look at the site of kl10pa:
http://www.entropyzero.org/kl10pa.html. A very good Terran example script is also provided.

Just to make sure we can test the script, here are the steps I use to test my scripts:

  1. Compile the script file (i.e. Protoss Expansion Custom Level.asc3) using SCAIEdit III. Make sure there are no errors left.
  2. Close the script file and open the "aiscript.bin". You can use WinMPQ to extract the latest aiscript.bin from the latest "Patch_rt.mpq" file (note: if the extracted file is all caps, then rename it to "aiscript.bin" with no caps, otherwise SCAIEdit might have trouble reading it). There is also a "aiscript.bin" included with SCAIEdit III.
  3. Look for the "Protoss Expansion Custom Level". Remove it from the "aiscript.bin" file. Then import your own "Protoss Expansion Custom Level.asc3" file.
  4. Compile the "aiscript.bin" file. The message "Script compilation done!" should appear.
  5. Close the "aiscript.bin" file. Then make a backup of the "Patch_rt.mpq" file in your Starcraft directory. Now use WinMPQ to open the file. Then look for the file "scripts\aiscript.bin" or "scripts\AISCRIPT.BIN". Remove it and add your own aiscript.bin (also use "scripts\" as the path). Make sure that while doing this you have (1) a backup of the original "Patch_rt.mpq", (2) no other program open that also makes use of the "Patch_rt.mpq" file (e.g. Starcraft/Broodwar).
  6. Close WinMPQ. Start Broodwar and create a game against a Protoss AI.

On to the next page where we start researching upgrades.








Previous Back to Index Next