[AI] AI Not working For a campaign map

Level 7
Joined
Sep 30, 2017
Messages
100
Hello Everyone, I'm making an AI to one of my campaign maps using Jass. It my First time using it so i didn't know anything basically, The AI have custom race and preplaced buildings and units but for somereason The AI doesn't run at all, can anyone help any tips?

The AI:
JASS:
//============================================================================
//  Chapter06 -- Teal player -- AI Script
//============================================================================
globals
    player user = Player(7) //player 7 Green
    
    constant integer Crusader = 'h609'
    constant integer Zealot = 'h612'
    constant integer Crossbowman = 'n607'
    constant integer Templar = 'h603'
    constant integer Inquisitor = 'h604'
    constant integer Bishop = 'h605'
    constant integer Knight = 'h617'
    constant integer Catapult = 'o602'
    constant integer Bunker = 'e604'
    constant integer Lieutenant = 'e605'
    constant integer Lord_Godfrey = 'H61L'
    constant integer Mystical_Knight = 'h61K'
    constant integer Archangel = 'h608'
    constant integer Paladin = 'h60A'
endglobals

function main takes nothing returns nothing
    set campaign_wood_peons = 5
    
    call CampaignAI('h615',null) //House
    call SetReplacements(1,1,1)
    call GroupTimedLife(true)
    call SetPeonsRepair(true)
    call SetSlowChopping(true)

    //Building Strategy
    //Tier 1
    call SetBuildUnitEx(8,8,8,Zealot) //Zealot
    call SetBuildUnitEx(2,2,2,'h616') //Armoury
    call SetBuildUnitEx(3,3,3,'h61D') //Watch Tower
    call SetBuildUnitEx(3,3,3,'h61E') //Guard Tower
    call SetBuildUnitEx(1,1,1,'h61F') //Cannon Tower
    call SetBuildUnitEx(1,1,1,'h61G') //Holy Tower
    call SetBuildUnitEx(1,1,1,'h60H') //Altar
    call SetBuildUnitEx(1,1,1,'h618') //Saw Mill
    call SetBuildUnitEx(1,1,1,'h619') //Forge
    call SetBuildUnitEx(1,1,1,'h61H') //Tabernacle
    call SetBuildUnitEx(14,14,14,'h615') //House
    //Tier 2
    call SetBuildUnitEx(1,1,1,'h61A') //Siege Workshop
    call SetBuildUnitEx(2,2,2,'h60M') //Cathedral
    //Tier 3
    call SetBuildUnitEx(1,1,1,'h614') //Monastery
    call SetBuildUnitEx(1,1,1,'h61C') //Tower of Blessings
    //Defender Units
    call CampaignDefenderEx(1,1,1,Lieutenant) //Lieutenant
    call CampaignDefenderEx(2,2,2,Bishop) //Bishop
    call CampaignDefenderEx(2,2,2,Inquisitor) //Inquisitor
    call CampaignDefenderEx(3,3,3,Templar) //Templar
    call CampaignDefenderEx(2,2,2,Knight) //Knight
    call CampaignDefenderEx(1,1,1,Catapult) //Catapult 
    call CampaignDefenderEx(2,2,2,Mystical_Knight) //Mystical Knight
    call CampaignDefenderEx(12,12,12,Crusader) //Crusader
    call CampaignDefenderEx(7,7,7,Crossbowman) //Crossbowman
    
    call WaitForSignal()

    //Attack Waves

    //Wave 1
    call InitAssaultGroup()
    call CampaignAttackerEx(4,4,4,Crusader)
    call CampaignAttackerEx(3,3,3,Crossbowman)
    call CampaignAttackerEx(2,2,2,Knight)
    call SuicideOnPlayerEx(M2,M2,M2,user)
    
    //Wave 2
    call InitAssaultGroup()
    call CampaignAttackerEx(4,4,4,Crusader)
    call CampaignAttackerEx(3,3,3,Crossbowman)
    call CampaignAttackerEx(2,2,2,Templar)
    call CampaignAttackerEx(2,2,2,Inquisitor)
    call CampaignAttackerEx(1,1,1,Catapult)
    call SuicideOnPlayerEx(M4,M4,M4,user)
    
    //Wave 3
    call InitAssaultGroup()
    call CampaignAttackerEx(5,5,5,Crusader)
    call CampaignAttackerEx(3,3,3,Templar)
    call CampaignAttackerEx(2,2,2,Inquisitor)
    call CampaignAttackerEx(2,2,2,Bishop)
    call CampaignAttackerEx(2,2,2,Catapult)
    call SuicideOnPlayerEx(M4,M4,M4,user)
    
    //Wave 4
    call InitAssaultGroup()
    call CampaignAttackerEx(1,1,1,Inquisitor)
    call CampaignAttackerEx(4,4,4,Crusader)
    call CampaignAttackerEx(3,3,3,Crossbowman)
    call CampaignAttackerEx(3,3,3,Bishop)
    call CampaignAttackerEx(1,1,1,Lord_Godfrey)
    call SuicideOnPlayerEx(M4,M4,M4,user)
    
    //Wave 5
    call InitAssaultGroup()
    call CampaignAttackerEx(3,3,3,Crusader)
    call CampaignAttackerEx(3,3,3,Crossbowman)
    call CampaignAttackerEx(1,1,1,Templar)
    call CampaignAttackerEx(1,1,1,Inquisitor)
    call CampaignAttackerEx(2,2,2,Mystical_Knight)
    call SuicideOnPlayerEx(M4,M4,M4,user)
    
    loop
        //Wave 6
        call InitAssaultGroup()
        call CampaignAttackerEx(3,3,3,Crusader)
        call CampaignAttackerEx(3,3,3,Crossbowman)
        call CampaignAttackerEx(3,3,3,Bishop)
        call SuicideOnPlayerEx(M3,M3,M3,user)
        
        //Wave 6.5
        call InitAssaultGroup()
        call CampaignAttackerEx(3,3,3,Mystical_Knight)
        call CampaignAttackerEx(2,2,2,Archangel)
        call SuicideOnPlayerEx(M5,M5,M5,user)
        
        //Wave 7
        call InitAssaultGroup()
        call CampaignAttackerEx(5,5,5,Crusader)
        call CampaignAttackerEx(2,2,2,Crossbowman)
        call CampaignAttackerEx(2,2,2,Templar)
        call CampaignAttackerEx(1,1,1,Catapult)
        call SuicideOnPlayerEx(M4,M4,M4,user)
        
        //Wave 8
        call InitAssaultGroup()
        call CampaignAttackerEx(4,4,4,Crusader)
        call CampaignAttackerEx(2,2,2,Crossbowman)
        call CampaignAttackerEx(1,1,1,Inquisitor)
        call CampaignAttackerEx(1,1,1,Bishop)
        call CampaignAttackerEx(1,1,1,Catapult)
        call SuicideOnPlayerEx(M4,M4,M4,user)
        
        //Wave 9
        call InitAssaultGroup()
        call CampaignAttackerEx(1,1,1,Inquisitor)
        call CampaignAttackerEx(4,4,4,Crusader)
        call CampaignAttackerEx(4,4,4,Crossbowman)
        call CampaignAttackerEx(2,2,2,Templar)
        call CampaignAttackerEx(1,1,1,Inquisitor)
        call SuicideOnPlayerEx(M5,M5,M5,user)
        
        //Wave 10
        call InitAssaultGroup()
        call CampaignAttackerEx(5,5,5,Crusader)
        call CampaignAttackerEx(4,4,4,Crossbowman)
        call CampaignAttackerEx(3,3,3,Templar)
        call CampaignAttackerEx(2,2,2,Inquisitor)
        call CampaignAttackerEx(2,2,2,Bishop)
        call CampaignAttackerEx(1,1,1,Lord_Godfrey)
        call SuicideOnPlayerEx(M5,M5,M5,user)
        
    endloop
