• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Campaign A.I not working, don't know why

Status
Not open for further replies.
Level 2
Joined
Jan 22, 2013
Messages
11
Hello readers!

So, for the past week or so I've been going through some JASS to make some A.I for my campaign and I'm using some A.I made by Blizzard as references to see if I'm on the right track with what I want. I have looked up some tutorials and one in particular seemed helpful however the 'helpfulness' was short lived as it just didn't help, sadly.

My script is supposed to be a simple A.I that attacks, leaves defenders and replaces destroyed buildings and units. The A.I doesn't go looking for bases to expand to, even for difficulty reasons since it's not that kind of map. So yeah, easy.

Here's what it looks like.
JASS:
//============================================================================
//highelf 05 -- High Elven Ranger Corps. - Blue
//============================================================================
globals
	player red Player(0)
endglobals  

//============================================================================
//	main
//============================================================================
function main takes nothing returns nothing
        call CampaignAI(ELF_FARM, null)

	set campaign_wood_peons = 5

	call SetReplacements(1,1,3)

        //************************
        //* Building/Defense Strat
        //************************
        
        call SetBuildUnitEx( 2,2,2, PEASANT)
        call SetBuiltUnitEx( 1,2,3, ELF_FARM)
        call SetBuildUnitEx( 0,0,1, ELF_HIGH_BARRACKS)
        call SetBuildUnitEx( 0,1,2, HIGH_GUARD_TOWER)
	call SetBuildUnitEx( 0,0,1, ARCANE_SANCTUM)
	call setBuildUnitEx( 5,5,5, PEASANT)

        call CampaignDefenderEx(4,5,5,HIGH_SWORDSMAN)
        call CampaignDefenderEx(4,5,5,HIGH_ARCHER)
	call CampaignDefenderEx(2,2,3, PRIEST)
	call CampaignDefenderEx(1,1,1, 'H601')
	call CampaignDefenderEx(1,2,2, 'e600')
        //************************
        //* Building/Defense Strat end
	//* Attacking Strat
        //************************
        
        loop
       		//*** WAVE 1 ***
       		call InitAssaultGroup()
       		call CampaignAttackerEx( 4,5,5, HIGH_SWORDSMAN )
       		call CampaignAttackerEx( 3,4,6, HIGH_ARCHER )
   		call CampaignAttackerEx( 1,2,2, PRIEST )
       		call CampaignAttackerEx( 0,1,1, 'e600' )
		call CampaignAttackerEx( 0,1,1, 'H601' )
        	call SuicideOnPlayerEx( M2,M3,M3, red )
        endloop
	//************************
        //* Attacking Strat end
        //************************
endfunction

Here is the reference script from the fifth Undead mission in Reign of Chaos
JASS:
//============================================================================
//  Undead 05 -- blue player -- AI Script
//============================================================================
globals
    player user = Player(3)
endglobals

