SCRMaps
/
Sign in

AI scripts

What Run AI Script can run, and the 113 opcodes for writing your own.

Explained in: Writing your own AI script

An AI script decides what a computer player does. Running a stock one comes first; writing your own is what you do when none of them fit.

What Run AI Script can run
AI Harass HereThe computer attacks the current location noticeably more often. It is the script Brood War Terran mission 6 used to make the Zerg hit the warp gate more often. It appears to set where the computer concentrates when it has several targets (enemy players) to choose from.
AI Nuke HereMakes the computer's Ghost fire one nuke at that location. It of course needs a Ghost and a loaded Nuclear Silo (or the ability to build a nuke).
(race) (number) - (whatever)The AIs used in the original campaign. “Protoss 1 - Zerg Town” means the enemy Zerg AI used in original Protoss mission 1. There are far too many to list, so read the scripts themselves with PyAI. The computer's main base needs a location on it.
Broodwar (race) (number) - Town (letter)The AIs used in the Brood War campaign. “Broodwar Protoss 1 - Town A” does not mean a Protoss AI: it means one of the enemy AIs used in Brood War Protoss mission 1, which is a Zerg AI. There are far too many to list, so read the scripts themselves with PyAI. The computer's main base needs a location on it.
Cast Disruption WebThe computer's Corsair casts Disruption Web at that location. A hero Corsair (Raszagal) will not, the tech must be researched, and it needs the energy. Famously used in Brood War Protoss mission 3. In TEP the script is called Disruption Web Here.
Cast Recall (Arbiter required)The computer's Arbiter Recalls to that location. A hero Arbiter (Danimoth) will not, the tech must be researched, and it needs the energy. Recalling to several points at once needs that many Arbiters. Used as a Recall effect in several missions, Brood War Terran 5 among them. In TEP the script is called Recall Here.
Clear Previous Combat DataClears the combat data for that location so the AI can rebuild there. When part of an AI base is attacked and judged badly destroyed, the area is dropped from the AI's town - which is why an AI that otherwise rebuilds will leave that patch empty. This script makes the location usable for rebuilding again. It does not fix a failure to rebuild that has some other cause.
Enter Closest BunkerSends the computer units at that location into the nearest Bunker.
Enter TransportLoads the units at that location into the nearest Bunker or transport. Careful with computer units: unless you give them another order or give them away the moment they board, they unload themselves straight away.
Exit TransportUnloads the units inside a Bunker or transport at that location onto that location.
(Expansion) (race) Campaign (Area Town/Difficult/Easy/Insane/Medium/Custom Level)Runs the standard computer AI. The computer's race and the AI's race have to match. Without Expansion it uses original units only. The computer's main base needs a location on it. Area Town: mines only. Easy / Medium / Difficult: difficulty. Insane: the computer is fed resources periodically and expands. Custom Level: the computer AI from an ordinary melee game.
Make These Units PatrolMakes the computer units at that location patrol to the top-left of the map (the default). The patrol point can be set with the Set Generic Command Target script. Used somewhere in the campaign, perhaps - it is hard to see why it exists.
Move Dark Templars to RegionThe script used in original Zerg mission 6 (stopping the Dark Templar running). Every computer Dark Templar and Dark Templar hero attacks towards that location. (Zeratul does not move.) Unlike the Order action's Attack, they engage on contact.
Send All Units on Random Suicide MissionsEvery computer unit hunts for the enemy until the enemy is wiped out, attacking everything it sees. Workers join in, and spellcasters and Lurkers will target things they cannot actually attack (a Lurker picking an Observer, say - it walks over and stands there). The AI most used in survival maps. It needs no location and applies to every unit on the map. Units tend to stay on the target they picked even while being attacked, and with several enemy players there is always a force sent at each one: with human players 1-3 and a single building owned by player 3, some computer units will set out for that one building.
Send All Units on Strategic Suicide MissionsEvery computer unit attacks the enemy with strategic movement until the enemy is wiped out. They do not set off the instant the trigger fires - they wait a while first. It needs no location and applies to every unit on the map.
Set Generic Command TargetSets that location as the patrol point for Make These Units Patrol.
Set Player To Ally/Enemy hereThe script used for ally and enemy relations before the Set Alliance Status action existed. It is no longer used and no longer works. Set Player To Ally here is not even registered properly in TEP.
Set Unit Order To: Junk Yard DogKnown as junkyard dog. The computer units inside that location are given attack orders to random points on the map - you can watch them wander the whole map at will.
Switch Computer Player To Rescue PassiveThe script used in Brood War Terran mission 7 (the RPG-style mission where Stukov is killed by Duran). It changes the current computer player to Rescuable.
Turn OFF/ON Shared Vision of Player (number) with current playerTurns vision on or off. “Turn On Shared Vision of Player 2 with current player” means player 2's vision is turned on for the current player.
Value This Area HigherThe computer treats the current location as more important and posts defenders there. Used to make the Protoss hold the warp gate in Brood War Terran mission 6, and in plenty of other missions.

