AI - Basics and Triggers

Tutorial By XXXconanXXX

Introduction

This tutorial shows a wide variety of orders and functions, controlling any unit with no control over a player.

Gettings unit to cast custom abilities

There are 3 ways to go about doing this. The first is using the basic GUI functions, and ordering the unit the order string of the spell. Depending on what type of spell your using, if your usin a no target ability like Locust Swarm, or a targetable ability like blink, then you would use one of the three actions, "Unit - Issue Order Targeting a Point", "Unit - Issue Order Targeting a Unit", "Unit - Issue Order With No Target". So for something like Locust Swarm, we would use the action "Issue Order With No Target; Order <Your Unit> to Undead Crypt Lord - Locust Swarm". For abilities like Frost Nova, we would use "Issue Order Targeting a Unit; Order <Your Unit> to Undead Lich - Frost Nova <Your other Unit>". The other way is to order your unit the Raw Code of the ability, by making a dummy trigger with your functions, and using the action "Issue Order Targeting" with any spell in it's place, then converting it to Custom Text. Then, you would go to the Object Editor, hit ctrl + D, find your spell, and copy that code, then paste it where it has the spell in your dummy trigger.

Lastly, you can go to the AI Editor (Module->AI Editor) and create a new dummy AI Script. Then, you can go to the Object Editor, go to File->Export all Object Data", and go back to the AI Editor. There, you go under Custom Data:" and add your Object Data. YOu can remove all checks, all waves, everything else, then go to File->Add to Map and then it will be in your Import Manager. Then, you can go to the Import Manager (Module->Import Manager) and remove the "AI Data". After that, in your Map Initlization rigger, add the action "Run Melee AI Script" and add your new script there. This will order each computer you have that you ran the script for, custom abilities.

Spawn and movement points

In a normal AoS style map, there are usually three spawn points for each team, and to move points in the corner for both. I have 4 triggers that handle this, checking which player entered, and has multiple events for each region. There is an alternaet, and could be done in ONE trigger. That, however, would lag pretty bad each time it spawned and moved. There are the triggers, for reference purposes:

Spawning Events Time - Every 60.00 seconds of game time Conditions Actions If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions (Execution count of (This trigger)) Equal to 1 Then - Actions Unit - Create 1 Child of the Sun for Player 6 (Orange) at (Center of Spawn 1 top <gen>) facing Default building facing (270.0) degrees Set AI_Heroes_Player6[1] = (Last created unit) Unit - Create 1 Child of the Sun for Player 6 (Orange) at (Center of Spawn 1 middle <gen>) facing Default building facing (270.0) degrees Set AI_Heroes_Player6[2] = (Last created unit) Unit - Create 1 Child of the Sun for Player 6 (Orange) at (Center of Spawn 1 bottom <gen>) facing Default building facing (270.0) degrees Set AI_Heroes_Player6[3] = (Last created unit) Unit - Create 1 Shadow Hunter for Player 6 (Orange) at (Center of Spawn 1 top <gen>) facing Default building facing (270.0) degrees Set AI_Heroes_Player6[4] = (Last created unit) Unit - Create 1 Shadow Hunter for Player 6 (Orange) at (Center of Spawn 1 middle <gen>) facing Default building facing (270.0) degrees Set AI_Heroes_Player6[5] = (Last created unit) Unit - Create 1 Shadow Hunter for Player 6 (Orange) at (Center of Spawn 1 bottom <gen>) facing Default building facing (270.0) degrees Set AI_Heroes_Player6[6] = (Last created unit) Else - Actions If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions (Execution count of (This trigger)) Equal to 1 Then - Actions Unit - Create 1 Death Knight for Player 12 (Brown) at (Center of Spawn 2 top <gen>) facing Default building facing (270.0) degrees Set AI_Heroes_Player12[1] = (Last created unit) Unit - Create 1 Death Knight for Player 12 (Brown) at (Center of Spawn 2 middle <gen>) facing Default building facing (270.0) degrees Set AI_Heroes_Player12[2] = (Last created unit) Unit - Create 1 Death Knight for Player 12 (Brown) at (Center of Spawn 2 bottom <gen>) facing Default building facing (270.0) degrees Set AI_Heroes_Player12[3] = (Last created unit) Unit - Create 1 Lich for Player 12 (Brown) at (Center of Spawn 2 top <gen>) facing Default building facing (270.0) degrees Set AI_Heroes_Player12[4] = (Last created unit) Unit - Create 1 Lich for Player 12 (Brown) at (Center of Spawn 2 middle <gen>) facing Default building facing (270.0) degrees Set AI_Heroes_Player12[5] = (Last created unit) Unit - Create 1 Lich for Player 12 (Brown) at (Center of Spawn 2 bottom <gen>) facing Default building facing (270.0) degrees Set AI_Heroes_Player12[6] = (Last created unit) Else - Actions -------- Team 1 spawn -------- Unit - Create 2 Spawn_Type[1] for Player 6 (Orange) at (Center of Spawn 1 top <gen>) facing Default building facing (270.0) degrees Unit - Create 2 Spawn_Type[1] for Player 6 (Orange) at (Center of Spawn 1 middle <gen>) facing Default building facing (270.0) degrees Unit - Create 2 Spawn_Type[1] for Player 6 (Orange) at (Center of Spawn 1 bottom <gen>) facing Default building facing (270.0) degrees Unit - Create 2 Rifleman for Player 6 (Orange) at (Center of Spawn 1 top <gen>) facing Default building facing (270.0) degrees Unit - Create 2 Rifleman for Player 6 (Orange) at (Center of Spawn 1 middle <gen>) facing Default building facing (270.0) degrees Unit - Create 2 Rifleman for Player 6 (Orange) at (Center of Spawn 1 bottom <gen>) facing Default building facing (270.0) degrees -------- Team 2 spawn -------- Unit - Create 2 Spawn_Type[2] for Player 12 (Brown) at (Center of Spawn 2 top <gen>) facing Default building facing (270.0) degrees Unit - Create 2 Spawn_Type[2] for Player 12 (Brown) at (Center of Spawn 2 middle <gen>) facing Default building facing (270.0) degrees Unit - Create 2 Spawn_Type[2] for Player 12 (Brown) at (Center of Spawn 2 bottom <gen>) facing Default building facing (270.0) degrees Unit - Create 2 Burning Archer for Player 12 (Brown) at (Center of Spawn 2 top <gen>) facing Default building facing (270.0) degrees Unit - Create 2 Burning Archer for Player 12 (Brown) at (Center of Spawn 2 middle <gen>) facing Default building facing (270.0) degrees Unit - Create 2 Burning Archer for Player 12 (Brown) at (Center of Spawn 2 bottom <gen>) facing Default building facing (270.0) degrees

Movement from spawn Events Unit - A unit enters Spawn 1 top <gen> Unit - A unit enters Spawn 1 middle <gen> Unit - A unit enters Spawn 1 bottom <gen> Unit - A unit enters Spawn 2 top <gen> Unit - A unit enters Spawn 2 middle <gen> Unit - A unit enters Spawn 2 bottom <gen> Conditions Or - Any (Conditions) are true Conditions (Owner of (Entering unit)) Equal to Player 6 (Orange) (Owner of (Entering unit)) Equal to Player 12 (Brown) Actions If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions (Owner of (Entering unit)) Equal to Player 6 (Orange) (Spawn 1 top <gen> contains (Entering unit)) Equal to True Then - Actions Unit - Order (Entering unit) to Attack-Move To (Center of Move top <gen>) Else - Actions If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions (Owner of (Entering unit)) Equal to Player 6 (Orange) (Spawn 1 middle <gen> contains (Entering unit)) Equal to True Then - Actions Unit - Order (Entering unit) to Attack-Move To (Center of Spawn 2 middle <gen>) Else - Actions If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions (Owner of (Entering unit)) Equal to Player 6 (Orange) (Spawn 1 bottom <gen> contains (Entering unit)) Equal to True Then - Actions Unit - Order (Entering unit) to Attack-Move To (Center of Move bottom <gen>) Else - Actions If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions (Owner of (Entering unit)) Equal to Player 12 (Brown) (Spawn 2 top <gen> contains (Entering unit)) Equal to True Then - Actions Unit - Order (Entering unit) to Attack-Move To (Center of Move top <gen>) Else - Actions If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions (Owner of (Entering unit)) Equal to Player 12 (Brown) (Spawn 2 middle <gen> contains (Entering unit)) Equal to True Then - Actions Unit - Order (Entering unit) to Attack-Move To (Center of Spawn 1 middle <gen>) Else - Actions If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions (Owner of (Entering unit)) Equal to Player 12 (Brown) (Spawn 2 bottom <gen> contains (Entering unit)) Equal to True Then - Actions Unit - Order (Entering unit) to Attack-Move To (Center of Move bottom <gen>) Else - Actions