//============================================================================
//  main
//============================================================================
function main takes nothing returns nothing
    call CampaignAI(ELF_FARM,null)
	set do_campaign_farms = false
	
	call SetReplacements(1,1,3)

    call SetBuildUnitEx( 0,0,1, TOWN_HALL			)
    call SetBuildUnitEx( 2,2,2, PEASANT				)
    call SetBuildUnitEx( 0,0,1, ELF_HIGH_BARRACKS	)
	call SetBuildUnitEx( 0,0,8, ELF_FARM			)
    call SetBuildUnitEx( 5,5,5, PEASANT				)
    
    call CampaignDefenderEx( 1,1,1, HIGH_SWORDMAN   )
    call CampaignDefenderEx( 1,1,1, HIGH_ARCHER     )
	call CampaignDefenderEx( 0,0,1, SORCERESS       )
	call CampaignDefenderEx( 0,0,1, SYLVANUS	    )

    call WaitForSignal()

    //*** WAVE 1 ***
    call InitAssaultGroup()
    call CampaignAttackerEx( 1,1,2, HIGH_SWORDMAN   )
    call CampaignAttackerEx( 2,2,4, HIGH_ARCHER     )
    call SuicideOnPlayer(0,user)

	call SetBuildUpgrEx( 1,1,1, UPG_SORCERY    )
	call SetBuildUpgrEx( 1,1,1, UPG_PRAYING    )

    //*** WAVE 2 ***
    call InitAssaultGroup()
    call CampaignAttackerEx( 1,1,3, HIGH_SWORDMAN   )
    call CampaignAttackerEx( 3,3,3, HIGH_ARCHER     )
    call CampaignAttackerEx( 1,1,1, SYLVANUS        )
    call SuicideOnPlayerEx(M6,M6,M5,user)

	call SetBuildUpgrEx( 1,1,1, UPG_DEFEND			)

    //*** WAVE 3 ***
    call InitAssaultGroup()
    call CampaignAttackerEx( 1,1,4, HIGH_SWORDMAN   )
    call CampaignAttackerEx( 3,3,4, HIGH_ARCHER     )
    call CampaignAttackerEx( 1,1,1, PRIEST          )
	call CampaignAttackerEx( 0,0,1, SORCERESS       )
	call CampaignAttackerEx( 1,1,2, BALLISTA        )
    call SuicideOnPlayerEx(M7,M7,M4,user)

    //*** WAVE 4 ***
    call InitAssaultGroup()
    call CampaignAttackerEx( 4,4,4, HIGH_SWORDMAN   )
    call CampaignAttackerEx( 2,2,4, HIGH_ARCHER     )
    call CampaignAttackerEx( 1,1,1, PRIEST          )
    call CampaignAttackerEx( 1,1,1, SYLVANUS        )
    call SuicideOnPlayerEx(M7,M7,M5,user)

	call SetBuildUpgrEx( 0,0,2, UPG_SORCERY     )
	call SetBuildUpgrEx( 0,0,2, UPG_PRAYING     )

    //*** WAVE 5 ***
    call InitAssaultGroup()
    call CampaignAttackerEx( 3,3,4, HIGH_SWORDMAN   )
    call CampaignAttackerEx( 3,3,4, HIGH_ARCHER     )
    call CampaignAttackerEx( 1,1,2, PRIEST          )
	call CampaignAttackerEx( 0,0,1, SORCERESS       )
    call CampaignAttackerEx( 0,0,1, SYLVANUS        )
	call CampaignAttackerEx( 1,1,1, BALLISTA        )
    call SuicideOnPlayerEx(M6,M6,M4,user)

    loop
        //*** WAVE 6+ ***
        call InitAssaultGroup()
        call CampaignAttackerEx( 2,2,2, HIGH_SWORDMAN)
        call CampaignAttackerEx( 5,5,7, HIGH_ARCHER  )
        call CampaignAttackerEx( 1,1,2, PRIEST       )
		call CampaignAttackerEx( 1,1,1, SORCERESS    )
        call CampaignAttackerEx( 1,1,1, SYLVANUS     )
        call SuicideOnPlayerEx(M7,M7,M5,user)

		//*** WAVE 7+ ***
		call InitAssaultGroup()
		call CampaignAttackerEx( 4,4,4, HIGH_SWORDMAN)
		call CampaignAttackerEx( 2,2,2, HIGH_ARCHER  )
		call CampaignAttackerEx( 3,3,4, PRIEST       )
		call CampaignAttackerEx( 0,0,1, SORCERESS    )
		call CampaignAttackerEx( 1,1,2, BALLISTA     )
		call SuicideOnPlayerEx(M6,M6,M4,user)

		//*** WAVE 8+ ***
		call InitAssaultGroup()
		call CampaignAttackerEx( 2,2,3, HIGH_SWORDMAN)
		call CampaignAttackerEx( 3,3,3, HIGH_ARCHER  )
		call CampaignAttackerEx( 1,1,2, PRIEST       )
		call CampaignAttackerEx( 2,2,2, SORCERESS    )
		call CampaignAttackerEx( 1,1,1, SYLVANUS     )
		call SuicideOnPlayerEx(M7,M7,M5,user)

    endloop
endfunction

Which, to make it easier on me, I cut down to this...
JASS:
//============================================================================
//  Undead 05 -- blue player -- AI Script
//============================================================================
globals
    player user = Player(3)
endglobals

