GUIDE: Adding new units

sovarn

Warlord
Joined
Nov 8, 2005
Messages
166
Location
London
How to add your own custom units

Beware that at the moment no one can create an actual new model but only new units with their own unique skins and/or stats. This can be added in very easily. This guide also doesn't cover changing unit stats, for that go to :http://modiki.civfanatics.com/index.php/Civ4UnitInfos for a list of tags and what they mean.

In our example we will be creating a new unit using the Warrior model with a new skin. This unit will be called Terry. Use common sense where applicable and tell me if something is wrong/missing or you just plain can't understand it.

To prepare, go to your customs assets folder or create a new mod. All files in the following guide will use the assets folder as the root. So if i say create a new folder, this folder will be created in the assets folder.

PART 1 - Getting ready

First of all you must unpak the Art0.fpk file using the PakBuild Utility to get the unit. Since new models can't be created you will have to use an existing one. Copy the whole ...arts/units/warrior folder from the unpaked .fpk file and paste it in your assets folder (either of your mod or the custom one) keeping the file structure.

Rename the folder to Terry but keep all the files inside intact i.e. do not touch them otherwise your game will crash and do funny stuff with you RAM. Get the new skin if you have one and replace it over the warrior_128.dds. The new skin has to take this name (in this example).

Next copy over your .../assets/xml/units/CIV4UnitClassInfos.xml and CIV4UnitInfos.xml to your assets folder using the same file structure.
Copy the .../assets/xml/text/CIV4GameText_Strategy.xml, CIV4GameTextInfos_Objects.xml and CIV4GameText_Civililopedia_Units.xml to your new assets folder - again keeping the file structure.
Copy the .../assets/xml/art/CIV4ArtDefines_Unit.xml over.

Now you should be ready.
 
PART 2 - Writing in your new unit

Now you are ready to mod .xml. You can use notepad or some other program which highlights stuff for you. I use Dreamweaver.

a) Open CIV4UnitInfos.xml
It's a very big file but copy one whole class section. i.e. between and including :

Code:
<UnitInfo>

....

</UnitInfo>

Then paste it after a </UnitInfo>. You have now esentially created a duplicate of a unit.

So now we need to edit it. I will only tell you the essential elements to change, the rest you can fiddle round with and you can figure out what the do by checking out the other units.

Below is a list of things to change.

<Class>UNITCLASS_WARRIOR</Class>
<Type>UNIT_WARRIOR</Type>
...
<Description>TXT_KEY_UNIT_WARRIOR</Description>
<Civilopedia>TXT_KEY_UNIT_WARRIOR_PEDIA</Civilopedia>
<Strategy>TXT_KEY_UNIT_WARRIOR_STRATEGY</Strategy>

to

<Class>UNITCLASS_TERRY</Class>
<Type>UNIT_TERRY</Type>
...
<Description>TXT_KEY_UNIT_TERRY</Description>
<Civilopedia>TXT_KEY_UNIT_TERRY_PEDIA</Civilopedia>
<Strategy>TXT_KEY_UNIT_TERRY_STRATEGY</Strategy>

Notice all i do is change all WARRIOR references to TERRY. If you want you can just type in the words you want bewtween the <Description><Civilopedia><Strategy> but then it won't translate. This will save you from editting the text files though.

Near the bottom of the UnitInfo class you will see this:
Code:
<UnitMeshGroups>
	<iGroupSize>3</iGroupSize>
	<fMaxSpeed>1.75</fMaxSpeed>
	<iMeleeWaveSize>3</iMeleeWaveSize>
	<iRangedWaveSize>0</iRangedWaveSize>
	<UnitMeshGroup>
		<iRequired>8</iRequired>
		<EarlyArtDefineTag>ART_DEF_UNIT_WARRIOR</EarlyArtDefineTag>
	</UnitMeshGroup>
</UnitMeshGroups>
<Button>,Art/Interface/Buttons/Units/Warrior.dds,Art/Interface/Buttons/Unit_Resource_Atlas.dds,2,1</Button>

