HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Why does my campaign AI script not work?

06-29-2006, 03:40 AM#1
Sardius
I based my campaign AI script roughly off one of the official campaign AI scripts for a computer controlled enemy orc base in my map.

The trigger I use to start the AI is the same as the official campaign does it.

AI - Start campaign AI script for Player 6 (Orange): 01_Orange1.ai
AI - Send Player 6 (Orange) the AI Command (0, 0)

Every campaign level of the official campaign uses this trigger to initiate its AI.

I have imported my script 01_Orange1.ai and removed the war3mapimported/ dir.

I have ran the Jass check, and the script is fine aside for what it calls "unreckonized variables" But that is just the raw data code for a custom hero on my map.

Part of the script can be seen below. But the script simply doesn't seem to do anything, the only enemy units that are doing anything since I imported the script the only enemy units that become active are peons, who are mining gold. Everyothing else just sits there, and no units are produced.

Collapse JASS:
globals
    player user = Player(1)
endglobals

//============================================================================
//  main
//============================================================================
function main takes nothing returns nothing
    call CampaignAI(BURROW,null)
    call SetReplacements(1,2,4)

    call SetBuildUnitEx    ( 1,1,1, GREAT_HALL            )
    call SetBuildUnit    ( 6, PEON                    )    
    call SetBuildUnitEx    ( 1,1,1, ORC_BARRACKS        )
    call SetBuildUnitEx    ( 1,1,1, FORGE                )
    call SetBuildUnitEx    ( 1,1,1, STRONGHOLD            )
    call SetBuildUnitEx    ( 1,1,1, ORC_ALTAR            )
    call SetBuildUnitEx    ( 1,1,1, LODGE                )
    call SetBuildUnitEx    ( 1,1,1, BESTIARY            )
    call SetBuildUnitEx    ( 1,1,1, FORTRESS            )

    call CampaignDefenderEx( 1,1,1, GRUNT            )
    call CampaignDefenderEx( 0,0,1, HEAD_HUNTER        )
    call CampaignDefenderEx( 1,1,1, SHAMAN            )
    call CampaignDefenderEx( 1,1,1, WITCH_DOCTOR    )
    call CampaignDefenderEx( 1,1,1, GROM    )
    call CampaignDefenderEx( 1,1,1, O00D    )

    call WaitForSignal()

    //*** WAVE 1 ***
    call InitAssaultGroup()
    call CampaignAttackerEx( 4,4,4, GRUNT            )
    call CampaignAttackerEx( 3,3,3, WYVERN        )
    call SuicideOnPlayerEx(M3,M3,M2,user)

    //*** WAVE 2 ***
    call InitAssaultGroup()
    call CampaignAttackerEx( 2,2,3, GRUNT            )
    call CampaignAttackerEx( 2,2,3, SHAMAN            ) 
    call CampaignAttackerEx( 4,4,4, O00D            )
    call SuicideOnPlayerEx(M4,M4,M4,user)

EDIT:

OK well it appears I just forgot the ' ' around my O00D, once I added those in my AI script came to life. Yet it doesn't seem to be working completely as intended, the attack waves do trigger and work. But they also appear to be constructing other units that aren't included in the "AttackerEx" and these units, insantly leave the base upon being trained and seem to go off instantly into battle. Any idea why that would be happening? Its almost like it sending its Defenders right off into battle, rather then staying at the base.

Do I need to to do something to manually set their "defending" point.
06-29-2006, 12:07 PM#2
moyack
I recommend to create your AI from scratch with the AI editor, in that way, you can control how many defenders will you have, the attack waves, etc.
06-29-2006, 05:07 PM#3
Sardius
Err, I can easily control that the way I'm doing it. The campaign AI scripts are quite simplistic, my problem seems to be at the moment that all the "Defenders" leave the base the second they are created, as if their trying to defend a point other then the base.
06-29-2006, 05:30 PM#4
moyack
Well, I'm good with the AI editor I was trying to understand what means the arguments in the function SuicideOnPlayerEx(Mx,Mx,Mx,user). What is Mx?

