• 🏆 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 AI doesn't start harvesting

Status
Not open for further replies.
Level 13
Joined
Dec 19, 2020
Messages
237
Hello guys,

Recently, i've completed my AI-script in JASS for an enemy custom faction. I've imported it in the World Editor with the import manager. After that, i made a trigger to start the AI-Script (start campaign AI) and i placed the starting units i wanted. Sadly enough, the AI doesn't start harvesting any gold or lumber. I'm wondering if the AI has started at all. Does anyone know what the problem could be/how to fix it?
 
Level 13
Joined
Dec 19, 2020
Messages
237
// -----------------------------------------------------------------
// JASS scripting Demo
// -----------------------------------------------------------------
globals
player user = PlayerEx(1)

constant integer Marshal = 'h00I:Hpb1'
constant integer Civilian Centre = 'h000:htow'
constant integer City Centre = 'h002 hkee'
constant integer Armory = 'h003:hbla'
constant integer Tavern = 'n00V:ntav'
constant integer Worker = 'h004:hpea'
constant integer Militia = 'h001:hmil'
constant integer Reservist = 'n00R:nrog'
constant integer Spearman = 'n00W:nbrg'
constant integer Veteran = 'n00T:nenf'
endglobals

// -----------------------------------------------------------------
// This will call when the AI script runs for the first time.
// -----------------------------------------------------------------
function main takes nothing returns nothing
call CampaignAI (HOUSE)
call SetReplacements (5)
call SetPeonsRepair (true)

call SetBuildUnitEx (1,1,1 Worker)
call SetBuildUnitEx (1,1,1 Civilian Centre)
call SetBuildUnitEx (4,4,4 Armory)
call SetBuildUnitEx (12,12,12 HOUSE)
call SetBuildUnitEx (1,1,1 LUMBER_MILL)
call SetBuildUnitEx (1,1,1 BLACKSMITH)
call SetBuildUnitEx (1,1,1 HUMAN_ALTAR)
call SetBuildUnitEx (1,1,1 City Centre)
call SetBuildUnitEx (3,3,3 Tavern)
call SetBuildUnitEx (12,12,12 Worker)

call CampaignDefenderEx (1,1,1 Marshal)
call CampaignDefenderEx (2,2,2 Veteran)
call CampaignDefenderEx (3,3,3 Spearman)
call CampaignDefenderEx (3,3,3 Reservist)
call CampaignDefenderEx (10,10,10 Militia)

call WaitForSignal ()

//***Wave 1 ***
call InitAssaultGroup()
call CampaignAttackerEx (12,12,12 Militia)
call SuicideOnPlayerEx (M6,M6,M6,User)

//***Wave 2 ***
call InitAssaultGroup()
call CampaignAttackerEx (1,1,1 Marshal)
call CampaignAttackerEx (2,2,2 Veteran)
call CampaignAttackerEx (3,3,3 Reservist)
call CampaignAttackerEx (4,4,4 Spearman)
call SuicideOnPlayerEx (M6,M6,M6,User)

//***Wave 3 ***
loop
call InitAssaultGroup()
call CampaignAttackerEx (12,12,12 Militia)
call SuicideOnPlayerEx (M6,M6,M6,User)

call InitAssaultGroup()
call CampaignAttackerEx (1,1,1 Marshal)
call CampaignAttackerEx (2,2,2 Veteran)
call CampaignAttackerEx (3,3,3 Reservist)
call CampaignAttackerEx (4,4,4 Spearman)
call SuicideOnPlayerEx (M6,M6,M6,User)
endloop
endfunction
 
Last edited:
Level 28
Joined
Feb 18, 2014
Messages
3,579
There are two issues in your AI variables (globals) which prevents it from working:

1 - Unit ID : A unit's id cannot have more than 4 characters. When referring a custom unit in a variable, you don't have to include the base unit's id,, so instead of writing 'h001:Hpb1' write 'h001' directly.

JASS:
constant integer Marshal = 'h00I'

2 - Space: You cannot use space in variables, use "_" instead.

JASS:
constant integer Civilian_Centre = 'h000'
 
Level 13
Joined
Dec 19, 2020
Messages
237
There are two issues in your AI variables (globals) which prevents it from working:

1 - Unit ID : A unit's id cannot have more than 4 characters. When referring a custom unit in a variable, you don't have to include the base unit's id,, so instead of writing 'h001:Hpb1' write 'h001' directly.

JASS:
constant integer Marshal = 'h00I'

2 - Space: You cannot use space in variables, use "_" instead.