Again change the WARRIOR ref to TERRY so it should look like this.
Code:
<UnitMeshGroups>
	<iGroupSize>3</iGroupSize>
	<fMaxSpeed>1.75</fMaxSpeed>
	<iMeleeWaveSize>3</iMeleeWaveSize>
	<iRangedWaveSize>0</iRangedWaveSize>
	<UnitMeshGroup>
		<iRequired>8</iRequired>
		<EarlyArtDefineTag>ART_DEF_UNIT_TERRY</EarlyArtDefineTag>
	</UnitMeshGroup>
</UnitMeshGroups>
<Button>Art/Interface/Buttons/Units/Terry.dds</Button>

Notice that I removed the atlas picture in the mod. It will still work fine without it and is just easier to edit one file.
There is so much more that you can do, but i am just covering the basics.

b) Open Civ4UnitClassInfos.xml

Again copy a whole UnitClassInfo and paste it in at the end but before the

</UnitClassInfos></Civ4UnitClassInfos>. It should look like this
Code:
<UnitClassInfo>
	<Type>UNITCLASS_TERRY</Type>
	<Description>TXT_KEY_UNIT_TERRY</Description>
	<iMaxGlobalInstances>-1</iMaxGlobalInstances>
	<iMaxTeamInstances>-1</iMaxTeamInstances>
	<iMaxPlayerInstances>-1</iMaxPlayerInstances>
	<DefaultUnit>UNIT_TERRY</DefaultUnit>
</UnitClassInfo>
c) Edit all the TEXT files.

This is pretty straight forward. Again copy the class and paste a new one, remembering to rename the KEYs corrrectly.

d) Open the CIV4ArtDefines_Units.xml

Like before create a new <UnitArtInfo> and edit it. It should look like this:

Code:
<UnitArtInfo>
	<Type>ART_DEF_UNIT_TERRY</Type>
	<fScale>0.61</fScale>
	<fInterfaceScale>1.3</fInterfaceScale>
	<NIF>Art/Units/Terry/Warrior.nif</NIF>
	<KFM>Art/Units/Terry/Warrior.kfm</KFM>
	<SHADERNIF>Art/Units/Terry/Warrior_FX.nif</SHADERNIF>
	<ShadowDef>
		<ShadowNIF>Art/Units/01_UnitShadows/LionShadow.nif</ShadowNIF>
		<ShadowAttachNode>LionBip Spine1</ShadowAttachNode>
		<fShadowScale>1.0</fShadowScale>
	</ShadowDef>
	<fBattleDistance>0.35</fBattleDistance>
	<fRangedDeathTime>0.28</fRangedDeathTime>
	<bActAsRanged>0</bActAsRanged>
	<TrainSound>AS2D_UNIT_BUILD_UNIT</TrainSound>
	<AudioRunSounds>
		<AudioRunTypeLoop/>
		<AudioRunTypeEnd/>
	</AudioRunSounds>
</UnitArtInfo>

Notce that all we do is change the folder reference to TERRY but keep the warrior file names. This is why you must not rename files as the .dds skin is not referenced here but in the .nif file. Everything has to be the same and original name so all the .kf s will work properly.

TADA: now your unit will be avaliable to play with its new graphics/stats. But we still have something missing. The buttons!!
 
PART 3 - Referencing and Graphics

Okay now for the more time consuming bit - graphics. (Hopefully someone created that skin for you otherwise this will be easy for those with a nimble digital paintbrush).

For normal units all you have to do is create one button image for your unit. An image will automatically be created to select the unit when it is in a stack.

Create a new .dds image called terry.dds and put it in .../Art/Interface/Buttons/Units/Terry.dds. Note that the Art folder is in the Assets folder. It is different to XML/Arts folder. In other words when you look in your custom assets folder you will see an Art and XML folder.

Somehow either export or edit the .dds file. It should be 64x64 pixels at 200 pixels/inch. They best way is to copy and rename an existing .dds and just edit that picture so you get to keep the blue frame.

PART 4 - Play the game

Now you can play your own unique unit you just put in. Have fun.

NOTE: creating a new Great person or specialist is similar but will require extra changes. It is a bit more complex with more files to edit and a couple of extra buttons.
I may write another guide if people want this.