endfunction



Also Here is the Triggers:
Screenshot 2024-06-18 192819.png


Note:
All of The Units used by the AI Have Editor Suffix names, Like for example The Crusader unit in the world editor is called Crusader (BH), I didn't know if that could cause a problem or not honestly
and also The Player that the ai conrtol is color teal but there is a trigger that only change his color to grey.
 

Attachments

  • Screenshot 2024-06-19 175424.png
    Screenshot 2024-06-19 175424.png
    102.9 KB · Views: 12
  • Screenshot 2024-06-19 175445.png
    Screenshot 2024-06-19 175445.png
    99.5 KB · Views: 13
  • Screenshot 2024-06-19 175504.png
    Screenshot 2024-06-19 175504.png
    95.6 KB · Views: 11
  • Chapter06(TealPlayer).ai
    5.9 KB · Views: 15
Last edited:
Level 30
Joined
Aug 29, 2012
Messages
1,382
That's a silly question but I assume your trigger is ran from another trigger? Because there is no event :grin:

Also, does the build order match your tech tree? E.g. you'd need the town hall first, then the worker, then a barracks, then a farm, then footmen etc.
 
Level 7
Joined
Sep 30, 2017
Messages
100
That's a silly question but I assume your trigger is ran from another trigger? Because there is no event :grin:

Also, does the build order match your tech tree? E.g. you'd need the town hall first, then the worker, then a barracks, then a farm, then footmen etc.
Yes This trigger is ran from another trigger ( After the Cinematic )

and Also yes it match The AI have the town hall (Monastery), workers (Zealot), and Barracks (Armoury) etc.

But The AI doesn't run at all and i didn't know why.
 
Level 7
Joined
Sep 30, 2017
Messages
100
Strangly, The AI now runs, and I know that because the workers start harvesting slowly, but it has strange behavior. First, the AI selects all the preplaced units and moves them near the gold mine except the hero for some reason; second, all the workers harvest gold, not lumber; and third, the AI doesn't send waves at all.
 
Level 30
Joined
Aug 29, 2012
Messages
1,382
Try using this action for your hero, I had a similar problem once with a preplaced hero

  • AI - Recycle (YourUnit)'s guard position
For the rest, perhaps try to send the command in a separate trigger, i.e. not immediately after starting the AI? Not sure that makes a difference but who knows
 
Level 7
Joined
Sep 30, 2017
Messages
100
Nope Still doesn't work, I have created another AI script for a different faction ( Ones with No Editor Suffix Names) and the units actually stays in place, but still workers don't harvest wood and the AI doesn't send attack waves.

JASS:
//============================================================================
//  Chapter 06 -- brown player -- AI Script
//============================================================================
globals
    player MyVictim = PlayerEx(1)
    
    constant integer Peasant = 'h60C'
    constant integer Swordsman = 'h601'
    constant integer Bowman = 'n605'
    constant integer Cavalier = 'h602'
    constant integer Mage = 'u60X'
    constant integer Catapult = 'o601'
    constant integer Champion = 'h606'
    constant integer Sorceress = 'h60Z'
    constant integer Gryphon_Rider = 'e602'
    constant integer Eagle_Knight = 'e603'
    constant integer Ballista = 'e600'
endglobals