I have the feeling that is in that part of this function where the bug happens.
06-29-2006, 06:05 PM#5
Sardius
That is the minutes that pass buy before that wave initiates... M3 means, after 3 minutes initiate attack wave...

This is the method used by all campaign AI scripts... Build up the attack wave over that duration and then initiate the attack... My attack waves work flawlessly as intended...

Its my "CallDefender" Whenever the enemy base produces its defenders, they don't seem to know that they are in their base, because the immedietly leave and head for an entirly different location on the map, no where near their base.

My attack waves work fine, its my defenders thats the problem.
06-29-2006, 09:57 PM#6
moyack
Hey!! I'm learning a lot of things about writing directly the AI, I'm happy!!

I've browsed the web and I found an strategy that has a build plan, a defense plan and a attack plan. At least it help me a lot to understand the AI code. I compared your AI with this code, and there is no such difference in the function order (I assume that the order is important). I'll post you if you can find something unusual. If you see it, please tell me, I'm very interest in learn more of this kind of script.

Collapse JASS:
//============================================================================
// $Id: h01x05.ai,v 1.8 2003/04/29 00:26:32 rpardo Exp $
//============================================================================
globals
player sylvie = PlayerEx(5)
endglobals

//============================================================================
// main
//============================================================================
function main takes nothing returns nothing
call CampaignAI(ZIGGURAT_1,null)
call SetReplacements(6,6,8)
set campaign_wood_peons = 3

call SetBuildUnitEx( 1, 1, 1, ACOLYTE )
call SetBuildUnitEx( 1, 1, 1, NECROPOLIS_1 )
call SetBuildUnitEx( 2, 2, 1, CRYPT )
call SetBuildUnitEx( 5, 5, 5, ZIGGURAT_1 )
call SetBuildUnitEx( 1, 1, 1, GRAVEYARD )
call SetBuildUnitEx( 1, 1, 1, UNDEAD_ALTAR )
call SetBuildUnitEx( 1, 1, 0, NECROPOLIS_2 )
call SetBuildUnitEx( 1, 1, 1, DAMNED_TEMPLE )
call SetBuildUnitEx( 4, 4, 4, ZIGGURAT_2 )
call SetBuildUnitEx( 1, 1, 1, SLAUGHTERHOUSE )
call SetBuildUnitEx( 1, 1, 1, SAC_PIT )
call SetBuildUnitEx( 1, 1, 0, NECROPOLIS_3 )
call SetBuildUnitEx( 5, 5, 5, ACOLYTE )

call CampaignDefenderEx( 1, 1, 1, GHOUL )
call CampaignDefenderEx( 1, 1, 1,OBS_STATUE )
call CampaignDefenderEx( 1, 1, 1, CRYPT_FIEND )
call CampaignDefenderEx( 2, 2, 1, BANSHEE )
call CampaignDefenderEx( 2, 2, 1, NECRO )

call SetBuildUpgrEx( 1,1,1, UPG_FIEND_WEB )
call SetBuildUpgrEx( 1,1,1, UPG_EXHUME )
call SetBuildUpgrEx( 1,1,0, UPG_SKEL_MASTERY )
call SetBuildUpgrEx( 1,1,0, UPG_NECROS )
call SetBuildUpgrEx( 1,1,0, UPG_BANSHEE )
call SetBuildUpgrEx( 1,1,1, UPG_SKEL_LIFE )

call WaitForSignal()

//*** WAVE 1 ***
call InitAssaultGroup()
call CampaignAttackerEx( 6,6,4, GHOUL )
call CampaignAttackerEx( 4,4,2, NECRO )
call CampaignAttackerEx( 4,4,2, BANSHEE )
call SuicideOnPlayerEx(M2,M2,M3,sylvie)

call SetBuildUpgrEx( 1,1,1, UPG_UNHOLY_STR )
call SetBuildUpgrEx( 1,1,1, UPG_CR_ATTACK )