Now you can add you own units in. Go ahead, you know you want to. You may now commence commenting on how useful this was (or not as the case may be :p ) Any ommissions or mistakes please point it out.

Thanks
 
I just add one thing, cause it is true there's so much to say about this... I have even succeeded to limit the nuclear weapons to the civilizations that would build a national wonder "manhattan project". So ... so much we could say ;)....


Well the precision :p...

We must precise the fact you can find several units with the same class.


Code:
<UnitClassInfo>
	<Type>UNITCLASS_TERRY</Type>
	<Description>TXT_KEY_UNIT_TERRY</Description>
	<iMaxGlobalInstances>-1</iMaxGlobalInstances>
	<iMaxTeamInstances>-1</iMaxTeamInstances>
	<iMaxPlayerInstances>-1</iMaxPlayerInstances>
	<DefaultUnit>UNIT_TERRY</DefaultUnit>
</UnitClassInfo>

When you are here you see this: <DefaultUnit>UNIT_TERRY</DefaultUnit>
This tell the game what is the default unit for this class.

In the file \Assets\xml\civilizations\CIV4CivilizationInfos.xml you can give some units to some civilizations. These units will replace the default unit. You can add several units to a civilization.

Exemple I have done ;)

Code:
			<Units>
				<Unit>
					<UnitClassType>UNITCLASS_MUSKETMAN</UnitClassType>
					<UnitType>UNIT_FRENCH_MUSKETEER</UnitType>
				</Unit>
				<Unit>
					<UnitClassType>UNITCLASS_INFANTRY</UnitClassType>
					<UnitType>UNIT_INFANTRY_WW1</UnitType>
				</Unit>
				<Unit>
					<UnitClassType>UNITCLASS_RIFLEMAN</UnitClassType>
					<UnitType>UNIT_MINUTEMAN</UnitType>
				</Unit>
			</Units>

This command the game to use 3 special units for the france. The 3 units are from the classes of UNITCLASS_MUSKETMAN ; UNITCLASS_INFANTRY and UNIT_INFANTRY_WW1.
So basically you can add here some specific units for a civilization without limit (except the hardcoded limits).
 
I just spent 2 days reworking every unit to match what I wanted for my mod. I even added 4 new units. I plan on doing more but for now this is good enough to start testing balance issues, ect.
I started up the game went to Advanced>Load Mod> My Mod
It restarted, loading my mod ( after quite a few errors were fixed lol ), but the Multiplayer menu option is greyed out, and when I go single player, the only option available is load game.
Am I missing some thing? Why can't I start a new game under my mod?

I only have 3 mod files:
Erdrik.ini
-- Mods/Erdrik/
CIV4GameTextInfos_Objects.xml
-- Mods/Erdrik/Assests/XML/Text/
CIV4UnitInfos.xml
-- Mods/Erdrik/Assests/XML/Units/

I do have a regular text file in -- Mods/Erdrik/Pertainent Info.txt
That I am using to type up mod ideas...

Is there something I am missing?
 
Yea I got that page bookmarked. :) very helpful.

Tho I couldn't find anything there to help with my problem. :sad:

...
 
OK guys, this thread is one of the best for modding I've found yet.

Question: How do you mod the promotions allowed for a custom unit?

I'm making the "Highlander" to be the UU for the Scots (to replace the Swordsman) and the Guerilla promotions are not available to it.

thanks
 
WaxonWaxov said:
Question: How do you mod the promotions allowed for a custom unit?
Okies. The unit file links to the promotions file through the <Combat> tag in the units file. If you look in the promtions file, you will see a <UnitCombats> tag, containing all the <Combat> types that can use the promotion.

Now unfortunetly you probably want your Highlander to be a melee combat unit (for purposes of combat bonuses against certain types), and melee units can't have the Guerilla promotion as standard.

There are several things you could do, however, I think that this one is the best method:

1) Mod in a new promotion called Guerilla_H or something. Make it available to melee units, and have the same stats as the Guerilla promotion.

2) Mod in a second promotion. Make this new promotion a prerequisite of Guerilla_H. Make sure no units can get this new promotion.

