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

AI script for custom race won't trigger

Status
Not open for further replies.
Level 24
Joined
Feb 28, 2007
Messages
3,479
Hey.

I've made a simple AI for a custom race using the AI editor, but the AI won't run properly once in-game. All it does is send all the peons to harvest gold, which I read is a sign that something is terribly wrong.

To run the imported AI script I use the following trigger:
  • AI - Start melee AI script for Player 7 (Green): myai.ai
The .wai file is attached to this pastebin entry:
http://www.hiveworkshop.com/forums/pastebin.php?id=c09txr

Thanks in advance.
 
you need is an ai file and wai file.
To create an ai file,use the ai editor,then a folder near the world editor(via warcraft folders) that includes an ai file.Open it with notepad then customize it.
If you want to use easier,open a Monolith unprotected map,export ai files then edit it.

Monolith is a good example of a map ai(altered melee),better check it out
 
Level 24
Joined
Feb 28, 2007
Messages
3,479
Importing a .wai file creates an AI file.

Anyway, tried editing Monolith's file but to no avail. Same problem. Fuck.

Edit: Here is my .ai file that supposedly does nothing (it should only send the peons to harvest)

JASS:
//===========================================================================
// 
// 01Green
// 
//   Warcraft III AI script
//   Generated by the Warcraft III World Editor
//   Date: Mon Nov 12 13:08:29 2012
// 
//===========================================================================

//***************************************************************************
//*
//*  Global Variables
//*
//***************************************************************************

globals
    integer                 attackWave                 = 1
    integer                 nextDelay                  = 0
    integer                 awGold                     = 0
    integer                 awWood                     = 0

    // Conditions
    boolean                 gCond_Attack_Enemy         = false
    boolean                 gCond_Attack_Strong_Creeps = false
    boolean                 gCond_Have_Lumber          = false
    boolean                 gCond_Need_Expansion       = false
endglobals

//***************************************************************************
//*
//*  Utility Functions
//*
//***************************************************************************

//===========================================================================
function CheckLastCommand takes boolean pop returns integer
    local integer cmd = GetLastCommand()
    if (pop) then
        call PopLastCommand(  )
    endif
    return cmd
endfunction

//===========================================================================
function CheckLastCommandData takes boolean pop returns integer
    local integer data = GetLastData()
    if (pop) then
        call PopLastCommand(  )
    endif
    return data
endfunction

//===========================================================================
function TotalFoodProduced takes nothing returns integer
    return GetPlayerState(ai_player,PLAYER_STATE_RESOURCE_FOOD_CAP)
endfunction

//===========================================================================
function ExpansionNeeded takes nothing returns boolean
    return take_exp
endfunction

//===========================================================================
function BuildExpansion takes integer hallID, integer mineID returns nothing
    if (HallsCompleted(hallID)) then
        call SetBuildExpa( TownCount(hallID) + 1, mineID )
    endif
endfunction

//===========================================================================
function CurrentAttackWave takes nothing returns integer
    return attackWave
endfunction

//===========================================================================
function ResetAttackUnits takes nothing returns nothing
    set awGold = 0
    set awWood = 0
    call InitAssaultGroup(  )
endfunction

//===========================================================================
function AddAttackUnit takes integer minQty, integer maxQty, integer unitID returns nothing
    // Track attacking gold workers
    if (unitID == 'o607') then
        set awGold = awGold + minQty
    endif

    // Track attacking wood workers
    if (unitID == 'o607') then
        set awWood = awWood + minQty
    endif

    call SetAssaultGroup( minQty, maxQty, unitID )
endfunction

//***************************************************************************
//*
//*  Basic Options
//*
//***************************************************************************

//===========================================================================
function InitOptions takes nothing returns nothing
    call SetMeleeAI(  )
    call SetDefendPlayer( false )
    call SetRandomPaths( false )
    call SetTargetHeroes( false )
    call SetPeonsRepair( true )
    call SetHeroesFlee( false )
    call SetHeroesBuyItems( false )
    call SetUnitsFlee( false )
    call SetGroupsFlee( false )
    call SetWatchMegaTargets( false )
    call SetIgnoreInjured( false )
    call SetHeroesTakeItems( false )
    call SetSlowChopping( true )
    call SetCaptainChanges( false )
    call SetSmartArtillery( false )
endfunction

//***************************************************************************
//*
//*  Conditions
//*
//***************************************************************************