JASS:
constant integer Civilian_Centre = 'h000'


Thanks (again). I will change my script later today. I will let you know if it solves the problem.
 
Level 12
Joined
Feb 5, 2018
Messages
521
I tried your recommandation yesterday with the BB Code Editor but it doesn't seem to have worked. Apparently, i'm doing something wrong but i don''t know what.

You can put [.Jass] text [./Jass] when you post scripts or [.Code] text [./code] without the dots.
 
Level 13
Joined
Dec 19, 2020
Messages
237
There are two issues in your AI variables (globals) which prevents it from working:

1 - Unit ID : A unit's id cannot have more than 4 characters. When referring a custom unit in a variable, you don't have to include the base unit's id,, so instead of writing 'h001:Hpb1' write 'h001' directly.

JASS:
constant integer Marshal = 'h00I'

2 - Space: You cannot use space in variables, use "_" instead.

JASS:
constant integer Civilian_Centre = 'h000'


Well, I've tested it after i changed the codes. It's still not working. Do you know any other solution or are you having an idea of what the problem could be?
 
Level 28
Joined
Feb 18, 2014
Messages
3,579
I just realized there were other problems like missing commas and invalid arguments. Anyway, I fixed them and it should work fine now.
JASS:
// -----------------------------------------------------------------
// JASS scripting Demo
// -----------------------------------------------------------------
globals
player user = PlayerEx(1)

constant integer Marshal = 'h00I'
constant integer Civilian_Centre = 'h000'
constant integer City_Centre = 'h002'
constant integer Armory = 'h003'
constant integer Tavern = 'n00V'
constant integer Worker = 'h004'
constant integer Militia = 'h001'
constant integer Reservist = 'n00R'
constant integer Spearman = 'n00W'
constant integer Veteran = 'n00T'
endglobals

// -----------------------------------------------------------------
// This will call when the AI script runs for the first time.
// -----------------------------------------------------------------
function main takes nothing returns nothing
call CampaignAI (HOUSE,null)
call SetReplacements (5,5,5)
call SetPeonsRepair (true)

call SetBuildUnitEx (1,1,1, Worker)
call SetBuildUnitEx (1,1,1, Civilian_Centre)
call SetBuildUnitEx (4,4,4, Armory)
call SetBuildUnitEx (12,12,12, HOUSE)
call SetBuildUnitEx (1,1,1, LUMBER_MILL)
call SetBuildUnitEx (1,1,1, BLACKSMITH)
call SetBuildUnitEx (1,1,1, HUMAN_ALTAR)
call SetBuildUnitEx (1,1,1, City_Centre)
call SetBuildUnitEx (3,3,3, Tavern)
call SetBuildUnitEx (12,12,12, Worker)

call CampaignDefenderEx (1,1,1, Marshal)
call CampaignDefenderEx (2,2,2, Veteran)
call CampaignDefenderEx (3,3,3, Spearman)
call CampaignDefenderEx (3,3,3, Reservist)
call CampaignDefenderEx (10,10,10, Militia)

call WaitForSignal ()

//***Wave 1 ***
call InitAssaultGroup()
call CampaignAttackerEx (12,12,12, Militia)
call SuicideOnPlayerEx (M6,M6,M6,user)

//***Wave 2 ***
call InitAssaultGroup()
call CampaignAttackerEx (1,1,1, Marshal)
call CampaignAttackerEx (2,2,2, Veteran)
call CampaignAttackerEx (3,3,3, Reservist)
call CampaignAttackerEx (4,4,4, Spearman)
call SuicideOnPlayerEx (M6,M6,M6,user)

//***Wave 3 ***
loop
call InitAssaultGroup()
call CampaignAttackerEx (12,12,12, Militia)
call SuicideOnPlayerEx (M6,M6,M6,user)

call InitAssaultGroup()
call CampaignAttackerEx (1,1,1, Marshal)
call CampaignAttackerEx (2,2,2, Veteran)
call CampaignAttackerEx (3,3,3, Reservist)
call CampaignAttackerEx (4,4,4, Spearman)
call SuicideOnPlayerEx (M6,M6,M6,user)
endloop
endfunction
I highly recommand using JASS Syntax Checker 0.1.7 when writing your ai scripts, it will help you identify all the issues in them.
 
Level 13
Joined
Dec 19, 2020
Messages
237
I just realized there were other problems like missing commas and invalid arguments. Anyway, I fixed them and it should work fine now.
JASS:
// -----------------------------------------------------------------
// JASS scripting Demo
// -----------------------------------------------------------------
globals
player user = PlayerEx(1)

