• 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.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

[Solved] AI Not Rebuilding Destroyed Buildings

Level 4
Joined
Aug 3, 2025
Messages
27
Using Warcraft 3 Patch 1.31
I am almost done from a map i was working on for over a month now, and i am facing issues regarding the AI parts of it, one thing being that I am making a custom faction with custom builds and units, so far the AI works well as it rebuilds units and defenders, the biggest issues i currently run into:

1-Using the Call SetBuildUnitEx causes the workers to build a great hall even when i already have a fortress or stronghold.
2-Is that Workers don't build, they just gather resources and repair i don't really get why.
I will attach one of the AIs i created and i would really appreciate if someone could guide me to making it fully functional.
This is my first map so if possible please keep it simple.

Extra Notes: well another odd thing i find is that the AI keeps overflowing the gold mines with workers, and i am not sure how can i use it to distribute them the right way, not to mention that in the Attachment i sent i tell the Ai to build an Elite Camp when in normal or hard difficulty yet like i said they don't build anything at all, the only thing they do is upgrade their stronghold into a fortress (the only thing related to buildings i mean)
 

Attachments

Last edited:
JASS:
call CampaignAI (CENTAUR_TENT,null)

Instead of your custom farm, try with BURROW or HOUSE, I've had issues whenever I used anything other than the defaults for this line and it doesn't prevent workers from building customs farms

Apart from that there are no syntax errors so if that's not it then I'm clueless
 
Sorry for the late replay
JASS:
call CampaignAI (CENTAUR_TENT,null)

Instead of your custom farm, try with BURROW or HOUSE, I've had issues whenever I used anything other than the defaults for this line and it doesn't prevent workers from building customs farms

Apart from that there are no syntax errors so if that's not it then I'm clueless
sorry for the late replay, that did seem to work, however the workers don't actually rebuild their great hall, i looked it up and i found this code:
if ( GetUnitCountDone(CENTAUR_GREATHALL) == 0 and GetUnitCountDone(CENTAUR_STRONGHOLD) == 0 and GetUnitCountDone(CENTAUR_FORTRESS) == 0 ) then

call SetBuildUnitEx(1, 1, 1, CENTAUR_GREATHALL)

endif
call SetBuildUpgrEx(1, 1, 1, CENTAUR_STRONGHOLD)

call SetBuildUpgrEx(1, 1, 1, CENTAUR_FORTRESS)
the AI upgrades it's great hall into a fortress, yet it doesn't actually build a great hall when the requirements are met, what is the right way to do that?
 
Well i haven't figured out how to make the workers stop building a great hall when a stronghold or fortress are on the map.
although using the method mentioned above and after using an already exisint AI Script in the game i managed to finally write an AI that functions properly
as for the workers overflowing the mines all i did was use the call commands:
call SetGoldPeons(5)
call SetWoodPeons(5)
Also at some point i happened to accidently switch the raw code of one my custom altars with another which cause the AI to malfunction greatly at some point, but well now i have a fully functioning AI (aside from the Great Hall rebuilding thing) Thanks for your time.
 
Tbf if you tell them to build a fortress, they will automatically build a Great Hall and upgrade it to Fortress, unless you need them to build the previous techs beforehand.
i used the code "call SetBuildUnitEx ( 0,1,1, CENTAUR_FORTRESS)", yet they only upgrade their stronghold into a fortress, then if you destroy the fortress they don't rebuild a great hall and upgrade it, from what i learned it is due to the fact that it is a custom build, however i am not sure exactly on how to make it work, unless i am messing some small detail.

Edit: yea i just tested it they definitely don't build any great halls and if i use the build great hall code they will just build a great hall next to the fortress
 
I think you use some custom Town Hall building. I got the same trouble. Check this thread: [JASS] - Campaign AI, weird issue with custom buildings order
So basically i add that code into the common.ai file then import it into my map? is it that simple or am i not understanding something here
Also just to be certain where should i write this code exactly bc there is over 2k lines of code here

EDIT: SO here is what i did, first i added the code lines at the end of the common.ai file, then i imported it to the import managed (I also made sure to make a back up for my map in case something breaks).
call SetBuildUnitEx ( 1,1,1, CENTAUR_GREATHALL )
call SetBuildUnitEx ( 1,1,1, CENTAUR_STRONGHOLD )
call SetBuildUnitEx ( 0,1,1, CENTAUR_FORTRESS )
I then used the codes mentioned above for the AI, and they ended up building the 3 builds, so if possible i would like to learn what i did wrong here.
 

Attachments

  • common.PNG
    common.PNG
    60.9 KB · Views: 35
Last edited:
So basically i add that code into the common.ai file then import it into my map? is it that simple or am i not understanding something here
Also just to be certain where should i write this code exactly bc there is over 2k lines of code here

EDIT: SO here is what i did, first i added the code lines at the end of the common.ai file, then i imported it to the import managed (I also made sure to make a back up for my map in case something breaks).
call SetBuildUnitEx ( 1,1,1, CENTAUR_GREATHALL )
call SetBuildUnitEx ( 1,1,1, CENTAUR_STRONGHOLD )
call SetBuildUnitEx ( 0,1,1, CENTAUR_FORTRESS )
I then used the codes mentioned above for the AI, and they ended up building the 3 builds, so if possible i would like to learn what i did wrong here.
There is a type in your common.ai, you put:
"uunitid" == 'o00G'