//===========================================================================
// Updates the values of all preset conditions
//===========================================================================
function UpdateConditions takes nothing returns nothing
    set gCond_Attack_Enemy = ( CheckLastCommand( false ) == 1 )
    set gCond_Attack_Strong_Creeps = ( FoodUsed(  ) >= 40 )
    set gCond_Have_Lumber = ( GetWood(  ) > 0 )
    set gCond_Need_Expansion = ( ( GetGold(  ) < 2000 ) and ( GetGoldOwned(  ) < 2000 ) )
endfunction

//***************************************************************************
//*
//*  Heroes
//*
//***************************************************************************

//===========================================================================
// Stores hero ID and skills
//===========================================================================
function SetHero takes integer order, integer heroid returns nothing
    if (order == 1) then
        set hero_id = heroid
        if (heroid == 'O007') then
            set skills1[ 1] = 'AHab'
            set skills1[ 2] = 'AOhw'
            set skills1[ 3] = 'ANms'
            set skills1[ 4] = 'AHab'
            set skills1[ 5] = 'AOhw'
            set skills1[ 6] = 'AHre'
            set skills1[ 7] = 'ANms'
            set skills1[ 8] = 'AHab'
            set skills1[ 9] = 'AOhw'
            set skills1[10] = 'ANms'
        endif
    endif
endfunction

//===========================================================================
// Selects hero IDs for three possible heroes
//===========================================================================
function SelectHeroes takes nothing returns nothing
    local integer roll = GetRandomInt(1,100)
    call SetHero( 1, 'O007' )
endfunction

//===========================================================================
// Returns the hero skill for the given hero and level
//===========================================================================
function ChooseHeroSkill takes nothing returns integer
    local integer curHero = GetHeroId()
    local integer level = GetHeroLevelAI()

    if (level > max_hero_level) then
        set max_hero_level = level
    endif

    if (curHero == hero_id) then
        return skills1[level]
    elseif (curHero == hero_id2) then
        return skills2[level]
    elseif (curHero == hero_id3) then
        return skills3[level]
    endif
    return 0
endfunction

//***************************************************************************
//*
//*  Building and Harvesting
//*
//***************************************************************************

//===========================================================================
// Specifies building priorities for workers
//===========================================================================
function BuildPriorities takes nothing returns nothing
    local integer mine = TownWithMine()
endfunction

//===========================================================================
// Specifies harvesting priorities for workers
//===========================================================================
function HarvestPriorities takes nothing returns nothing
    local integer mine = TownWithMine()
    local integer allGold = GetUnitCountDone('o607')
    local integer allWood = GetUnitCountDone('o607')
    local integer numWorkers
    set numWorkers = 5
    call HarvestGold( 0, numWorkers )
    set numWorkers = 2
    call HarvestWood( 0, numWorkers )
endfunction

//===========================================================================
// Determines all building and harvesting assignments for workers
//===========================================================================
function WorkerAssignment takes nothing returns nothing
    loop
        call UpdateConditions(  )

        // Harvesting
        call ClearHarvestAI(  )
        call HarvestPriorities(  )

        // Building
        call InitBuildArray(  )
        call BuildPriorities(  )

        call Sleep( 2 )
    endloop
endfunction

//***************************************************************************
//*
//*  Attacking
//*
//***************************************************************************

//===========================================================================
// Returns true if the minimum forces for an attack exist
//===========================================================================
function HaveMinimumAttackers takes nothing returns boolean
    local integer count

    // Check for attack wave limit
    if (attackWave > 1) then
        return false
    endif

    // Attack Group: Minimum
    set count = GetUnitCountDone( 'O007' )
    if (count < 1) then
        return false
    endif
    set count = GetUnitCountDone( 'nfrl' )
    if (count < 3) then
        return false
    endif
    return true
endfunction

//===========================================================================
// Assigns units to attack based on the given attack group
//===========================================================================
function PrepareAttackGroup takes integer groupID returns nothing
    local integer all

    // Attack Group #1: All Units
    if (groupID == 1) then
        set all = GetUnitCountDone( 'nfrs' )
        call AddAttackUnit( all, all, 'nfrs' )
        set all = GetUnitCountDone( 'O007' )
        call AddAttackUnit( all, all, 'O007' )
        set all = GetUnitCountDone( 'nfrl' )
        call AddAttackUnit( all, all, 'nfrl' )
        set all = GetUnitCountDone( 'nfrb' )
        call AddAttackUnit( all, all, 'nfrb' )
        set all = GetUnitCountDone( 'nfrg' )
        call AddAttackUnit( all, all, 'nfrg' )

        // Attack Group #2: Minimum
    elseif (groupID == 2) then
        call AddAttackUnit( 1,   1,   'O007' )
        call AddAttackUnit( 3,   3,   'nfrl' )

    endif