3) Give your Highlander unit the second promotion as a free promotion (bottom tag on unitinfos).
 
<Button>,Art/Interface/Buttons/Units/Terry.dds</Button>

I have to remove the first "," for this to work:

<Button>Art/Interface/Buttons/Units/Terry.dds</Button>

Still, this leaves me with a "!" instead of the picture that shows current production in a city. I have tried to solve this by pasting my custom button in a custom_atlas file, so that it looks just like the original code. The game can pick the graphics correctly from both files but it didn't help. :(

Do anyone else have this problem?
 
I keep getting an error message when trying to add a new unitclass.

"Tag: UNITCLASS_SKIRMISH2 in Info class was incorrect Current XML file is: Units\CIV4UnitInfos.xml"

I thought I followed this guide exactly. I have tried a different name, clearing the cache, checking other mods to compare how they do it, searching for relevant text strings inside the Civ 4 folders and inside my mod to make sure there are no other hidden references to unitclass... and I still can't figure out why I get this error!

Here is a cut and paste of my entry in CIV4UnitClassInfos.xml :

<UnitClassInfo>
<Type>UNITCLASS_SKIRMISH2</Type>
<Description>TXT_KEY_UNIT_SKIRMISH2</Description>
<iMaxGlobalInstances>-1</iMaxGlobalInstances>
<iMaxTeamInstances>-1</iMaxTeamInstances>
<iMaxPlayerInstances>-1</iMaxPlayerInstances>
<DefaultUnit>UNIT_SKIRMISH2</DefaultUnit>
</UnitClassInfo>

Believe me, I've checked the entry in CIV4UnitInfos.xml too. No mispellings, etc.

Can anyone help? Any ideas?


Cheers,
Peter :(
 
hiya guys, glad to see someone using my guide.

Is there anything wrong with the guide? because i did check it before i posted it.
what are you havign problems with.
 
See the issue with an exclamation point showing up as described in post #11 in this thread. (just a couple up)

Otherwise this is a great guide. You might want to amend it a little for "if you want this to be a Unique Unit..."
 
Hi all!

I have the same problem: A "!" instead of the picture that shows current production in a city. By the way, your Tutorial is very good. It helps a lot.

Greetings

D_K

P.S. English is not my first language, so be patient with my text, please...:)
 
Sorry, if i want to chang only the name of a unit?
In the first link guide, i don't understad how to do this.

The text tags are

<Class>UNITCLASS_WARRIOR</Class>
<Type>UNIT_WARRIOR</Type>
<UniqueNames/>
<Special>NONE</Special>
<Capture>NONE</Capture>
<Combat>UNITCOMBAT_MELEE</Combat>
<Domain>DOMAIN_LAND</Domain>
<DefaultUnitAI>UNITAI_ATTACK</DefaultUnitAI>
<Invisible>NONE</Invisible>
<SeeInvisible>NONE</SeeInvisible>
<Description>TXT_KEY_UNIT_WARRIOR</Description>
<Civilopedia>TXT_KEY_UNIT_WARRIOR_PEDIA</Civilopedia>
<Strategy>TXT_KEY_UNIT_WARRIOR_STRATEGY</Strategy>
<Advisor>ADVISOR_MILITARY</Advisor>


I have the italian version, i can't find the association with the object names
 
This file CIV4GameTextInfos_Objects.xml in folder .../xml/text
Example:

<TEXT>
<Tag>TXT_KEY_UNIT_MODERN_ARMOR</Tag>
<English>Modern Armor</English>
<French>
<Text>Blind&#233; moderne</Text>
<Gender>Male</Gender>
<Plural>0</Plural>
</French>
<German>
<Text>Kampfpanzer</Text>
<Gender>Male</Gender>
<Plural>0</Plural>
</German>
<Italian>
<Text>Unit&#224; corazzata:Unit&#224; corazzate</Text>
<Gender>Female</Gender>
<Plural>0:1</Plural>
</Italian>
<Spanish>
<Text>Blindado moderno:Blindados modernos</Text>
<Gender>Male</Gender>
<Plural>0:1</Plural>
</Spanish>
</TEXT>
 
Thanks! I did it!
 
Top Bottom