Try remove it and reimport it.
If it still doesn't work, you can send your map if you want me to check it
 
So here is what i did i imported the common.ai file after fixing the typo i made and remove the wr3imported path (not sure if it makes a change though) then i realized that placing the call build command for each of the greathall, stronghold and fortress directly under each other is also a main factor in the bug i was facing, i ended up arranging them in a way that makes more sense, and yep it did actually work and my AI rebuilds it's main hall now, although i ran into Two problems one is less significant then the other:

1- being that My centaur warriors AI one has a weird bug that causes all units to flood the goldmine now even though i checked with jass demo that there is no syntax error, it isn't really a big deal but i would like to know if there is a way to make them return to harvesting both gold and lumber separately.

2-Well The Centaurs Elites AI now crashes the game whenever i destroy one of their fortress basically the issue lies in the fact that the AI attempts to rebuild the great hall but the game completely crashes and that is only the cause for this one AI, the rest are quite similar to it even one having 2 fortress yet still functioning normally, it is only the centaurs elites ai that crashes so i would like to know what causes it as well
Aside from that my map is clear of any issues.
 

Attachments

You can simplify your scripts by ignoring the gold peons, peons are all automatically ordered to harvest gold by default; you only need to specify the wood peons.
well speaking of which i was about to add an edit that the workers actually do end up harvesting the lumber but a bit later compared to the other AIs, well that leaves the issue with the Centaurs Elites AI crashing on me.
 
I'd check the triggers that it isn't causing any loops, in terms of AI crashes? The only AI crashes I know of are related to expansion finding and path finding occasionally causing crashes. But yeah I'd double check the triggers for loops as a first point to check.
 
If the issues is with the triggers wouldn't that apply to the rest of the AIs too? i have like 4 other AIs almost identical to this one with the exception of the heroes, and they all work very fine so far, one thing i noticed after testing each building one by one is that Altars are safe from this issue, so far what causes it are spirit lodges and warmills, and previously great halls until i removed them.
Based on what you mentioned i literally removed the great hall building code completely so it definitely doesn't have anything to do expansions, as for path finding the only thing i can think of is the fact that the base is a little crowded with units other then that i got no clue.
And it isn't about the raw codes either because i checked every single one of them and there is no syntax error as far as i know.
 

Attachments

  • Elites.PNG
    Elites.PNG
    1.7 MB · Views: 35
i don't think the loops are the issue, first of all because i have them for the attacks not the builds, not to mention that like i said i have 4 similar AIs and they work just fine, as for the triggers the only trigger i have that repeats itself is a trigger to spawn a unit every 1200 seconds, so i don't really see how looping is the issue here, should i just send the map and let you have a look at it?
 
So after so many tries with different possibilities and different AIs and disabling many triggers and even changing the player slot the centaur elites still kept crashing so i am pretty much clueless on what is happening with them.
Alas i guess i will just mark this as solved since i technically managed to get the rest of my AIs functioning
The actual building started after i changed this code: call CampaignAI (CENTAUR_TENT,null) into this call CampaignAI (BURROW,null)
then i managed to get the AI to rebuild the great halls after i edited the common.ai and added my custom builds to it like this:
So here is what i did i imported the common.ai file after fixing the typo i made and remove the wr3imported path (not sure if it makes a change though) then i realized that placing the call build command for each of the greathall, stronghold and fortress directly under each other is also a main factor in the bug i was facing, i ended up arranging them in a way that makes more sense, and yep it did actually work and my AI rebuilds it's main hall now, although i ran into Two problems one is less significant then the other:

1- being that My centaur warriors AI one has a weird bug that causes all units to flood the goldmine now even though i checked with jass demo that there is no syntax error, it isn't really a big deal but i would like to know if there is a way to make them return to harvesting both gold and lumber separately.

2-Well The Centaurs Elites AI now crashes the game whenever i destroy one of their fortress basically the issue lies in the fact that the AI attempts to rebuild the great hall but the game completely crashes and that is only the cause for this one AI, the rest are quite similar to it even one having 2 fortress yet still functioning normally, it is only the centaurs elites ai that crashes so i would like to know what causes it as well
Aside from that my map is clear of any issues.
I basically ended up having all bases functioning well expect for one so i could call that a success, in the end i ended up removing player 18 build AI completely so that it won't crash anymore, basically a small sacrifice to get the whole map functioning.
so technically problem is solved.
 
Your loop isn't indented properly, you're still putting spaces after functions and before the brackets, you're still using the function to set gold peons. I'd recommend cleaning up and formatting your AIs nicely as it will help with bug fixing, troubleshooting and also make it easier for other people to understand and see what's going.
 
i copied that AI code using a tutorial from one of the members of hive on youtube and it functioned well so far it is this one specific faction that keeps crashing.
Can you perhaps show me a well made AI for me to use as a reference? since i am not certain how to make my loop indented properly for example.
 
Back
Top