//*** WAVE 2 ***
call InitAssaultGroup()
call CampaignAttackerEx( 4,4,4 CRYPT_FIEND)
call CampaignAttackerEx( 2,2,2, ABOMINATION )
call CampaignAttackerEx( 3,3,2, NECRO )
call SuicideOnPlayerEx(M3,M3,M5,sylvie)

call SetBuildUpgrEx( 1,1,1, UPG_UNHOLY_ARMOR)
call SetBuildUpgrEx( 1,1,1, UPG_CR_ARMOR )
call SetBuildUpgrEx( 1,1,1, UPG_NECROS )
call SetBuildUpgrEx( 1,1,1, UPG_BANSHEE )

//*** WAVE 3 ***
call InitAssaultGroup()
call CampaignAttackerEx( 7,7,5, GHOUL )
call CampaignAttackerEx( 2,2,1, MEAT_WAGON )
call CampaignAttackerEx( 4,4,3, GARGOYLE )
call CampaignAttackerEx( 4,4,3, NECRO )
call CampaignAttackerEx( 4,4,3, BANSHEE )
call SuicideOnPlayerEx(M3,M3,M5,sylvie)

//*** WAVE 4 ***
call InitAssaultGroup()
call CampaignAttackerEx( 7,7,5, GHOUL )
call CampaignAttackerEx( 4,4,4, ABOMINATION )
call CampaignAttackerEx( 5,5,4, CRYPT_FIEND)
call CampaignAttackerEx( 3,3,2, BANSHEE )
call SuicideOnPlayerEx(M3,M3,M5,sylvie)

call SetBuildUpgrEx( 2,2,2, UPG_UNHOLY_STR )
call SetBuildUpgrEx( 2,2,2, UPG_CR_ATTACK )

//*** WAVE 5 ***
call InitAssaultGroup()
call CampaignAttackerEx( 4,4,5, GHOUL )
call CampaignAttackerEx( 2,2,2, MEAT_WAGON)
call CampaignAttackerEx( 6,6,5, CRYPT_FIEND)
call CampaignAttackerEx( 3,3,2, NECRO )
call SuicideOnPlayerEx(M3,M3,M5,sylvie)

call SetBuildUpgrEx( 2,2,2, UPG_UNHOLY_ARMOR)
call SetBuildUpgrEx( 2,2,2, UPG_CR_ARMOR )

//*** WAVE 6 ***
call InitAssaultGroup()
call CampaignAttackerEx( 5,5,7, GHOUL )
call CampaignAttackerEx( 4,4,3, GARGOYLE )
call CampaignAttackerEx( 3,3,4, BANSHEE )
call SuicideOnPlayerEx(M3,M3,M5,sylvie)

//*** WAVE 7+ ***
loop
call InitAssaultGroup()
call CampaignAttackerEx( 7,7,5, NECRO )
call CampaignAttackerEx( 6,6,4, CRYPT_FIEND)
call CampaignAttackerEx( 2,2,2, MEAT_WAGON)
call SuicideOnPlayerEx(M3,M3,M5,sylvie)

call InitAssaultGroup()
call CampaignAttackerEx( 5,5,7, GHOUL )
call CampaignAttackerEx( 4,4,3, ABOMINATION )
call CampaignAttackerEx( 6,6,4, GARGOYLE )
call CampaignAttackerEx( 4,4,3, BANSHEE )
call SuicideOnPlayerEx(M5,M5,M3,sylvie)

call InitAssaultGroup()
call InitAssaultGroup()
call CampaignAttackerEx( 7,7,7, GHOUL )
call CampaignAttackerEx( 4,4,4, CRYPT_FIEND)
call CampaignAttackerEx( 4,4,3, BANSHEE )
call CampaignAttackerEx( 3,3,2, NECRO )
call SuicideOnPlayerEx(M5,M5,M3,sylvie)
endloop
endfunction
06-30-2006, 01:00 AM#7
Sardius
Yah thats the same style as my AI script... Onlything I don't understand about em, is