function main takes nothing returns nothing
    call CampaignAI('h60G',null) //House
    call SetReplacements(1,1,1)
    call GroupTimedLife(true)
    call SetPeonsRepair(true)
    call SetSlowChopping(true)
    set campaign_wood_peons = 4

    //Building Strategy
    //Tier 1
    call SetBuildUnitEx(8,8,8,Peasant) //Peasant
    call SetBuildUnitEx(2,2,2,'h60I') //Barracks
    call SetBuildUnitEx(21,21,21,'h60G') //House
    call SetBuildUnitEx(1,1,1,'h60H') //Altar
    call SetBuildUnitEx(1,1,1,'h60J') //Saw Mill
    call SetBuildUnitEx(1,1,1,'h60K') //Blacksmith
    call SetBuildUnitEx(1,1,1,'h60T') //Market
    //Tier 2
    call SetBuildUnitEx(1,1,1,'h610') //Arcane Tower
    call SetBuildUnitEx(1,1,1,'h60L') //Siege Workshop
    //Tier 3
    call SetBuildUnitEx(1,1,1,'h60F') //Palace
    call SetBuildUnitEx(6,6,6,'h60P') //Guard Tower
    //Defender Units
    call SetBuildUnitEx(9,9,9,Swordsman) //Swordsman
    call SetBuildUnitEx(3,3,3,Bowman) //Bowman 
    call SetBuildUnitEx(2,2,2,Cavalier) //Cavalier
    call SetBuildUnitEx(1,1,1,Champion) //Champion
    call SetBuildUnitEx(1,1,1,Sorceress) //Sorceress
    call SetBuildUnitEx(3,3,3,Mage) //Mage
    call SetBuildUnitEx(3,3,3,Gryphon_Rider) //Gryphon_Rider
    call SetBuildUnitEx(1,1,1,Catapult) //Catapult

    call WaitForSignal()
    
    //Attack Waves

    //Wave 1
    call InitAssaultGroup()
    call CampaignAttackerEx(4,4,4,Swordsman)
    call CampaignAttackerEx(2,2,2,Bowman)
    call SuicideOnPlayerEx(M3,M3,M3,MyVictim)

    call InitAssaultGroup()
    call CampaignAttackerEx(4,4,4,Swordsman)
    call CampaignAttackerEx(2,2,2,Bowman)
    call CampaignAttackerEx(2,2,2,Cavalier)
    call SuicideOnPlayerEx(M4,M4,M4,MyVictim)
    
    //Wave 2
    call InitAssaultGroup()
    call CampaignAttackerEx(3,3,3,Swordsman)
    call CampaignAttackerEx(2,2,2,Bowman)
    call CampaignAttackerEx(2,2,2,Mage)
    call CampaignAttackerEx(1,1,1,Sorceress)
    call SuicideOnPlayerEx(M3,M3,M3,MyVictim)
    
    //Wave 3
    call InitAssaultGroup()
    call CampaignAttackerEx(4,4,4,Swordsman)
    call CampaignAttackerEx(1,1,1,Champion)
    call CampaignAttackerEx(2,2,2,Mage)
    call CampaignAttackerEx(2,2,2,Sorceress)
    call CampaignAttackerEx(1,1,1,Catapult)
    call SuicideOnPlayerEx(M5,M5,M5,MyVictim)
        
    //Wave 4
    call InitAssaultGroup()
    call CampaignAttackerEx(3,3,3,Swordsman)
    call CampaignAttackerEx(3,3,3,Bowman)
    call CampaignAttackerEx(2,2,2,Mage)
    call CampaignAttackerEx(1,1,1,Catapult)
    call SuicideOnPlayerEx(M3,M3,M3,MyVictim)

    loop
        
        //Wave 5
        call InitAssaultGroup()
        call CampaignAttackerEx(3,3,3,Swordsman)
        call CampaignAttackerEx(3,3,3,Bowman)
        call CampaignAttackerEx(2,2,2,Mage)
        call CampaignAttackerEx(2,2,2,Sorceress)
        call SuicideOnPlayerEx(M3,M3,M3,MyVictim)
        
        //Wave 6
        call InitAssaultGroup()
        call CampaignAttackerEx(6,6,6,Swordsman)
        call CampaignAttackerEx(3,3,3,Bowman)
        call CampaignAttackerEx(2,2,2,Mage)
        call CampaignAttackerEx(1,1,1,Catapult)
        call CampaignAttackerEx(1,1,1,Champion)
        call SuicideOnPlayerEx(M4,M4,M4,MyVictim)
        
        //Wave 7
        call InitAssaultGroup()
        call CampaignAttackerEx(6,6,6,Swordsman)
        call CampaignAttackerEx(4,4,4,Bowman)
        call CampaignAttackerEx(4,4,4,Gryphon_Rider)
        call CampaignAttackerEx(2,2,2,Catapult)
        call SuicideOnPlayerEx(M3,M3,M3,MyVictim)

    endloop
endfunction
 
Level 30
Joined
Aug 29, 2012
Messages
1,382
JASS:
call CampaignAI('h60G',null)

That might be the problem, try using HOUSE or hhou instead of your custom farm-type building. From what I can gather, it doesn't really matter what building you set there, but everytime I've tried to use custom ones, my AIs just wouldn't do anything
 
Level 7
Joined
Sep 30, 2017
Messages
100
I Just Syntax to check for any errors and it just says Underclared Function

I didn't know man really, I copied and pasted AI scripts from other AI scripts and still nothing works sad really.
 
Level 7
Joined
Sep 30, 2017
Messages
100
UPDATE:
The AI Actually works! but for somereason doesn't work on the map i want to use it one. i used it in a different map in my campaign and it works ( not perfectly but works ) it repair, build and send attack waves, i don't know whats wrong my map.
 
Level 7
Joined
Sep 30, 2017
Messages
100
I have tried running the trigger that activate the ai using map initialization and the Ai works perfectly, Here has to be something wrong the triggers maybe the start trigger or the intro cinematic, hopefully i will find the problem.

But anyways thank you very much for your support. 🙏🏻
 
if you unpause all units in your cinematic without first using the action "pause all units" this can break the AI.

EDIT: I should've said if it's an issue with the triggers you could post them here and we can take a look :)
 
Last edited:
Top