• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

[AI] Stop Attack when Player is Destroyed

Status
Not open for further replies.
Level 16
Joined
Mar 3, 2006
Messages
1,564

JASS:
globals
    player MyVictim = Player(2) // Player 3 (Teal)
endglobals

function hero_levels takes nothing returns integer
    local integer hero  = GetHeroId()
    local integer level = GetHeroLevelAI()
    local integer a = 0
    if hero == DEMON_HUNTER then
        if level == 1 or level == 3 or level == 5 then
            set a = IMMOLATION
        endif
        if level == 2 or level == 4 or level == 7 then
            set a = MANA_BURN
        endif
        if level >= 8 then
            set a = EVASION
        endif
        if level == 6 then
            set a = METAMORPHOSIS
        endif
    endif
    if hero == MOON_CHICK then
        if level == 1 or level == 3 or level == 5 then
            set a = TRUESHOT
        endif
        if level == 2 or level == 4 or level == 7 then
            set a = SEARING_ARROWS
        endif
        if level >= 8 then
            set a = SCOUT
        endif
        if level == 6 then
            set a = STARFALL
        endif
    endif
    return a
endfunction


function main takes nothing returns nothing
    call CampaignAI( MOON_WELL, function hero_levels )
    //call AttackMoveXY(-6500,-6500) // Just a signal to detect if the AI is working or not
    //call PurchaseZeppelin()
    
    //call SetBuildUnitEx( 9, 9, 9, WISP         )
    //•••••••••••••••••••••••••••••••••••••••••
    //•               DEFENDERS               •
    //•••••••••••••••••••••••••••••••••••••••••
    call CampaignDefenderEx( 1, 1, 1, MOON_CHICK )
    //call CampaignDefenderEx( 3, 3, 3, ARCHER     )
    //call CampaignDefenderEx( 3, 3, 3, HUNTRESS   )

    //•••••••••••••••••••••••••••••••••••••••••
    //•               ATTACKING               •
    //•••••••••••••••••••••••••••••••••••••••••


    loop
        //•     WAVE #5+    •
        call InitAssaultGroup()
        call CampaignAttackerEx(1,1,1,MOON_CHICK)
        call CampaignAttackerEx(6,6,6,ARCHER)
        call CampaignAttackerEx(6,6,6,HUNTRESS)
        //call ForeverSuicideOnPlayer(10,MyVictim)
        call SuicideOnPlayerEx(10,10,10,MyVictim)
        //exitwhen GetEnemyBase() == null
    endloop
endfunction
I removed the first waves to test the AI faster and also changed the unit build time to 1.

How to exit the loop when the target is destroyed ? Do I have to detect this via triggers then send an AI command, if so how to do it ?
 
Last edited:
Status
Not open for further replies.
Top