The 3rd Age

Age of the Firstborn - The Rebirth

Age of the Firstborn - The Rebirth

Continues on Elrond99's Age of the Firstborn mod by turning time back to around TA2000.

Button for The 3rd AgeButton for The Dwarf HoldsButton for The Elven AllianceButton for Helm's Deep Last HopeButton for GothmogtheOrcButton for BFME+Button for The Four AgesButton for HDR HeadquartersButton for Middle Earth CenterButton for Project Perfect Mod

Become an affiliate!


Quick Lists

Top Rated Popular New Updated Last Comments Users

Register and log in to move these advertisements down

Adding a new unit

Tutorial for Battle for Middle-earth BFME, Battle for Middle-earth II BFME 2, Battle for Middle-earth II: Rise of the Witch-king ROTWK

Avatar of Hostile


Category: Code
Level: Intermediate
Created: Monday March 26, 2007 - 15:03
Updated: Saturday June 27, 2009 - 20:46
Views: 13178
Summary: The basics of a units code


Staff says


Members say




9 votes

The Basics - Adding A New Unit

Written by: Hostile

The purpose of this tutorial is to go step by step on explaining each major part of the object code. This doesn't cover every single aspect or the tutorial would run for pages. But does cover enough of the basics to give you an idea of how it works.

There are basic parts of a unit that I will list here.
Object Code - coding the unit
Model/Skin/Animations - this tutorial assumes you have these ready
Special Powers/Spells
Command Buttons

Before embarking on this challenge of adding a New Unit, I suggest you read the beginner tutorials so that you know how to extract the INI's and use your edited INI's.

All the tools you need to add your new faction can also be found in the Downloads section. So, let's get started.

I'm going to start with the object code as it is the most detailed and important. Also the easiest to make a mistake on. I've broken down the object code into sections that will address differant parts of the new unit. I'm going to be working with Mordor Goblin Fighters because I believe they are simple but allow enough variations for a good example.

Open up the object ini file for Mordor Goblin Fighter located at \data\ini\object\evilfaction. I've included a seperate text file for you to view so you can just click here for a copy of just this file instead.

Art Code
Condition States

The code begins with the art for this unit.

ButtonImage = BuildingNoArt

But most have a portrait here such a gondor soldier.
SelectPortrait = UPGondor_Soldier

Draw = W3DHordeModelDraw ModuleTag_01

OkToChangeModelColor = Yes

StaticModelLODMode = Yes
; specify options for static LODs
LodOptions = LOW
MaxAnimFrameDelta = 0 ;These guys are out of a horde more often than in, so they need permission to diverge.
RandomTexture = MUGblnSwrd.tga 0 MUGblnSwrd.tga
RandomTexture = MUGblnSwrd2.tga 0 MUGblnSwrd.tga
RandomTexture = MUGblnSwrd3.tga 0 MUGblnSwrd.tga
Model = MUGblnSwrd_SKN
Skeleton = MUGblnSwrd_SKL

It starts by naming the image ini to use, in this case it is not a button, no art necessary. But most units name a portrait image to be seen in the display when you click on it. The next line DRAW = W3DHordeModelDraw ModuleTag_01 is a basic command telling the game that this is a unit that will eventually form a horde. You'll use this often for new units.

I've included a section of the next code because it sets up how the art is done over differant resolutions. I would just copy paste all three LodOptions. It's standard...

The next code gives the options for random textures for our goblins, so they don't all look alike. MUGblnSwrd2.tga 0 MUGblnSwrd.tga, means that sometimes instead of the standard skin, substitute it for the first one. Lastly here we set our default model and skin. So the game knows what the model and the skeleton is we are working from.

Next starts the real art code. It states a condition state and what animation should be used when this condition state is true.

AnimationState = PASSENGER
Animation = Wiggling
AnimationName = MUGblnSwrd_FLLA
AnimationMode = LOOP

StateName = STATE_Flying
Animation = Thrown
AnimationName = MUGblnSwrd_FLYA
AnimationMode = LOOP

AnimationState = FREEFALL
Animation = Falling
AnimationName = MUGblnSwrd_FLYB
AnimationMode = LOOP
AnimationBlendTime = 10
AnimationSpeedFactorRange = 0.7 0.7

The first animation (condition) state describes when the goblin becomes a passenger. Namely this means when an eagle grabs one. Hence you can understand why it is called "wiggling". This animation state exists until the unfortunate goblin is dropped. Than it assumes the FREEFALL state.

The THROWN_PROJECTILE state exists when the goblin is hit by something like a rock from an Ent. He flies back from the force. These are an example of how condition states work and react when units are interacted with.

Now I'm not going to explain every condition state and how it relates. But by looking close at the code you'll notice you can code random dying animations and such based on how goblins land on the ground and such. Figuring this out is best left to the modder. That is part of the advanture.

This finishes up the art section of the object code. I'll now get into the Design Parameters for the unit code. Layed out as such...

Design Parameters
Mmore Basics

