AI - Basics and Triggers

Discussion in 'Tutorial Repository' started by XXXconanXXX, Apr 4, 2005.

  1. XXXconanXXX

    XXXconanXXX Cocktails anyone?

    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:

    Code:
    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
    
    Code:
    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
    
    Code:
    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
    
    Code:
    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!
  2. AceHart

    AceHart Your Friendly Neighborhood Admin

    Reading this in Dummy Mode, I came up with this quick writeup of Things that aren't clear:



    > The first is using the basic GUI functions,

    The second also.


    > and ordering the unit the order string of the spell.

    What's an order string?
    I usually just click on a button in game.


    > Depending on what type of spell your using, if your usin a no target ability like Locust Swarm,

    Well, I don't know for you, but my locusts seem to have no problems with finding their 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>".

    This is nice. Unfortunately, my custom ability "Flying Sheep From Outer Hell", my current Pet Hero's ultimate,
    is not in that list.
    How do I get it there?


    > The other way is to order your unit the Raw Code of the ability, by making a dummy trigger with your functions,

    Raw Code? What code, and why raw?
    But, more importantly, what's a dummy trigger?
    A trigger that never runs? Something I'm not going to use anyway? Do I need one?


    > and using the action "Issue Order Targeting" with any spell in it's place, then converting it to Custom Text.

    So, this is really the same as version 1 from up, or isn't it?

    > 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.

    This "method two" is really only "Coolness through Obscurity".

    But, if I paste something in... you said up there there's three different orders... how can this do for all cases?


    > Lastly, you can go to the AI Editor (Module->AI Editor) and create a new dummy AI Script.

    Same here, what's a dummy AI script? One that isn't used? That doesn't do anything? The one to really beat up?


    > 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.

    Actually, if you're going for "Menu: File / Add to map", there's no need to export / import anything.
    It's all automagic, in one click.


    > Then, you can go to the Import Manager (Module->Import Manager) and remove the "AI Data".

    But, if I remove the script, what do I run later on?


    > After that, in your Map Initlization rigger, add the action "Run Melee AI Script" and add your new script there.

    Wait, there is no script anymore, since I removed it... (see above).


    > This will order each computer you have that you ran the script for, custom abilities.

    Ehm... what?


    > In a normal AoS style map,

    I really only like RPG maps, they are much cooler :)


    > there are usually three spawn points for each team,

    Really? If that's any true, they all copied from each other.
    (Well, let me add here that I never played any Aos or DotA or Footmen map...)


    > and to move points in the corner for both.

    Hm...?


    > I have 4 triggers that handle this, checking which player entered, and has multiple events for each region.

    Which "player" entered? I thought "spawns" were for Creeps.


    > Dummy units are what they are called, dummy units.

    You don't say.


    > THey are used to attack things, cast spells, or anything else without being seen.

    Oh, I see. So, basically, my custom Sorceress with "invisibility" is, actually, a dummy unit?


    > You can make a dummy unit by making any new unit.

    Can I use a Dark Ranger?


    > Then, change the shadow to NONE, change model file to "Tree of life upgrade ability",

    Now, this is something...
    I strongly suggest to set the model to "NONE".

    This is too much in the "I tried and failed, but, somehow found something that seems not to crash the game" - category.
    (That's just me, obviously, you may ignore this)

    > No attack, no movement (This depends on if you want your unit to move), and with the abilities "Invulnerable" and "Locust".

    Do you really need those? On a unit that can't be seen anyway?

    > 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.

    Ok. Why only in the next action? Can't I use two or more?


    > You can also place them in a variable, and use them for later.

    And, if I don't? Will they clutter up the map and lag it to hell and back?
    Dunno, just asking.


    > Melee AI is the AI used by the computer players in any Melee game.

    Actually, is it somewhat clear what AI stands for? Does it stay for something? Did Blizzard invent it?


    > 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.

    :)


    > Campaign AI, is usually AI that is made for campaigns,

    Yes... terrific.


    > and is also custom AI which is made through JASS.

    Ah, yes? So I can't make an AI just for my campaign, since I don't know JASS?
    Damn, and there I thought this AI Editor could do that... what with the imported custom abilities and such... :(


    > 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.

    So be 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!

    "screw up" is a bit like "It doesn't work", only worse...




    The ususal disclaimer applies here.
    Nothing personal, I don't care who's hot or cold or needs a shower...


    Yours
    AceHart
  3. gunngarothar

    gunngarothar Guest

    XXconanXXX,
    thank you for taking the time to post the tutorial. i've been trying to figure out a good trigger system for the movement (code 3 & 4) that you posted for a long time that didn't have bugs. but, when I tried to use the trigger codes you posted (code 3 & 4), it didn't work. for one team, the trigger would work fine, but for the other, they would get to the region, turn around, and then go to where the other team was ordered to go. whichever team had its part of the trigger come first would be the guys who would turn around. any suggestions?
  4. The Helper

    The Helper Administrator Staff Member

  5. Marksman

    Marksman Guest

    Ok, i know it can be done, but I'm having trouble actually doing it.

    What I want to do is make creep waves that do not belong to a player. I already have 12 players on my map who will each get a hero. I want creeps to spawn that are neutral, but allied with one team, but attack the other teams. Does anybody know how to do this?

    Random thought- if you made then spawn neutral hostile but made each team a particular unit type (Tauren, Ancient, Commoner etc.) and made it so the spawns for that team could not legally attack those targets, would the waves work like they should (easier way preferable) ??
  6. Im_On_56k

    Im_On_56k Hm...

  7. Marksman

    Marksman Guest

    yeah, yeah, ok, i just figured since this was the AI thread other people would want to know how to do it, and this is where they would look.
  8. dremmuel

    dremmuel Guest

    XXconanXXX,

    You said:
    What code do you mean to copy from the Object Editor and where should it be placed in the trigger? The trigger I am looking at is:

    Code:
    function Trig_Naga_Abilities_Func001C takes nothing returns boolean
        if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'nnrg' ) ) then
            return false
        endif
        return true
    endfunction
    
    function Trig_Naga_Abilities_Actions takes nothing returns nothing
        if ( Trig_Naga_Abilities_Func001C() ) then
            call IssueTargetOrderBJ( GetTriggerUnit(), "thunderbolt", GetAttacker() )
        else
        endif
    endfunction
    
    //===========================================================================
    function InitTrig_Naga_Abilities takes nothing returns nothing
        set gg_trg_Naga_Abilities = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ( gg_trg_Naga_Abilities, EVENT_PLAYER_UNIT_ATTACKED )
        call TriggerAddAction( gg_trg_Naga_Abilities, function Trig_Naga_Abilities_Actions )
    endfunction
    
    It seems that the address of the ability is not used anywhere, only the order string. How then does the function know which ability to use if multiple abilities use the same order string?

    Thanks for your help.

    dremmuel
  9. phyrex1an

    phyrex1an Staff Member and irregular helper Staff Member

    It doesn't know that, it orders the unit to perform the order. The order will only be executed if the unit has an ability that can be used with that order.
    If the unit has more than 1 ability that uses that order then the unit will use one of them, but you can't specify which.
  10. AceHart

    AceHart Your Friendly Neighborhood Admin

    > How then does the function know which ability to use if multiple abilities use the same order string?

    Well, you can't put two abilities with the same base ability on one unit.
    So, there is no confusion.


    Your trigger, btw, waits for a Naga Royal Guard to be under attack, and, if yes, orders it to "thunder bolt" the attacker.
    No ability ID involved there.
  11. dremmuel

    dremmuel Guest

    Right Now the Naga Royal Guard has two abilities with the same order string and it is using the first ability in the ability list unless it is on cooldown, in which case it uses the second.

    When WC3 interprets the code, does it build a pointer list from the unit (like a unit data structure) to the unit's abilities? Is that why none of the other abilities are "seen" by the order?

    Thanks for your help.
  12. LucidWay

    LucidWay Guest

    great tutorial. I have a question though. How can I control WHEN a computer uses a specific ability. IE: Use warstomp when there are 4 enemies in range, use bladestorm when xxxx. Knowing this would help me so much in my map. Thanks!
  13. ayumilove

    ayumilove Youtube account suspended! youtube.com/ayumilove8

    that is what im looking for too lucidway, but this tutorial is not really helping (-.-o)

    i tried out the method describe in the first paragraph where it ask user to
    export data and import them back, those are no use for heroes who have more than 9 level of abilities.
  14. Eotall

    Eotall Guest

    Taggers AI

    Hi :)
    I've noticed that your tutorial does not cover the AI programming for, say, a kodotag. I'm sure I'm not the only one who's tried making a tag but havn't been able to accurately program the computer-controlled taggers to attack the runners, without stopping to kill every building on the way.

    Can you pretty please post a tutorial for that kind of programming too? I'd be forever gratefull :thup:

Share This Page