Collapse JASS:
function main takes nothing returns nothing
call CampaignAI(ZIGGURAT_1,null)
call SetReplacements(6,6,8)]

Not sure what thats intended to, unless thats just the farm type they use and how many they are suppose to have at the least?

But at any rate, as I said, my Defender's are not defending their base as they normally would... Instead they send them all away... I am not sure if this has anything to do with my script... Or the map settings, or the trigger itself...

But I have copied the campaign's method of doing it exactly, not sure why it isn't working out for me.
06-30-2006, 01:55 PM#8
moyack
Collapse JASS:
call CampaignAI(ZIGGURAT_1,null)
I found that instruction is for setting the race houses, and in the null part you set the hero Id (in that AI, no hero is trained, is for that reason that they use null). Honestly I'm not sure about the hero, but I'll ckeck it later.

Collapse JASS:
call SetReplacements(6,6,8)
This function determines how often the AI will replace their fallen units defending the base. So on easy they will replace once, medium twice, and hard three times.
06-30-2006, 06:08 PM#9
Sardius
Well do I need to define anything to set up the area that they are suppose to defend?

Like a region? a trigger? a property?

Cause I am using fixed player settings as suggested and fixed starting locations, I have insured that their starting location is at their main Fortress and when browsing through the triggers and properties of the campaign maps I can see absolutly no triggers, regions or properties that define the area there defenders, defend... The campaign maps also used fixed player settings and fixed starting locations.

Basicly exactly what is happening is all the defender units are moving to the location of an event just outside a base who is allied with the user... There is a gate, a few towers and a few pally units... Just outside the gate of the user's ally base are about a dozen hidden pre placed enemy units "same player as my ai script" These units unhide after the player activates a certain trigger.

All the defenders are heading right for that location, as if trying to meet up with the hidden units there... Because once they get there, they stop entirly and hang out, as if thats the location they're trying to defend. If I delete these hidden units, then the problem goes away and they defend their base as intended.
06-30-2006, 07:23 PM#10
moyack
Probably the hidden allies are affecting your AI behavior because part of the defenders function is to give help to the "weakest" ally units, and, if they're hide and can see the enemy but can't react, the AI will send backup to that point in order to defend the inmovile units.

I think that is in that point the bug. I don't know if you can set the units as neutral passive, until the respective trigger gets active. This night I'll prove your AI in a map, and the AI that I found, in order to see how they react. Any ideas I'll post inmediately.
06-30-2006, 08:11 PM#11
Sardius
Naw, just switched em over to another player and changed their color and name to match and the problem is corrected... Now it works fine... Only thing I need to try to do now is get the AI for transport ships to work right... The other ships work fine, transports are a bit wierd.

Also this, set replacement thing,

call SetReplacements(1,1,3)

What does it replace? Like pre-set units that you've already placed on the map get replaced upon their death? Seperate from Defenders and Attackers?

And do you have any idea what this does?

set do_campaign_farms = false
06-30-2006, 08:30 PM#12
moyack
That function replaces the fallen defenders units, (1,1,3) = oce in easy and normal, and three times in difficult mode.
06-30-2006, 08:44 PM#13
Sardius
Are you sure? Because if you remove that entirly they still replace their defender units...

CallDefenderEx will always replace a defender as soon as it dies.

For example if you have.

call CampaignDefenderEx( 1,1,1, CHAOS_RAIDER )

Then as soon as that unit dies they will build another one to replace it, this doesn't seem to have anything to do with the Set Replacements value.
07-01-2006, 01:25 PM#14
moyack
mmm... really??? well, to be honest I've never removed this instruction and see what happens. I'll test this too.
07-01-2006, 05:10 PM#15
Sardius
Well I noticed when I removed this command, that the enemy would replace ANY lost unit on the map that was pre-placed... Like that group of pre-set units outside the town, when they were wiped out the enemy would constantly said replacement units to that position, same unit type and same position.