• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Solved] Campaign AI Not Working

Status
Not open for further replies.
Level 1
Joined
Oct 6, 2015
Messages
5
Hello everyone, I followed Moyack's campaign AI tutorial and came up with this, though the computer won't create any units. I have imported the .ai file and used a trigger that starts it, so I believed there is something up with the code. I'll be thankful for any help, thanks!



Code:
globals                                                                    
  player User = Player( 0 )
endglobals

function ConfigureAI takes nothing returns nothing
    call SetSlowChopping( true )
    call SetPeonsRepair( true )
endfunction

function hero_levels takes nothing returns integer
    local integer hero = GetHeroId()
    local integer level = GetHeroLevelAI()
    local integer a = 0
    if hero == 'Nbbc' then
       if level == 7 then
           set a = 'AOww'
        endif
       if level == 8 then
           set a = 'ANr3'
       endif
    endif
    return a
endfunction

function main takes nothing returns nothing
    call CampaignAI( 'otrb', function hero_levels )
    call ConfigureAI( )
    //*DEFENSE
    call SetReplacments(99, 99, 99)
    call CampaignDefenderEx( 2, 2, 2, 'nrwm' )
    call CampaignDefenderEx( 1, 1, 1, 'nbal' )
    call CampaignDefenderEx( 1, 1, 1, 'ninf' )
    //*ATTACKING
    /*Wave 1
    call InitAssualtGroup()
    call CampaignAttackerEx( 5, 5, 5, 'nchg' )
    call CampaignAttackerEx( 4, 4, 4, 'nchw' )
    call CampaignAttackerEx( 4, 4, 4, 'nchr' )
    call SuicideOnPlayerEx( M3, M3, M3, User )
  
    /*Wave 2
    call InitAssaultGroup()
    call CampaignAttackerEx( 2, 2, 2, 'ninf' )
    call CampaignAttackerEx( 3, 3, 3, 'nbal' )
    call CampaignAttackerEx( 1, 1, 1, 'Nbbc' )
    call SuicideOnPlayerEx( M4, M4, M4, User )
endfunction
 
Last edited:
tutorial
Creating AI workflow

do you have preplaced ncpn units? if not use this line
call SetBuildUnit(2, CHAOS_PEON)
are required buildings exists? Has Ai resources?
did you set computer slot and start ai like this:
  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • AI - Start campaign AI script for Player 3 (Teal): war3mapImported\file.ai
 
Level 1
Joined
Oct 6, 2015
Messages
5
tutorial
Creating AI workflow

do you have preplaced ncpn units? if not use this line
call SetBuildUnit(2, CHAOS_PEON)
are required buildings exists? Has Ai resources?
did you set computer slot and start ai like this:
  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • AI - Start campaign AI script for Player 3 (Teal): war3mapImported\file.ai
Yes, ncpn units are preplaced, all required buildings are placed, the AI has plenty of resources and computer slot is set and the trigger is correct
 
Level 6
Joined
Sep 7, 2017
Messages
207
You need to make variables for each unit type.
You can open the Chasing the Dawn campaign and check the .ai files in the w3n file. It was my reference of learning AI.
 
Level 12
Joined
Jun 15, 2016
Messages
472
You need to make variables for each unit type.
You can open the Chasing the Dawn campaign and check the .ai files in the w3n file. It was my reference of learning AI.

That is unnecessary, these units already have a variable name in the common.ai file:

JASS:
constant integer DOOMGUARD          = 'nbal'
constant integer ORC_DRAGON         = 'nrwm'
...

If you copied your AI file as it is, I believe the problem is in these lines:

JASS:
    /*Wave 1 <- this is not a comment, a comment starts with '//'
    call InitAssualtGroup()
    call CampaignAttackerEx( 5, 5, 5, 'nchg' )
    call CampaignAttackerEx( 4, 4, 4, 'nchw' )
    call CampaignAttackerEx( 4, 4, 4, 'nchr' )
    call SuicideOnPlayerEx( M3, M3, M3, User )
 
    /*Wave 2 <- this is also not a comment
    call InitAssaultGroup()
    call CampaignAttackerEx( 2, 2, 2, 'ninf' )
    call CampaignAttackerEx( 3, 3, 3, 'nbal' )
    call CampaignAttackerEx( 1, 1, 1, 'Nbbc' )
    call SuicideOnPlayerEx( M4, M4, M4, User )
 
Level 1
Joined
Oct 6, 2015
Messages
5
That is unnecessary, these units already have a variable name in the common.ai file:

JASS:
constant integer DOOMGUARD          = 'nbal'
constant integer ORC_DRAGON         = 'nrwm'
...

If you copied your AI file as it is, I believe the problem is in these lines:

JASS:
    /*Wave 1 <- this is not a comment, a comment starts with '//'
    call InitAssualtGroup()
    call CampaignAttackerEx( 5, 5, 5, 'nchg' )
    call CampaignAttackerEx( 4, 4, 4, 'nchw' )
    call CampaignAttackerEx( 4, 4, 4, 'nchr' )
    call SuicideOnPlayerEx( M3, M3, M3, User )
 
    /*Wave 2 <- this is also not a comment
    call InitAssaultGroup()
    call CampaignAttackerEx( 2, 2, 2, 'ninf' )
    call CampaignAttackerEx( 3, 3, 3, 'nbal' )
    call CampaignAttackerEx( 1, 1, 1, 'Nbbc' )
    call SuicideOnPlayerEx( M4, M4, M4, User )
OK, I fixed those 2 lines and the computer still does nothing
 
Status
Not open for further replies.
Top