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

How to make AI build a unit like a structure

Status
Not open for further replies.
Level 28
Joined
Dec 3, 2020
Messages
970
As mentioned, how can I make the AI build a unit such as the Battle Golem? I made it mechanical, and I as the player can build it... but the AI does not build it even though I put the unit inside an attack wave in JASS.
Unless I have to issue a build order through an action in a trigger, telling to to build that unit?
 
Level 28
Joined
Dec 3, 2020
Messages
970
Call SetBuildUnit() I think is what you'll want. The AI will train units for its attack waves but if the unit is built like a building you'll need to order it to build it before the attack wave.
Woah thanks!
Do I do it before the actual attack, and then call the unit like normal in the attack?
Or do I put it after the call InitAssaultGroup() but before the call CampaignAttackerEx( 2,2,4, WAR_GOLEM ) ?
 
Probably best to put it at the start, I'm assuming they have defensive units pre-placed? If so do a

Call SetBuildUnitEx(1,2,3,'hfoo')

for every defender unit and the computer will replace them infinitely if they're killed. That example there has Ex at the end for the 3 different difficulties: easy, normal and hard and then the unit's ID at the end, in this case the Human Footman. If you do this for buildings it will replace any pre-placed buildings that are destroyed.

So if I have an enemy barracks on the map

and CallSetBuildUnitEx(1,1,1,'hbar')

Any time that barracks is killed, the AI will rebuild it.

You'll want it before the InitAssaultGroup(), the InitAssaultGroup() just prepares Captains IIRC, the call CampaignAttackerEx checks if they have enough units and if not to train more. However the way that script works is for training units not building them, so it'll never build the War Golems but would assign War Golems that are already built or pre-placed.
 
Level 28
Joined
Dec 3, 2020
Messages
970
Probably best to put it at the start, I'm assuming they have defensive units pre-placed? If so do a

Call SetBuildUnitEx(1,2,3,'hfoo')

for every defender unit and the computer will replace them infinitely if they're killed. That example there has Ex at the end for the 3 different difficulties: easy, normal and hard and then the unit's ID at the end, in this case the Human Footman. If you do this for buildings it will replace any pre-placed buildings that are destroyed.

So if I have an enemy barracks on the map

and CallSetBuildUnitEx(1,1,1,'hbar')

Any time that barracks is killed, the AI will rebuild it.

You'll want it before the InitAssaultGroup(), the InitAssaultGroup() just prepares Captains IIRC, the call CampaignAttackerEx checks if they have enough units and if not to train more. However the way that script works is for training units not building them, so it'll never build the War Golems but would assign War Golems that are already built or pre-placed.
Thank you very much! Very clear and concise explanation!

Also yeah, the AI will have some pre-placed war golems around its base. I assume the war golems will go back to their spots when rebuilt since they are units.
I'm fine if the AI builds them around its town hall. I might also check the AI Placement Radius thingy so they're not built too close to other structures for example but that's misc stuff.
 
Status
Not open for further replies.
Top