endfunction

//===========================================================================
// Prepares an attack group based on the current attack wave
//===========================================================================
function PrepareForces takes nothing returns nothing
    if (attackWave == 1) then
        call PrepareAttackGroup( 1 )
    endif
endfunction

//===========================================================================
// Sleep delays for each attack wave
//===========================================================================
function AttackWaveDelay takes integer inWave returns nothing
    if (inWave < nextDelay) then
        return
    endif

    set nextDelay = inWave + 1
endfunction

//===========================================================================
// Advances attack wave counter
//===========================================================================
function AttackWaveUpdate takes nothing returns nothing
    call AttackWaveDelay( attackWave )
    set attackWave = attackWave + 1
    if (attackWave > 1) then
        set attackWave = 1
        set nextDelay = attackWave + 1
    endif
endfunction

//===========================================================================
// Basic attack functionality
//===========================================================================
function AttackTarget takes unit target, boolean addAlliance returns nothing
    if (target == null) then
        return
    endif
    if (addAlliance) then
        call SetAllianceTarget( target )
    endif
    call FormGroup( 3, true )
    call AttackMoveKillA( target )
    if (not addAlliance) then
        call SetAllianceTarget( null )
    endif
endfunction

//===========================================================================
// Initiates an attack based on target priorities
//===========================================================================
function LaunchAttack takes nothing returns nothing
    local unit target = null
    local boolean setAlly = true

    // Don't launch any attack while town is threatened
    if (TownThreatened()) then
        call Sleep( 2 )
        return
    endif

    // Target Priority #1
    if (target == null) then
        set target = GetAllianceTarget()
        if (target != null) then
            set setAlly = false
        endif
    endif

    // Target Priority #2
    if (gCond_Attack_Strong_Creeps) then
        if (target == null) then
            set target = GetExpansionFoe()
            if (target != null) then
                set take_exp = false
            endif
        endif

        // Target Priority #3
    endif
    if (gCond_Attack_Enemy) then
        if (target == null) then
            set target = GetMegaTarget()
        endif

        // Target Priority #4
        if (target == null) then
            set target = GetEnemyExpansion()
        endif

        // Target Priority #5
        if (target == null) then
            set target = GetEnemyExpansion()
            if (target == null) then
                call StartGetEnemyBase(  )
                loop
                    exitwhen (not WaitGetEnemyBase())
                    call SuicideSleep( 1 )
                endloop
                set target = GetEnemyBase()
            endif
        endif

        // Target Priority #6
    endif
    if (target == null) then
        set target = GetCreepCamp( 0, 6, false )
    endif

    // Target Priority #7
    if (gCond_Attack_Strong_Creeps) then
        if (target == null) then
            set target = GetCreepCamp( 7, 15, true )
        endif

        // Target Priority #8
        if (target == null) then
            set target = GetCreepCamp( 16, 100, true )
        endif

    endif
    // Attack the target and increment attack wave
    if (target != null) then
        call AttackTarget( target, setAlly )
        call AttackWaveUpdate(  )
    else
        // If no target was found, sleep a bit before trying again
        call Sleep( 20 )
    endif
endfunction

//===========================================================================
// Determines all attacking assignments
//===========================================================================
function AttackAssignment takes nothing returns nothing
    call StaggerSleep( 0, 2 )
    if (attackWave == 1) then
        call AttackWaveDelay( 0 )
    endif
    loop
        loop
            call UpdateConditions(  )
            exitwhen (HaveMinimumAttackers() and not CaptainRetreating())
            call Sleep( 2 )
        endloop
        call ResetAttackUnits(  )
        call PrepareForces(  )
        call LaunchAttack(  )
    endloop
endfunction

//***************************************************************************
//*
//*  Main Entry Point
//*
//***************************************************************************

//===========================================================================
function main takes nothing returns nothing
    call InitAI(  )
    call InitOptions(  )
    call SelectHeroes(  )
    call CreateCaptains(  )
    call SetHeroLevels( function ChooseHeroSkill )

    call Sleep( 0.1 )
    call StartThread( function WorkerAssignment )
    call StartThread( function AttackAssignment )
    call PlayGame(  )
endfunction
 
Status
Not open for further replies.
Top