Movement from top corner Events Unit - A unit enters Move top <gen> Conditions Or - Any (Conditions) are true Conditions (Owner of (Entering unit)) Equal to Player 6 (Orange) (Owner of (Entering unit)) Equal to Player 12 (Brown) Actions If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions (Owner of (Entering unit)) Equal to Player 6 (Orange) Then - Actions Unit - Order (Entering unit) to Attack-Move To (Center of Spawn 2 top <gen>) Else - Actions If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions (Owner of (Entering unit)) Equal to Player 12 (Brown) Then - Actions Unit - Order (Entering unit) to Attack-Move To (Center of Spawn 1 top <gen>) Else - Actions

Movement from bottom corner Events Unit - A unit enters Move bottom <gen> Conditions Actions If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions (Owner of (Entering unit)) Equal to Player 6 (Orange) Then - Actions Unit Group - Pick every unit in (Units in Move bottom <gen>) and do (Unit - Order (Picked unit) to Attack-Move To (Center of Spawn 2 bottom <gen>)) Else - Actions If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions (Owner of (Entering unit)) Equal to Player 12 (Brown) Then - Actions Unit - Order (Entering unit) to Attack-Move To (Center of Spawn 1 bottom <gen>) Else - Actions

Dummy Units

Dummy units are what they are called, dummy units. THey are used to attack things, cast spells, or anything else without being seen. You can make a dummy unit by making any new unit. Then, change the shadow to NONE, change model file to "Tree of life upgrade ability", No attack, no movement (This depends on if you want your unit to move), and with the abilities "Invulnerable" and "Locust". Then, in the trigger you want to create and order them, you would use the action "Create 1 dummy unit for <Whoever>". Then, in only the next action, you can reference them with the "(Last Created Unit)" function. You can also place them in a variable, and use them for later.

Channel Spell

Channel is a great spell all around, and can be used for many different reasons. Learn about it here

Melee AI

Melee AI is the AI used by the computer players in any Melee game. Melee AI, or often referred to as "Normal AI" can be made in the AI Editor, as the AI Editor was specifically made for Melee AI.

You can also find an advanced user made version of the Melee AI at http://amai.wc3campaigns.com

Campaign AI

Campaign AI, is usually AI that is made for campaigns, and is also custom AI which is made through JASS. All the AI files for Warcraft III can be found in the .MPQ in the Warcraft III Directory. The Blizzard campaign AI is made using only the native functions of JASS. Extract the AIs from the .MPQ, and also Blizzard.j and Common.j to see all those functions, and how they did it.

WARNING: DO NOT PUT THE BLIZZARD.J AND COMMAN.J FILES IN YOUR WARCRAFT III DIRECTORY AS THEY WILL SCREW UP WORLD EDITOR AND YOU WILL NOT BE ABLE TO SAVE ANY CUSTOM MAP!

Click here to comment on this tutorial.
 
 
Blizzard Entertainment, Inc.
Silkroad Online Forums
Team Griffonrawl Trains Muay Thai and MMA fighters in Ohio.
Apex Steel Pipe - Buys and sells Steel Pipe.