[page=Introduction]
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] = {
HGN_MOTHERSHIP,
VGR_MOTHERSHIP,
VGR_MOTHERSHIP_MAKAAN,
}
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] = {
HGN_MOTHERSHIP,
VGR_MOTHERSHIP,
VGR_MOTHERSHIP_MAKAAN,
KPR_SAJUUK,
}
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] = {
HGN_TANKER,
HGN_CARRIER,
HGN_MOTHERSHIP,
HGN_SHIPYARD,
HGN_DESTROYER,
HGN_BATTLECRUISER,
HGN_DREADNAUGHT,
VGR_CARRIER,
VGR_MOTHERSHIP,
VGR_MOTHERSHIP_MAKAAN,
VGR_SHIPYARD,
VGR_DESTROYER,
VGR_BATTLECRUISER,
}
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
kCollector = HGN_RESOURCECOLLECTOR
kRefinery = HGN_RESOURCECONTROLLER
kScout = HGN_SCOUT
kInterceptor = HGN_INTERCEPTOR
kBomber = HGN_ATTACKBOMBER
kCarrier = HGN_CARRIER
kShipYard = HGN_SHIPYARD
kDestroyer = HGN_DESTROYER
kBattleCruiser = HGN_BATTLECRUISER
elseif (s_race == Race_Vaygr) then
kCollector = VGR_RESOURCECOLLECTOR
kRefinery = VGR_RESOURCECONTROLLER
kScout = VGR_SCOUT
kInterceptor = VGR_INTERCEPTOR
kBomber = VGR_BOMBER
kCarrier = VGR_CARRIER
kShipYard = VGR_SHIPYARD
kDestroyer = VGR_DESTROYER
kBattleCruiser = VGR_BATTLECRUISER
else
kCollector = KPR_MOVER
kRefinery = KPR_KEEPER
kScout = KPR_ATTACKDROID
kInterceptor = KPR_ATTACKDROID
kBomber = KPR_MOVER
kCarrier = KPR_KEEPER
kShipYard = KPR_SAJUUK
kDestroyer = KPR_KEEPER
kBattleCruiser = KPR_DREADNAUGHT
end
end
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 :)
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 ;) )