• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

How to make AI build a unit like a structure

Level 22
Joined
Dec 3, 2020
Messages
568
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 22
Joined
Dec 3, 2020
Messages
568
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 22
Joined
Dec 3, 2020
Messages
568
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.
 
Top