constant integer Marshal = 'h00I'
constant integer Civilian_Centre = 'h000'
constant integer City_Centre = 'h002'
constant integer Armory = 'h003'
constant integer Tavern = 'n00V'
constant integer Worker = 'h004'
constant integer Militia = 'h001'
constant integer Reservist = 'n00R'
constant integer Spearman = 'n00W'
constant integer Veteran = 'n00T'
endglobals

// -----------------------------------------------------------------
// This will call when the AI script runs for the first time.
// -----------------------------------------------------------------
function main takes nothing returns nothing
call CampaignAI (HOUSE,null)
call SetReplacements (5,5,5)
call SetPeonsRepair (true)

call SetBuildUnitEx (1,1,1, Worker)
call SetBuildUnitEx (1,1,1, Civilian_Centre)
call SetBuildUnitEx (4,4,4, Armory)
call SetBuildUnitEx (12,12,12, HOUSE)
call SetBuildUnitEx (1,1,1, LUMBER_MILL)
call SetBuildUnitEx (1,1,1, BLACKSMITH)
call SetBuildUnitEx (1,1,1, HUMAN_ALTAR)
call SetBuildUnitEx (1,1,1, City_Centre)
call SetBuildUnitEx (3,3,3, Tavern)
call SetBuildUnitEx (12,12,12, Worker)

call CampaignDefenderEx (1,1,1, Marshal)
call CampaignDefenderEx (2,2,2, Veteran)
call CampaignDefenderEx (3,3,3, Spearman)
call CampaignDefenderEx (3,3,3, Reservist)
call CampaignDefenderEx (10,10,10, Militia)

call WaitForSignal ()

//***Wave 1 ***
call InitAssaultGroup()
call CampaignAttackerEx (12,12,12, Militia)
call SuicideOnPlayerEx (M6,M6,M6,user)

//***Wave 2 ***
call InitAssaultGroup()
call CampaignAttackerEx (1,1,1, Marshal)
call CampaignAttackerEx (2,2,2, Veteran)
call CampaignAttackerEx (3,3,3, Reservist)
call CampaignAttackerEx (4,4,4, Spearman)
call SuicideOnPlayerEx (M6,M6,M6,user)

//***Wave 3 ***
loop
call InitAssaultGroup()
call CampaignAttackerEx (12,12,12, Militia)
call SuicideOnPlayerEx (M6,M6,M6,user)

call InitAssaultGroup()
call CampaignAttackerEx (1,1,1, Marshal)
call CampaignAttackerEx (2,2,2, Veteran)
call CampaignAttackerEx (3,3,3, Reservist)
call CampaignAttackerEx (4,4,4, Spearman)
call SuicideOnPlayerEx (M6,M6,M6,user)
endloop
endfunction
I highly recommand using JASS Syntax Checker 0.1.7 when writing your ai scripts, it will help you identify all the issues in them.


Thanks again! I will test the improved script later today. Also thanks for the recommandation. I will look into it. One thing i'm wondering about is the preplacement of the workers. Can it do any harm if i place the workers beforehand (so the AI doesn't have to train them the first time?)
 
Level 13
Joined
Dec 19, 2020
Messages
237
I just realized there were other problems like missing commas and invalid arguments. Anyway, I fixed them and it should work fine now.
JASS:
// -----------------------------------------------------------------
// JASS scripting Demo
// -----------------------------------------------------------------
globals
player user = PlayerEx(1)

constant integer Marshal = 'h00I'
constant integer Civilian_Centre = 'h000'
constant integer City_Centre = 'h002'
constant integer Armory = 'h003'
constant integer Tavern = 'n00V'
constant integer Worker = 'h004'
constant integer Militia = 'h001'
constant integer Reservist = 'n00R'
constant integer Spearman = 'n00W'
constant integer Veteran = 'n00T'
endglobals

// -----------------------------------------------------------------
// This will call when the AI script runs for the first time.
// -----------------------------------------------------------------
function main takes nothing returns nothing
call CampaignAI (HOUSE,null)
call SetReplacements (5,5,5)
call SetPeonsRepair (true)

call SetBuildUnitEx (1,1,1, Worker)
call SetBuildUnitEx (1,1,1, Civilian_Centre)
call SetBuildUnitEx (4,4,4, Armory)
call SetBuildUnitEx (12,12,12, HOUSE)
call SetBuildUnitEx (1,1,1, LUMBER_MILL)
call SetBuildUnitEx (1,1,1, BLACKSMITH)
call SetBuildUnitEx (1,1,1, HUMAN_ALTAR)
call SetBuildUnitEx (1,1,1, City_Centre)
call SetBuildUnitEx (3,3,3, Tavern)
call SetBuildUnitEx (12,12,12, Worker)