//============================================================================
//  main
//============================================================================
function main takes nothing returns nothing
    call CampaignAI(ELF_FARM,null)
	set do_campaign_farms = false
	
	call SetReplacements(1,1,3)

    call SetBuildUnitEx( 0,0,1, TOWN_HALL			)
    call SetBuildUnitEx( 2,2,2, PEASANT				)
    call SetBuildUnitEx( 0,0,1, ELF_HIGH_BARRACKS	)
	call SetBuildUnitEx( 0,0,8, ELF_FARM			)
    call SetBuildUnitEx( 5,5,5, PEASANT				)
    
    call CampaignDefenderEx( 1,1,1, HIGH_SWORDMAN   )
    call CampaignDefenderEx( 1,1,1, HIGH_ARCHER     )
	call CampaignDefenderEx( 0,0,1, SORCERESS       )
	call CampaignDefenderEx( 0,0,1, SYLVANUS	    )

    loop
		//*** WAVE 8+ ***
		call InitAssaultGroup()
		call CampaignAttackerEx( 2,2,3, HIGH_SWORDMAN)
		call CampaignAttackerEx( 3,3,3, HIGH_ARCHER  )
		call CampaignAttackerEx( 1,1,2, PRIEST       )
		call CampaignAttackerEx( 2,2,2, SORCERESS    )
		call CampaignAttackerEx( 1,1,1, SYLVANUS     )
		call SuicideOnPlayerEx(M7,M7,M5,user)

    endloop
endfunction

Now, the reference scripts (including the one I cut down) work 100% fine and despite the fact my script is pretty identical to them, it doesn't work.
My peasants just mine gold and idle otherwise. Heck, I've even gotten rid of
JASS:
set campaign_wood_peons = 5
set campaign_gold_peons = 4
to see if it'd work and no change.

I was hoping someone here could help me with this issue as it's really starting to annoy me that I can't seem to write my own A.I from scratch, I'd hate and refuse to grab someone elses and edit it for use. A free Tic Tac for anyone that helps out in anyway. :ogre_kawaii:

Thanks in advance and sorry if this is something super simple and I'm just dumb. :ogre_icwydt:
 
Last edited:
Level 2
Joined
Jan 22, 2013
Messages
11
The "set do_campaign_farms = false" is completely unnecessary. Same for the " set campaign_gold_peons = 4". Remove them.
You only need to do that for wood, the rest of the workers will harvest gold anyways.

Yeah, I ended up removing the gold peons due to that, was pointless keeping as you mentioned. I only added the "set do campaign_farms = false" because the reference scripts had them (almost every single one) so I thought I should although I didn't get to find out what it does but yeah, didn't seem to make an effect of any kind no matter how I used or edited the scripts.

Sadly, the problem still remains that it doesn't function at all. :ogre_icwydt:

Thanks anyway for mentioning something on my script.
 
Level 2
Joined
Jan 22, 2013
Messages
11
Yes, my workers can build the structures and the same thing is also happening with an Orc A.I script that looks exactly the same as the one I put here but instead of High Elves, it's Orcs. The script currently up is the last updated version of it so you can use that if you like.
Thanks for helping. ;D
 

Shar Dundred

Community Moderator
Level 72
Joined
May 6, 2009
Messages
5,872
player red Player(0)

Didn't take a closer look before, this line is indeed wrong (Sorry, WaterKnight). It should be like this:

player red = Player(0)

call setBuildUnitEx( 5,5,5, PEASANT)

Capital letter for the set.

call CampaignAttackerEx( 4,5,5, HIGH_SWORSDMAN )

It's HIGH_SWORDMAN.

There were some other mistakes I fixed. Here's the fixed version of your script, should be working now - didn't test it though.

JASS:
globals
    player red = Player(0)
endglobals  

