HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

AI command trigger: Question about where to get those integers from?

02-02-2009, 01:38 PM#1
tom_mai78101
Anyone familiar about the trigger: Send AI command?

Hidden information:
Trigger:
Beginning
Collapse Events
Time - Elapsed game time is 2.00 seconds
Conditions
Collapse Actions
Game - Display to (All players) for 10.00 seconds the text: MIssion: Your job i...
Wait 15.00 game-time seconds
Game - Display to (All players) the text: All units are now v...
Collapse Unit Group - Pick every unit in (Units in Region) and do (Actions)
Collapse Loop - Actions
Unit - Make (Picked unit) Vulnerable
Collapse Player Group - Pick every player in (All players matching (((Picked player) controller) Equal to Computer)) and do (Actions)
Collapse Loop - Actions
AI - Send Player 1 (Red) the AI Command (0, 0)


Forget about the rest. I just need to focus on this part:

Trigger:
AI - Send Player 1 (Red) the AI Command (0, 0)

That "(0,0)" meant: The first 0 is Command, the second is Data. So...

1: What is "Command"? Where do I get the values for the correct commands from?
2: What is "Data"? And where do I get those values from?


That'll be it. I heard AMAI peoples are here, and basically our admin said this stuff here, which really tempted me to come here and ask them (or you) for help.

Thanks in advance.
02-03-2009, 03:52 AM#2
Archmage Owenalacaster
You can send any integers to an AI using AI Command (CommandAI in JASS). But the AI must be designed to access the values using GetLastCommand and GetLastData, usually with WaitForSignal or a loop that checks between Sleeps.

Collapse Examples:
globals
    integer playerIndex = 0
endglobals

function CheckForTargetPlayer takes nothing returns nothing
    local integer data = 0
    loop
        set data = GetLastData()
        if (playerIndex != data) and (data >= 0) and (data <= 16) then
            set playerIndex = data
        endif
        call Sleep(M1)
    endloop
endfunction

function main takes nothing returns nothing
    call CampaignAI(HOUSE,null)
    call StartThread(function CheckForTargetPlayer) // This starts a new thread
                                                    // that checks for data
                                                    // value each minute, then
                                                    // passes the value on to
                                                    // 'playerIndex', used as
                                                    // a player target.

    call SetBuildUnit( 4, PEASANT       )
    call SetBuildUnit( 3, BARRACKS      )
    call SetBuildUnit( 2, SANCTUM       )
    call SetBuildUnit( 1, BLACKSMITH    )
    call SetBuildUnit( 1, LUMBER_MILL   )
    call SetBuildUnit( 1, ARCANE_VAULT  )
    call SetBuildUnit( 1, HUMAN_ALTAR   )
    
    call WaitForSignal()    // 'WaitForSignal' will loop-sleep until the
                            // AI receives a command, whatever the value.
    
    loop
        call InitAssaultGroup()
        call CampaignAttacker(0,GetRandomInt(2,4),FOOTMAN) 
        call CampaignAttacker(0,GetRandomInt(2,4),RIFLEMAN) 
        call CampaignAttacker(0,GetRandomInt(1,2),SORCERESS) 
        call CampaignAttacker(0,GetRandomInt(1,2),PRIEST)  
        call CampaignAttacker(0,GetRandomInt(1,2),SPELL_BREAKER)
        call CampaignAttacker(0,GetRandomInt(0,1),KNIGHT)    
        call CampaignAttacker(0,GetRandomInt(0,1),MORTAR)
        call SuicideOnPlayer(M1,Player(playerIndex))
    endloop
    
endfunction

I realize this may be confusing to a GUI-user, but the full extent of AI capability is beyond what the WE AI Editor can render.
02-03-2009, 02:01 PM#3
tom_mai78101
Quote:
I realize this may be confusing to a GUI-user, but the full extent of AI capability is beyond what the WE AI Editor can render.

I'm not going to use AI editor.

At the beginning (map initialization), what should be retrieved when using GetLastData? Isn't that suppose to be empty, since the last data technically didn't exist? I didn't see GetLastCommand(), where is it?

---------------------------

Back to the trigger (Send AI command), should the integers be user-defined? Do I just input the numbers and then let it run on its own?
02-03-2009, 04:38 PM#4
Archmage Owenalacaster
  • Do not confuse AI with triggering computer player behavior. AIs are run from either .ai or .wai files uploaded into a map, usually through the Import Manager. To start an AI, use either Start Melee AI Script or Start Campaign AI Script (in GUI), or StartMeleeAI or StartCampaignAI (in JASS), preferably during map inititialization.
  • You cannot call exclusive AI functions from map triggers. AIs use the functions and constants in common.ai and common.j (I don't know if it can use blizzard.j functions). Only with a modified common.j imported to your map can your map triggers use common.ai functions like GetUnitGoldCost.
  • You can send about anything to an AI using CommandAI. You can use whatever integers please you, but the AI won't do anything with it unless it was designed to do so. The return bug even allows you to send something like a unit or location to an AI, useful for specific assault targets.
If this makes it any clearer, AIs are not programmed with map triggers. Use a program like JassCraft to design an AI.
02-04-2009, 01:46 PM#5
tom_mai78101
Oh....Thank you.

---------
Note to self:

Which leaves me wondering why do the developers placed the Send AI command trigger in there for...? You may answer if you want, it's just me stumped.
02-04-2009, 02:17 PM#6
Archmage Owenalacaster
Send AI Command is usually used with Blizzard Campaign AIs to tell the AIs when to begin building assault forces. It has no use with Blizzard Melee AIs.
02-04-2009, 03:02 PM#7
DioD
check AMAI this will help a lot.
02-04-2009, 03:39 PM#8
tom_mai78101
To Archmage Owenalacaster:

Thank you.

To Diod:

No thanks. AMAI sure is a lot more complex than the Campaign AI. I haven't learned much about AMAI.
02-04-2009, 03:51 PM#9
DioD
AMAI have nice documentation and great to learn about "send get and return commands"
02-07-2009, 07:32 PM#10
tom_mai78101
Hmm...You've got me.