call CampaignDefenderEx (1,1,1, Marshal)
call CampaignDefenderEx (2,2,2, Veteran)
call CampaignDefenderEx (3,3,3, Spearman)
call CampaignDefenderEx (3,3,3, Reservist)
call CampaignDefenderEx (10,10,10, Militia)

call WaitForSignal ()

//***Wave 1 ***
call InitAssaultGroup()
call CampaignAttackerEx (12,12,12, Militia)
call SuicideOnPlayerEx (M6,M6,M6,user)

//***Wave 2 ***
call InitAssaultGroup()
call CampaignAttackerEx (1,1,1, Marshal)
call CampaignAttackerEx (2,2,2, Veteran)
call CampaignAttackerEx (3,3,3, Reservist)
call CampaignAttackerEx (4,4,4, Spearman)
call SuicideOnPlayerEx (M6,M6,M6,user)

//***Wave 3 ***
loop
call InitAssaultGroup()
call CampaignAttackerEx (12,12,12, Militia)
call SuicideOnPlayerEx (M6,M6,M6,user)

call InitAssaultGroup()
call CampaignAttackerEx (1,1,1, Marshal)
call CampaignAttackerEx (2,2,2, Veteran)
call CampaignAttackerEx (3,3,3, Reservist)
call CampaignAttackerEx (4,4,4, Spearman)
call SuicideOnPlayerEx (M6,M6,M6,user)
endloop
endfunction
I highly recommand using JASS Syntax Checker 0.1.7 when writing your ai scripts, it will help you identify all the issues in them.


Well, i've checked your version of the AI-script with the JASS Syntax Checker 0.1.7. It says there are no errors. After that i've imported the file and placed it with a trigger. It still doesn't work. I'm growing a little desperate right know. Do you know any other reasons why it is not working?

  • AI - Start campaign AI script for Player 12 (Brown): war3mapImported\Local Militia Definitive .ai[trigger]
 
Level 28
Joined
Feb 18, 2014
Messages
3,579
Well, i've checked your version of the AI-script with the JASS Syntax Checker 0.1.7. It says there are no errors. After that i've imported the file and placed it with a trigger. It still doesn't work. I'm growing a little desperate right know. Do you know any other reasons why it is not working?

  • AI - Start campaign AI script for Player 12 (Brown): war3mapImported\Local Militia Definitive .ai[trigger]
That's very odd. Are you sure the player is controlled by a computer? Does the AI do some thing like harvesting or nothing at all? I don't know if it's because of the "space" but try adding space before every actions like in this example :
[AI] - Campaign AI Thingy
If it still doesn't work, then it will be best if you upload a test map so we can take a look at it.
 
Level 13
Joined
Dec 19, 2020
Messages
237
That's very odd. Are you sure the player is controlled by a computer? Does the AI do some thing like harvesting or nothing at all? I don't know if it's because of the "space" but try adding space before every actions like in this example :
[AI] - Campaign AI Thingy
If it still doesn't work, then it will be best if you upload a test map so we can take a look at it.

I´ve checked the player properties. The player (brown in this case) is controlled by a computer. I've also added space in the script and tested it. The AI still does nothing at all. They just sit and wait. I've also removed this trigger to see if it helped. It did not.
  • Melee Game - Run melee AI scripts (for computer players)

It would be great if you could take a look at my map. I've uploaded it so you can have a look for yourself. The brown base is the base where the AI is supposed to work.The AI script is already uploaded in the import manager and the trigger editor.
 

Attachments

  • Map voor AI Test.w3x
    224.6 KB · Views: 33
Level 28
Joined
Feb 18, 2014
Messages
3,579
I´ve checked the player properties. The player (brown in this case) is controlled by a computer. I've also added space in the script and tested it. The AI still does nothing at all. They just sit and wait. I've also removed this trigger to see if it helped. It did not.
  • Melee Game - Run melee AI scripts (for computer players)

It would be great if you could take a look at my map. I've uploaded it so you can have a look for yourself. The brown base is the base where the AI is supposed to work.The AI script is already uploaded in the import manager and the trigger editor.
Okay I checked your map and I finally found what's wrong.

The problem is not in the AI but in Scenario --> Force Properties. You forgot to check "Fixed Player Settings" box.

untitled-jpg.370767


I think the reason why the AI doesn't start when Fixed Player Settings is unchecked is because he doesn't recognize the race of the player as if it was random.
 