//============================================================================
//  main
//============================================================================
function main takes nothing returns nothing
    call CampaignAI(ELF_FARM, null)
    call SetReplacements(1,1,3)
    set campaign_wood_peons = 5

    //************************
    //* Building/Defense Strat
    //************************
       
    call SetBuildUnitEx( 2,2,2, PEASANT)
    call SetBuildUnitEx( 1,2,3, ELF_FARM)
    call SetBuildUnitEx( 0,0,1, ELF_HIGH_BARRACKS)
    call SetBuildUnitEx( 0,1,2, HIGH_GUARD_TOWER)
    call SetBuildUnitEx( 0,0,1, ARCANE_SANCTUM)
    call SetBuildUnitEx( 9,9,9, PEASANT)

    call CampaignDefenderEx(4,5,5,HIGH_SWORDMAN)
    call CampaignDefenderEx(4,5,5,HIGH_ARCHER)
    call CampaignDefenderEx(2,2,3, PRIEST)
    call CampaignDefenderEx(1,1,1, 'H601')
    call CampaignDefenderEx(1,2,2, 'e600')
        
    //************************
    //* Building/Defense Strat end
    //* Attacking Strat
    //************************
       
    loop
        //*** WAVE 1 ***
        call InitAssaultGroup()
        call CampaignAttackerEx( 4,5,5, HIGH_SWORDMAN )
        call CampaignAttackerEx( 3,4,6, HIGH_ARCHER )
        call CampaignAttackerEx( 1,2,2, PRIEST )
        call CampaignAttackerEx( 0,1,1, 'e600' )
        call CampaignAttackerEx( 0,1,1, 'H601' )
        call SuicideOnPlayerEx(M2,M3,M3,red)
    endloop
    //************************
    //* Attacking Strat end
    //************************
endfunction

Send me the whole map if there are still issues with the AI so I can also take a look at the object and trigger editor.
 
Level 2
Joined
Jan 22, 2013
Messages
11
Oh wow, I thought it'd be some simple, stupid crap. >.<
Embarrassing for someone who's coded in Java for ages.
Anyway, I tested it and sadly, it didn't work, it just did the same thing as last time.
I've sent a pm with a map I made to test A.I with the same units as the original map and the triggers are basically the same as the original map (barely added any since it's not of concern at the moment).

Thanks for finding those spelling errors though and thanks WaterKnight for the syntax thing. xD
 
Last edited:

Shar Dundred

Community Moderator
Level 72
Joined
May 6, 2009
Messages
5,872
Here's the fixed Elf AI.

JASS:
//============================================================================
//highelf 05 -- High Elven Ranger Corps. - Blue
//============================================================================
globals
    player red = Player(0)
endglobals  

//============================================================================
//  main
//============================================================================
function main takes nothing returns nothing
    call CampaignAI(ELF_FARM, null)
    call SetReplacements(1,1,3)
    set campaign_wood_peons = 5

    //************************
    //* Building/Defense Strat
    //************************
       
    call SetBuildUnitEx( 2,2,2, PEASANT)
    call SetBuildUnitEx( 1,2,3, ELF_FARM)
    call SetBuildUnitEx( 0,0,1, ELF_HIGH_BARRACKS)
    call SetBuildUnitEx( 0,1,2, ELF_GUARD_TOWER)
    call SetBuildUnitEx( 0,0,1, ARCANE_SANCTUM)
    call SetBuildUnitEx( 9,9,9, PEASANT)

    call CampaignDefenderEx(4,5,5,HIGH_SWORDMAN)
    call CampaignDefenderEx(4,5,5,HIGH_ARCHER)
    call CampaignDefenderEx(2,2,3, PRIEST)
    //call CampaignDefenderEx(1,1,1, 'H601')
    //call CampaignDefenderEx(1,2,2, 'e600')
       
    //************************
    //* Building/Defense Strat end
    //* Attacking Strat
    //************************
       
    loop
        //*** WAVE 1 ***
        call InitAssaultGroup()
        call CampaignAttackerEx( 4,5,5, HIGH_SWORDMAN )
        call CampaignAttackerEx( 3,4,6, HIGH_ARCHER )
        call CampaignAttackerEx( 1,2,2, PRIEST )
        //call CampaignAttackerEx( 0,1,1, 'e600' )
        //call CampaignAttackerEx( 0,1,1, 'H601' )
        call SuicideOnPlayerEx(M2,M3,M3,red)
    endloop
    //************************
    //* Attacking Strat end
    //************************
endfunction
 
Status
Not open for further replies.
Top