• 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.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

[AI] AI wont attack Another AI

Level 8
Joined
Sep 30, 2017
Messages
113
I have a little problem here. Basically, I want Maroon Player to attack Purple Player. Both of them are computers. Whoever Maroon works well with, it builds and replaces units if they die but won't attack at all, purple attack maroon, but maroon always defend and never attack for somereason.

Also, can an AI attack two players? Like, send a wave in 4 minutes to player 1 and send another wave to player 2 after 5 minutes?



JASS:
//============================================================================
//  Chapter05 -- Maroon player -- AI Script
//============================================================================
globals
    player MuPurple = PlayerEx (4) //player 4 Purple
    
    constant integer Peasant = 'h60C'
    constant integer Swordsman = 'h601'
    constant integer Bowman = 'n605'
    constant integer Mage = 'h60X'
    constant integer Catapult = 'o601'
    constant integer Protector = 'h60Y'
    constant integer Paladiness = 'H61I'
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 = 3

    //Building Strategy
    //Tier 1
    call SetBuildUnitEx(7,7,7,Peasant) //Peasant
    call SetBuildUnitEx(1,1,1,'h60I') //Barracks
    call SetBuildUnitEx(2,2,2,'h60O') //Watch Tower
    call SetBuildUnitEx(1,1,1,'h60P') //Guard Tower
    call SetBuildUnitEx(1,1,1,'h60H') //Altar
    call SetBuildUnitEx(1,1,1,'h60J') //Saw Mill
    call SetBuildUnitEx(1,1,1,'h60K') //Blacksmith
    call SetBuildUnitEx(11,11,11,'h60G') //House
    //Tier 2
    call SetBuildUnitEx(1,1,1,'h60L') //Siege Workshop
    call SetBuildUnitEx(1,1,1,'h610') //Tower of Sorceries
    call SetBuildUnitEx(1,1,1,'h60E') //Stronghold
    //Build Units
    call SetBuildUnitEx(5,5,5,Swordsman) //Swordsman
    call SetBuildUnitEx(3,3,3,Bowman) //Bishop
    call SetBuildUnitEx(3,3,3,Mage) //Mage
    call SetBuildUnitEx(2,2,2,Protector) //Protector
    call SetBuildUnitEx(1,1,1,Paladiness) //Paladiness
    //Defenders Units
    call CampaignDefenderEx(3,3,3,Swordsman)  //Swordsman
    call CampaignDefenderEx(2,2,2,Bowman) //Bowman
    call CampaignDefenderEx(1,1,1,Protector) //Protector
    
    call WaitForSignal()

    //Attack Waves

    //Wave 1
    call InitAssaultGroup()
    call CampaignAttackerEx(4,4,4,Swordsman)
    call CampaignAttackerEx(3,3,3,Bowman)
    call CampaignAttackerEx(2,2,2,Mage)
    call SuicideOnPlayerEx(M3,M3,M3,MuPurple)
    
    //Wave 2
    call InitAssaultGroup()
    call CampaignAttackerEx(4,4,4,Swordsman)
    call CampaignAttackerEx(3,3,3,Bowman)
    call CampaignAttackerEx(2,2,2,Protector)
    call CampaignAttackerEx(1,1,1,Paladiness)
    call CampaignAttackerEx(1,1,1,Catapult)
    call SuicideOnPlayerEx(M4,M4,M4,MuPurple)
    
    //Wave 3
    call InitAssaultGroup()
    call CampaignAttackerEx(5,5,5,Swordsman)
    call CampaignAttackerEx(2,2,2,Protector)
    call CampaignAttackerEx(2,2,2,Mage)
    call CampaignAttackerEx(2,2,2,Paladiness)
    call CampaignAttackerEx(1,1,1,Catapult)
    call SuicideOnPlayerEx(M4,M4,M4,MuPurple)
    
    
    loop
        //Wave 5
        call InitAssaultGroup()
        call CampaignAttackerEx(4,4,4,Swordsman)
        call CampaignAttackerEx(3,3,3,Bowman)
        call CampaignAttackerEx(2,2,2,Mage)
        call SuicideOnPlayerEx(M3,M3,M3,MuPurple)
        
        //Wave 7
        call InitAssaultGroup()
        call CampaignAttackerEx(4,4,4,Swordsman)
        call CampaignAttackerEx(3,3,3,Bowman)
        call CampaignAttackerEx(2,2,2,Protector)
        call CampaignAttackerEx(1,1,1,Paladiness)
        call SuicideOnPlayerEx(M4,M4,M4,MuPurple)
        
        //Wave 8
        call InitAssaultGroup()
        call CampaignAttackerEx(5,5,5,Swordsman)
        call CampaignAttackerEx(2,2,2,Protector)
        call CampaignAttackerEx(2,2,2,Mage)
        call CampaignAttackerEx(2,2,2,Paladiness)
        call CampaignAttackerEx(1,1,1,Catapult)
        call SuicideOnPlayerEx(M5,M5,M5,MuPurple)
              
    endloop
endfunction
 
Level 29
Joined
Dec 3, 2020
Messages
1,034
Purple is player 3 in AI scripts :) It's offset by -1 because it starts at 0 for player 1

You can just declare another global for your other target and then launch an attack just like what you're doing right now
Yeah Player 4 Purple is actually player MuPurple = PlayerEx (3) in the AI script as Chaosium says.
Still, I believe it should attack a random enemy even if the indexing is wrong (aka: no valid target to attack).

Script looks valid though so just change that player MuPurple = PlayerEx (4) to ---> player MuPurple = PlayerEx (3)
 
Level 8
Joined
Sep 30, 2017
Messages
113
So i changed the PlayerEX to 3 and then nothing happens, still maroon defend and doesn't send attack waves to purple.

Edited: Tried to set it to attack another AI Computer (Orange) also didn't work and didn't send any attack waves
 
Last edited:
Level 8
Joined
Sep 30, 2017
Messages
113
Lost hope Really, I can't figure out what the problem is, and I'm new to AI scripts. Here is the script for the maroon computer. I just want it to send waves and to attack the orange, purple, and green players if they are alive. If anyone wants to help, please give it a shot. I know you all better than me because I'm lost really.
 

Attachments

  • Chapter05(MaroonPlayerTest).ai
    3.7 KB · Views: 2
Purple is player 3 in AI scripts :) It's offset by -1 because it starts at 0 for player 1

You can just declare another global for your other target and then launch an attack just like what you're doing right now
This is only true when using Player(i). But PlayerEx(i) is a function that is basically Player(i - 1). So purple is PlayerEx(4).

In terms of the attacks. Do you ever send the AI the signal to move past the call WaitForSignal()?
 
Top