Attachments

  • untitled.JPG
    untitled.JPG
    43.8 KB · Views: 104
Level 13
Joined
Dec 19, 2020
Messages
237
Okay I checked your map and I finally found what's wrong.

The problem is not in the AI but in Scenario --> Force Properties. You forgot to check "Fixed Player Settings" box.

untitled-jpg.370767


I think the reason why the AI doesn't start when Fixed Player Settings is unchecked is because he doesn't recognize the race of the player as if it was random.


Well, it is finally working! Thanks a lot! The only thing what happens now is that the AI cannot replace their units very fast because they are harvesting 1 gold at a time. Is it normal that they start with this handicap? Otherwise i have to search for a solution.
 
Level 28
Joined
Feb 18, 2014
Messages
3,579
Well, it is finally working! Thanks a lot! The only thing what happens now is that the AI cannot replace their units very fast because they are harvesting 1 gold at a time. Is it normal that they start with this handicap? Otherwise i have to search for a solution.
If you want the AI to harvest normally add this to your script
JASS:
call SetSlowChopping(false)
Otherwise, you can give it more gold at the start or periodically add gold to it.
  • Trigger
    • Events
      • Time - Every 15.00 seconds of game time
    • Conditions
    • Actions
      • Player - Add 1000 to Player 12 (Brown) Current gold
 
Level 13
Joined
Dec 19, 2020
Messages
237
If you want the AI to harvest normally add this to your script
JASS:
call SetSlowChopping(false)
Otherwise, you can give it more gold at the start or periodically add gold to it.
  • Trigger
    • Events
      • Time - Every 15.00 seconds of game time
    • Conditions
    • Actions
      • Player - Add 1000 to Player 12 (Brown) Current gold

Thanks! The AI is almost working as if it is Warcraft 3! There are only two new problems showing up. First, the AI does train the required units for an attack wave, but does not always send all the required units. For example, i want an AI to attack with 4 Siege Engines. It trains 4 Siege Engines, but it sends only three of them. The last one remains behind, while it is not part of the defense group. The second problem is that the AI doesn't send my custom hero to attack, while it is ordered to do so. It doesn't seem to be a problem in the script, but i don't know what it else could be. Do you know where i can find for an solution for these problems?
 
Level 12
Joined
Feb 5, 2018
Messages
521
The second problem is that the AI doesn't send my custom hero to attack, while it is ordered to do so. It doesn't seem to be a problem in the script, but i don't know what it else could be. Do you know where i can find for an solution for these problems?

Try adding the custom Hero to the Hero list found in Advanced --> Gameplay Constants. IIRC custom heroes should be added to the list.
 
Level 13
Joined
Dec 19, 2020
Messages
237
Try adding the custom Hero to the Hero list found in Advanced --> Gameplay Constants. IIRC custom heroes should be added to the list.

Well i've added my custom hero's to the hero's list. Sadly, it doesn't work. At the moment i am having six custom heroes. Three of them are working fine. They join the attack waves when ordered to. Two others are only joining the first attack wave. after that, they are not revived. The last hero does nothing at all. He is just sitting there and waiting for the game to end. Do you know what the cause of this difference could be?
 
Level 28
Joined
Feb 18, 2014
Messages
3,579
First, the AI does train the required units for an attack wave, but does not always send all the required units. For example, i want an AI to attack with 4 Siege Engines. It trains 4 Siege Engines, but it sends only three of them. The last one remains behind, while it is not part of the defense group
I think that's because the time between the attack launch and unit training is not enough. Let's say you want the AI to send 10 knight after 2 minutes, when those two minutes passes, the AI will start training those knights or pick those who already exist and wait a few seconds before launching the attack. So if the AI hasn't been able to train all the 10 knights, he will simply go without them. My suggestion is either reduce the seige engine training time or build more barracks so the AI won't have to train everything in the same building.
 
Level 13
Joined
Dec 19, 2020
Messages
237
I think that's because the time between the attack launch and unit training is not enough. Let's say you want the AI to send 10 knight after 2 minutes, when those two minutes passes, the AI will start training those knights or pick those who already exist and wait a few seconds before launching the attack. So if the AI hasn't been able to train all the 10 knights, he will simply go without them. My suggestion is either reduce the seige engine training time or build more barracks so the AI won't have to train everything in the same building.

Thanks for the tip. Luckily, the problem hasn't happened again. The AI is working fine at the moment (except for my little problem with the hero's-iguess i'll have to experiment with it)
 
Status
Not open for further replies.
Top