SCRMaps
/
Sign in

Writing your own AI script

Attacking with the composition you want, when you want it, means replacing aiscript.bin itself.

9 min read

Choosing from the stock list runs out quickly. If you want a Zerg computer to come with Zerglings and Mutalisks, or to attack at exactly seven minutes with a particular composition, nothing on the list does it.

AI scripts live in aiscript.bin and bwscript.bin inside StarCraft. Replace aiscript.bin with a file containing your own and they appear in the Run AI Script list - the same principle as FileManager substituting a tbl.

  1. 1Open aiscript.bin in PyAI, part of PyMS. It needs Python 2.7 and PIL.
  2. 2Open Default Scripts to read the stock ones - not to edit them, but to see how they are written.
  3. 3Write your script, save, and put that bin into the map.

The folder you unpack PyMS into must not have a Korean name. And workers count as buildings in these opcodes - miss that and any command that counts units is off.

The opcodes fall into seven groups: header, build and attack and defend, flow control, multi-thread, miscellaneous, StarEdit, and the unused ones. All 113 are on the reference page.

Some descriptions on the reference page carry a ⚠. Those are where a reader corrected the original article - most notably wait_train, which despite its name and description does not train a unit.

Before that: a good share of the usual complaints about the computer can be fixed by helping it with triggers rather than touching the script at all. Four that are actually used.

Helping the AI with triggers
Keeping Medics with MarinesIf there is no Marine inside the Medic's location, order the Medic to the Marine location. It has no side effects at all - the kind of thing people say should have shipped with the game.
Workers defending an expansionAttach a location to the Command Center and order the nearby SCVs to attack when enemies inside it pass a threshold. It reliably stops the base being gutted while the workers keep mining.
Hit and runCompare friendly and enemy counts inside a wide location and pull back when losing. Leave strategic units like Dark Templar out of the count. The flaw is that it judges on bodies, so it sometimes retreats from a fight it would have won.
Vulture controlAttach a location the size of the Vulture's range and patrol it back toward the base when an enemy enters. The flaw is that an upgraded Vulture simply outruns the control.

All four are the same shape: attach a location to a unit, look at what is inside it, give one order. That is far cheaper than rewriting the intelligence and there is nothing to break. Save the script edit for what this cannot do - the production composition and the timing.

All 113 AI opcodes