Homeworld 2 continues the epic struggle of the Hiigarans and their leader Karan S'jet. Many thought their hardships would end when they returned to Hiigara, yet fate has not been so kind to the Exiles. Now the Hiigarans face a new and bitter enemy, a renegade clan from the eastern fringes of the galaxy, who wield the power of the ancients. Homeworld 2 chronicles the valiant journey of the Mothership and its crew into the oldest regions of the galaxy to confront their new foe and discover the truth behind their exile.

Post tutorial RSS Enable AI to Build New Ships

Okay, so you have a new race, or you've added a new ship into Homeworld 2. That's great and all, but your computer, no matter how good, doesn't know what to do with it. I will show you how to make your computer make sense of you new ship(s)

Posted by on - Intermediate Client Side Coding

Okay, so you have a new race, or you've added a new ship into Homeworld 2. That's great and all, but your computer, no matter how good, doesn't know what to do with it. I will show you how to make your computer make sense of you new ship(s).
[page=The ClassDef.lua File]
Before you can tell the AI to build the ship, you have to tell it what kind of ship it is. But this tutorial, I will show you two examples, a new race from my mod, the Progenitor, and to add a new ship, the "Bishop" Crew Transport (from the single-player mission). This is so you know how to add a new race to the listing.

Now, in you Data folder, add a new folder, name it "AI". This will contain all the AI needed files (but I'm sure you already knew that). Now, make sure to use the file given in the RND pack, this is because LuaDC does not properly de-compile the AI files (I have no idea why). Now, if you see, that is more-or-less a list of all the games ships. Now to add those ships. First, add the new Mothership for the Progenitor, Sajuuk. This is how it originally looked:

squadclass[eMotherShip] = {

I'm not sure of this, but you have to add the new ships in a specific order, and way (correct me if I am wrong). Now, under VGR_MOTHERSHIP_MAKAAN, we'll add Sajuuk. It should now be:

squadclass[eMotherShip] = {


Hopefully you understand what need to be done. Now each "table" has a purpose, this first one was to define the Mothership. Now to add the Crew Transport. We'll define it as a Capital class ship.

squadclass[eCapital] = {

Now remember, it does matter whether or not you use uppercase and lowercase letters.

Now add all of your new ships to their appropriate place.
[page=The CPUBuild.lua File]
Okay, so the AI knows what?s what, but yet it doesn't know...what?s what? Well, it know what it's good for, it doesn't know whether or not it's something it needs to build, or something like that. It's time to go to the CPUBuild.lua file. It's fairly easy. If you?re just adding a new ship and isn't replacing and existing ship listed here (such as a replacement carrier, destroyer, etc.). If you?re adding a new race, everything changes. This is what my CPUBuild.lua file looks like, with the Progenitor added in (not the whole file, just the top section)

function CreateBuildDefinitions()
	if (s_race == Race_Hiigaran) then
		kScout = HGN_SCOUT
		kInterceptor = HGN_INTERCEPTOR
		kCarrier = HGN_CARRIER
		kShipYard = HGN_SHIPYARD
		kDestroyer = HGN_DESTROYER
		kBattleCruiser = HGN_BATTLECRUISER
	elseif (s_race == Race_Vaygr) then
		kScout = VGR_SCOUT
		kInterceptor = VGR_INTERCEPTOR
		kBomber = VGR_BOMBER
		kCarrier = VGR_CARRIER
		kShipYard = VGR_SHIPYARD
		kDestroyer = VGR_DESTROYER
		kBattleCruiser = VGR_BATTLECRUISER


		kCollector = KPR_MOVER
		kRefinery  = KPR_KEEPER
		kInterceptor = KPR_ATTACKDROID
		kBomber = KPR_MOVER
		kCarrier = KPR_KEEPER
		kShipYard = KPR_SAJUUK
		kDestroyer = KPR_KEEPER
		kBattleCruiser = KPR_DREADNAUGHT

If you just look it over, I think you can understand what needs to be done. Just replace all the Progenitor ships, with your own, just make sure what you add in makes sense for what it's defined as (unless you don't have a ship that fits in, just add anything.)
[page=Hints and Tips]
Okay, that's all I know of AI scripting, I am trying to get the research enabled for the AI, but I've still to learn and debug the files. Instead, here are some things you should keep in mind.

Look for existing patterns
When adding in a new ship, try to add it in a way similar to that of what is already their. It will help ensure that it works.

Check for typos
This is the most important thing to remember, a single extra or missing letter, comma, or bracket can make the whole file useless. It has caused me so much trouble at times. It can save you allot of trouble to do it right the first time, even if it takes a little extra time or work.

If you?re stuck, ask for help
It's as simple as that, their are plenty of forums out their who can help. A great place to ask is at Relicnews Forums, a great community of Relic games and their mods.

Other Homeworld tutorials by me
Make sure to check out my Setting up a New Race tutorial. Their are more to come. :)


never modded HW2 (dont even have it) but it looks like a good reference for newbies :)

Reply Good karma Bad karma+2 votes
Mr.Grim Author

Yep, that what I'm going to try to do, make an ultimate newb guide to HW2. (Not one tutorial, a whole collection of them ;) )

Reply Good karma+1 vote
Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

Follow Profile
Homeworld 2
Windows, Mac
Send Message
Release date
Game watch
Related Games
Homeworld 2
Homeworld 2 Real Time Strategy
Related Groups
Sierra Entertainment
Sierra Entertainment Developer & Publisher