The opcodes for writing one yourself. Remember that workers count as buildings here.

AI opcodes
capt_expand()header · Lets the AI expand using the default expansion block. Nobody has published what that block contains. - Overlords and Observers scout more widely and defending units keep moving. - Vultures lay Spider Mines more widely and more sensibly, including defensively inside their own base. - defenseuse_ga and defensebuild_ga only run when this is present. - It attacks neutral critters.
check_transports()header · The AI builds and manages transports. With start_campaign() running it uses 2; otherwise up to 5. The first is built at priority 80 and the rest at 50. Protoss builds 2 Observers at priority 80.
default_min(byte)header · Sets how large a defending force is posted at an expansion. The higher the byte the more defenders; at 0 reinforcements are sent only when the expansion is attacked.
defaultbuild_off()header · Turns defaultbuild off. default_build is on by default.
default_build()header · Once the AI holds more than 600 minerals and 300 gas it trains the units below up to the define_max figure, and tends not to attack while doing it. Terran: Marine, Ghost, Siege Tank, Goliath, Wraith, Battlecruiser. Zerg: Hydralisk, Mutalisk. Protoss: Zealot, Dragoon, Reaver, Scout, Carrier.
define_max(byte, unit)header · Caps that unit at byte of them. At 255 the AI never makes it at all.
farms_notiming()header · Only builds supply units or buildings once supply is actually full.
farms_timing()header · Builds supply units or buildings ahead of supply filling up.
start_areatown()header · Starts a town AI that sees only the units and buildings inside the location. Requires start_campaign.
start_campaign()header · Starts the campaign-only AI. Its behaviour differs slightly from start_town used alone.
start_town()header · Starts a town AI centred on the location. - The AI does not go to an ally's aid (another script can cover that). - Overlords and Observers scout a wider ring around the base than the ordinary AI does. - It builds up to 3 transports. - It rebuilds pre-placed units that die, 3 or 4 times. - It builds up to 2 Observers. - It does not attack neutral critters. - And so on.
transports_off()header · The AI neither builds nor manages transports.
attack_add(byte, military)build / attack / defend · Adds byte of that military unit to the current attack force. byte tops out at 62.
attack_clear()build / attack / defend · Clears the current attack force.
attack_do()build / attack / defend · Sends the current attack force at the enemy.
attack_prepare()build / attack / defend · Readies the current attack force.
build(byte1, building, byte2)build / attack / defend · Builds that building or worker up to byte1 of them at priority byte2. byte1 tops out at 30.
build_bunkers()build / attack / defend · Builds 3 Bunkers around the base. (Terran only.)
build_turrets()build / attack / defend · Builds 6 Missile Turrets around the base. (Terran only.)
create_nuke()build / attack / defend · Produces one Nuclear Missile instantly, with no build time. It is said to require start_campaign; it does not, and works fine without it. Computer players only.
creep(flag)build / attack / defend · Sets how tightly buildings are packed. At flag 0 they go up close together, at 4 well spread out. It was normally used to set the spacing of Zerg Sunken and Spore Colonies.
defensebuild_aa(byte, military)build / attack / defend · Builds byte of that military unit as air-to-air defence (e.g. what to train when Devourers come). *For the defensebuild and defenseuse families, writing 1 for byte is enough - the AI builds and uses plenty on its own.
defensebuild_ag(byte, military)build / attack / defend · Builds byte of that military unit as air-to-ground defence.
defensebuild_ga(byte, military)build / attack / defend · Builds byte of that military unit as ground-to-air defence. Requires capt_expand.
defensebuild_gg(byte, military)build / attack / defend · Builds byte of that military unit as ground-to-ground defence.
defenseclear_aa()build / attack / defend · Clears air-to-air defensive production.
defenseclear_ag()build / attack / defend · Clears air-to-ground defensive production.
defenseclear_ga()build / attack / defend · Clears ground-to-air defensive production.
defenseclear_gg()build / attack / defend · Clears ground-to-ground defensive production.
defenseuse_aa(byte, military)build / attack / defend · Uses byte of that military unit as air-to-air defence.
defenseuse_ag(byte, military)build / attack / defend · Uses byte of that military unit as air-to-ground defence.
defenseuse_ga(byte, military)build / attack / defend · Uses byte of that military unit as ground-to-air defence. This one requires capt_expand.
defenseuse_gg(byte, military)build / attack / defend · Uses byte of that military unit as ground-to-ground defence.
do_morph(byte, military)build / attack / defend · Produces one of that military unit whenever there are fewer than byte of them.
easy_attack(byte, unit)build / attack / defend · Sends byte of that unit at the enemy without attack_add, attack_prepare or attack_do.
fake_nuke()build / attack / defend · Resets nuke_rate to 0.
get_oldpeons(byte)build / attack / defend · Sends byte workers to the expansion.
guard_all()build / attack / defend · Uses every unit to defend the base. Normally only part of the army responds to an attack; with this, all of it comes running.
guard_resources(military)build / attack / defend · Posts one of that military unit at an empty expansion site as a scout.
help_iftrouble()build / attack / defend · Comes to an allied player's aid when they are attacked.
nuke_rate(byte)build / attack / defend · Limits the AI to building and firing one nuke every byte minutes.
max_force(word)build / attack / defend · Changes the size of the defending force according to word. Rarely used; ignore it.
place_guard(unit, byte)build / attack / defend · Posts one of that unit at position byte. In the campaign this was typically a Queen or Defiler, sitting in the base and coming out to Ensnare or Spawn Broodling. 0 = base centre, 1 = mineral line, 2 = gas.
player_need(byte, building)build / attack / defend · If the AI does not own byte of that building or worker, it builds or trains them at priority 80. This applies across every town, not just one. byte tops out at 30.
prep_down(byte1, byte2, military)build / attack / defend · Adds every one of that military unit it owns to the attack force except byte1 of them - but always sends at least byte2.
quick_attack()build / attack / defend · Sends the current attack force at the enemy without attack_prepare.
send_suicide(byte)build / attack / defend · Runs Send All Units on Random/Strategic Suicide Missions. byte 0 is Strategic, 1 is Random.
tech(tech, byte)build / attack / defend · Researches that tech at priority byte.
train(byte, military)build / attack / defend · Trains that military unit up to byte of them.
upgrade(byte1, upgrade, byte2)build / attack / defend · Researches that upgrade up to level byte1 at priority byte2. byte1 tops out at 31.
wait(word)build / attack / defend · Waits word frames. (wait(1) = 0.042 real seconds at Fastest.)
wait_build(byte, building)build / attack / defend · Waits until the AI owns byte of that building or worker.
wait_bunkers()build / attack / defend · Waits for build_bunkers to finish.
wait_buildstart(byte, building)build / attack / defend · Waits until the AI has started byte of that building or worker.
wait_finishattack()build / attack / defend · Waits until the current attack force has finished attacking.
wait_force(byte, unit)build / attack / defend · Trains and waits until the AI owns byte of that unit.
wait_train(byte, military)build / attack / defend · Trains and waits until the AI owns byte of that military unit. ⚠ A reader's correction says that, contrary to the source, it does not actually train them.
wait_turrets()build / attack / defend · Waits for build_turrets to finish.
wait_upgrades()build / attack / defend · Waits for every upgrade and tech research to finish.
call(block)flow control · Calls that block as a subroutine. Only one call is possible per game across all AIs: if player 1's AI calls and then player 2's does, player 2 overrides player 1 and takes control of the return. Do not put wait or any blocking opcode inside the block. If you do not know what it is for, leave it alone.
enemyowns_jump(unit, block)flow control · Jumps to that block if the enemy owns that unit.
enemyresources_jump(word1, word2, block)flow control · Jumps to that block if the enemy holds at least word1 minerals and word2 gas.
goto(block)flow control · Jumps to that block.
groundmap_jump(block)flow control · Jumps to that block on a ground map (that is, not an island map) - specifically, if there is any reachable enemy building.
if_owned(unit, block)flow control · Jumps to that block if the AI owns that unit, including one in production. The target block appears to have to sit below this line to work properly.
notowns_jump(unit, block)flow control · Jumps to that block if the AI does not own that unit.
nuke_pos(word1, word2)flow control · Requires start_campaign. Fires a nuke at the coordinate (word1, word2).
race_jump(block1, block2, block3)flow control · Jumps to block1 if the enemy is Terran, block2 if Zerg, block3 if Protoss.
random_jump(byte, block)flow control · Jumps to that block with probability byte/256.
region_size(byte, block)flow control · Jumps to that block when the AI's region falls below byte tiles. Not properly tested.
resources_jump(word1, word2, block)flow control · Jumps to that block if the AI holds at least word1 minerals and word2 gas.
return()flow control · Returns to where call was executing.
rush(byte, block)flow control · Jumps to that block depending on condition byte. Needlessly complicated and hard to use - Blizzard abandoned it, so treat it as not existing.
stop()flow control · Stops the current code. Normally used to stop a block.
time_jump(byte, block)flow control · Jumps to that block once byte minutes of normal time have passed.
try_townpoint(byte, block)flow control · Jumps to that block if the AI holds byte or more expansions.
expand(byte, block)multithread · Builds expansion number byte using that block.
multirun(block)multithread · Runs that block. Being a multithread opcode it runs alongside the script already executing, which makes it very useful.
killable()multithread · Makes the current thread killable.
kill_thread()multithread · Kills every thread in the killable state - including other players' threads. Best avoided.
panic(block)multithread · If the AI has not yet built an expansion and has fewer than 7,500 unmined minerals, it expands using that block. If it has expanded before, it checks each time whether unmined minerals are below 7,500 or 2 or fewer gas geysers remain unexhausted.
allies_watch(byte, block)multithread · Expands at point byte using that block. The points are the ones SCMDraft shows under Overlay Settings → AI Town Locations. At byte 8 or below it expands at that numbered player's start location; if the point is already taken it does nothing. byte tops out at 250.
create_unit(unit, word1, word2)other · Creates one of that unit at (word1, word2). Requires start_campaign.
debug(block, string)other · Prints that debug string and jumps to the block. It looks as though the AI is typing in chat.
fatal_error()other · Shuts StarCraft down with the message “Illegal AI script executed.” (!)
give_money()other · Grants 2,000 minerals and 2,000 gas every time both drop below 500.
set_randomseed(dword)other · Sets the random seed to dword. It affects every random value in the game.
clear_combatdata()StarEdit · Clears the combat data for the AI town at that location so the area can be rebuilt and used again.
disruption_web()StarEdit · Makes the computer's Corsair cast Disruption Web at that location.
enter_bunker()StarEdit · Sends the computer units at that location into the nearest Bunker.
enter_transport()StarEdit · Loads the units at that location into the nearest Bunker or transport.
exit_transport()StarEdit · Unloads every unit inside a Bunker or transport at that location.
harass_location()StarEdit · Makes the AI attack that location noticeably more often.
junkyard_dog()StarEdit · Gives the computer units inside that location an attack order to a random point on the map.
make_patrol()StarEdit · Makes the units at that location patrol to the top-left of the map (the default). If a Generic Command Target has been set, they patrol there instead.
move_dt()StarEdit · Sends the computer's ordinary and hero Dark Templar to attack around that location.
nuke_location()StarEdit · Makes the AI fire a nuke at that location.
player_ally()StarEdit · Allies with the players who own the units inside that location.
player_enemy()StarEdit · Sets the players who own the units inside that location as enemies.
recall_location()StarEdit · Makes the computer's Arbiter Recall to that location.
sharedvision_off(player)StarEdit · Makes that player turn shared vision off for the current player.
sharedvision_on(player)StarEdit · Makes that player turn shared vision on for the current player.
switch_rescue()StarEdit · Changes the current AI player to Rescuable.
value_area()StarEdit · Makes the AI treat the current location as more important and post defenders there.
eval_harass(block)unused / unknown · When the AI's base is attacked it evaluates some unknown condition and jumps to that block. It compares something against the enemy's attack force.
harass_factor(word)unused / unknown · Something to do with the size of a force in one region.
if_dif(byte1, byte2, block)unused / unknown · Compares byte2 against some internal value and jumps to that block on the result. (byte1: 0 = greater than, 1 = less than.)
if_towns()unused / unknown · An opcode that does not exist in memory.
implode()unused / unknown · Unknown.
scout_with(military)unused / unknown · Has no effect.
set_attacks(byte)unused / unknown · Does nothing by itself. It runs some command depending on byte, and nothing detailed is known.
target_expansion()unused / unknown · Requires start_campaign. It was always used alongside set_attacks, and is assumed to carry out an attack under set_attacks' conditions. Nothing detailed is known.
wait_secure()unused / unknown · Unknown.

Where a reader corrected the original article, the row carries a ⚠. In particular wait_train does not train a unit, contrary to its description.