Let's start with the basics of DESIGN PARAMETERS
Side = Mordor
IsTrainable = No
EditorSorting = UNIT
ThreatLevel = 1.0
ThingClass = HORDE_UNIT
CommandPoints = 1

TransportSlotCount = 1

Side = Mordor, Tells us this unit works for Mordor. A unit cannot work if it is being built by a side it does not work for. So if you want Sauramon to work for Mordor you have to copy paste his object code and change the name and side = to Morder from Isengard.

IsTrainable = No Why would this be here? Because Mordor Goblins do not gain rank. That is the only time you would use this feature. Most units don't have it.

EditorSorting = UNIT World Builder needs to know what group it should be listing under. This one is a unit.

ThingClass = HORDE_UNIT/CommandPoints = 1 What is this item and how many command point does it take?

TransportSlotCount = 1 If I load this unit into something, how many spaces does it take up?

Next we move onto WEAPONSET. WEAPONSET is the weapon that the unit will use. This is a direct reference to the WEAPON.INI file located in data/ini/weapon.ini. A unit can have up to three weapons: PRIMARY, SECONDARY, TERTIARY.
Conditions = None
Weapon = PRIMARY MordorGoblinSword

Conditions sets when this weaponset is to be used. This can be None, Updraded, and so on. You may have multiple weaponsets based on the units statis. This can include upgrades, veterency, health, and so on. Many options to choose from. Look at the existing units for other options.

Example: the Gondor soldier
Weapon = PRIMARY GondorSwordUpgraded

Weapon = PRIMARY This can also include SECONDARY and TERTIARY weapons. You can define them all here. As many as you can think of. PRIMARY with an upgrade or veterency, SECONDARY with the same parameters. You can even state a condition state like REALLYDAMAGED. If you feel that your unit will change it's weaponset if it's really damaged. This is the condition to use. There are set condition states though. You cannot just make them up.

If a goblin can use swords and bows than it would look like this:
Conditions = None
Weapon = PRIMARY MordorGoblinSword
Weapon = SECONDARY MordorGoblinBow

That finishes WEAPONSET, let's move on to ARMORSET.
Conditions = None
Armor = CreepArmor
DamageFX = NormalDamageFX

Conditions should now already be explained, Armor is listed in the armor.ini file. You can have an armor, an upgraded armor, veterency armor, and such. Not much to explain here. The armor ini can be located at /data/ini/armor.ini

And some more of the basics. Such as:
DisplayName = OBJECT:GoblinSwordsman
CrushableLevel = 0 ;What am I?: 0 = for infantry, 1 = for trees, 2 = general vehicles
CrusherLevel = 0 ;What can I crush?: 0 = small animals, 1 = infantry, 2 = trees, 3 = vehicles
CrushRevengeWeapon = BasicInfantryCrushRevenge

VisionRange = VISION_STANDARD_MELEE Most units have this melee vision range. How far can I see and engage enemies.
DisplayName = OBJECT:GoblinSwordsman This is the CSF file entry. What shows up when I hover over this unit?
CRUSHABLE items are self explanitory here.
BountyValue = This is set in the gamedata.ini and gives a dollar value for when this unit is killed if you have such an ability to gain Bounty kills.

CommandSet = MordorFighterCommandSet

This will list the actions that this unit can perform. This is directly referenced in the CommandSet.ini file located in /data/ini/commandset.ini

VoiceSelect = UrukVoiceSelect ; MordorOrcHordeVoiceSelect
VoiceMove = UrukVoiceMove ; MordorOrcHordeVoiceMove
VoiceMove2 = OrcVoiceMove2
VoiceAttack = UrukVoiceAttack ; MordorOrcHordeVoiceAttack

This is where you assign the voices to be used for your unit. You can record your own. But you must code them in the audio.ini file. Than you can reference your new ones here.

Engineering Parameters

RadarPriority = UNIT

Body = ActiveBody ModuleTag_02
MaxHealthDamaged = 5
;RecoveryTime = 5000

Behavior = AIUpdateInterface ModuleTag_03
AutoAcquireEnemiesWhenIdle = Yes ATTACK_BUILDINGS
MoodAttackCheckRate = 500
AILuaEventsList = MordorFighterFunctions
AttackPriority = AttackPriority_Infantry

RadarPriority = UNIT Tells us this unit will show up as a unit on the radar map, not a structure or hero.
KindOf = Tells us how the computer should view this unit. This should be considered infantry, be selectable, pass through each other, and such.

Body = ActiveBody moduletag gives the unit life. MaxHealth is referenced right from the gamedata.ini, though you can just place a number here. That is accepted.

Behavior = AIUpdateInterface This open up the doors for letting the AI use this unit. Tells the AI abit about the unit and how it should behave.

Locomotor = HumanLocomotor
Condition = SET_NORMAL
Speed = 32

Locomotors tell the computer how fast or how agile a unit is. It is defined in locomotor.ini located in /data/ini/locomotor.ini You may add other locomotors based on condition states such as upgraded, veterency, so on.

The next part of the unit code is behaviors. Most flexible of the code and the most powerful. Sarumon cannot cast fireballs without a behavior being in his code to allow him to do this.

Behavior = UnpauseSpecialPowerUpgrade ModuleTag_FireballEnabler
SpecialPowerTemplate = SpecialAbilitySarumanFireball
TriggeredBy = Upgrade_SarumanFireBall

Nor can units recieve upgrades without some code here to support it.

Behavior = SubObjectsUpgrade Armor_Upgrade
TriggeredBy = Upgrade_GondorHeavyArmor
UpgradeTexture = GUManAtArms.tga 0 GUManAtArms_HA.tga
RecolorHouse = Yes
ExcludeSubobjects = Forged_Blade

Heroes need to be respawned, but they won't know that without having the code to support it.

Behavior = RespawnUpdate ModuleTag_RespawnUpdate
DeathAnim = DYING
;DeathAnim = STUNNED ;Model condition to play when killed-to-respawn
DeathFX = FX_SarumanDieToRespawn ;FXList to play when killed-to-respawn
DeathAnimationTime = 5500 ;1133 ;How long DeathAnim will take.
InitialSpawnFX = FX_SarumanInitialSpawn
RespawnAnim = LEVELED ;Animation to play when respawning.
RespawnFX = FX_SarumanRespawn ;FXList to play when respawning.
RespawnAnimationTime = 2000 ;Time it takes for respawn to play.
AutoRespawnAtObjectFilter = NONE +CASTLE_KEEP ;Respawn at this location -- and at it's exit production point if possible.
ButtonImage = HISaruman

;RespawnEntries determine the ruleset for how a character can be revived. Some units may automatically respawn, others
;may require a specific revive action performed on him. You can specify different values for each level... or use Level:Any
RespawnRules = AutoSpawn:No Cost:1200 Time:120000 Health:100% ;DEFAULT VALUES
RespawnEntry = Level:2 Cost:1400 Time:120000 ;For other levels, only override what is different.
RespawnEntry = Level:3 Cost:1600 Time:120000
RespawnEntry = Level:4 Cost:1800 Time:120000
RespawnEntry = Level:5 Cost:2000 Time:180000
RespawnEntry = Level:6 Cost:2200 Time:180000
RespawnEntry = Level:7 Cost:2400 Time:180000
RespawnEntry = Level:8 Cost:2600 Time:180000
RespawnEntry = Level:9 Cost:2800 Time:180000
RespawnEntry = Level:10 Cost:3000 Time:180000

Some units can auto heal based on this behavior:

Behavior = AutoHealBehavior ModuleTag_SarumanHealing
StartsActive = Yes
HealingAmount = HERO_HEAL_AMOUNT
HealingDelay = 1000
StartHealingDelay = HERO_HEAL_DELAY
HealOnlyIfNotInCombat = Yes

Behaviors do so much more than I can begin to explain here. They are the backbone of all the special abilites of units. So I'll end that part here. The last part I'll finish with is geometry.

Geometry = CYLINDER
GeometryMajorRadius = 8.0
GeometryMinorRadius = 8.0
GeometryHeight = 19.2
GeometryIsSmall = Yes
ShadowSizeX = 11;
ShadowSizeY = 11;
ShadowTexture = ShadowI;

The model, believe it or not, has limited uses other than showing the player what is happening. The geometry of the unit tells the computer the size of the area that this unit actually makes up. This is what the game factors really use when determining how close one unit is to another.

That finishes up the object code. Once this is complete to your liking than you have to add a commandbutton to build it and the command buttons to upgrade the unit and any other command buttons such as activating a spell and such.

These command buttons are than added to the units commandset and the command button used to build the unit is than added to the structure that you would like to have build this unit. You must really look at the existing units to get a good grasp of just how all this fits together. See Command Button Tutorial.

I hope this answers a few questions regarding the object code for your new unit. Any further questions about this tutorial can be answered by coming to our forums.


GothmogtheOrcporting the tutorial to the new site


Display order: Newest first

memocarvajal - Thursday December 6, 2012 - 19:21

you can make a video of each step to create a unit if possible friend
tell me your facebook and msm for your best friend to tell me
I speak Spanish but I understand English not worry about it

please help me because friend and tried many times to create a unit and not succeeded and please help me friend


Friend you also have noticed that in BFME2 troops can form freely if possible friend I would also like to explain to me why porfabor friend thanks

Emperor of the East - Saturday November 21, 2009 - 0:30

I am trying to make new units out of existing files for my Men of the East faction and my Rohan faction, and this is getting to be confusing due to the differences between these guidelines and the units I downloaded off of here.

Akhôrahil - Friday August 24, 2007 - 20:00

It's a article that tells you how to add new units, not new skins.

Ultama - Sunday August 19, 2007 - 11:56

This really dosnt tell me about adding new skins to troops =/
How can i add new skins/Models to troops/exisiting troops (using Map.ini :D)

Go to top


"One site to rule them all, one site to find them,
one site to host them all, and on the network bind them."