Mount & Blade Warband: Napoleonic Wars > Modifications

Napoleonic Wars basic modding Tutorial.

(1/22) > >>

In this tutorial I will teach you how to make a full modification to Napoleonic Wars. This will be done by showing you how to create a new soldier with new equipment with step by step instructions. At the end you will have a new modification with one new troop.

Programs you will need.
(Some of these vary from different people, these are the ones I use and so will be best able to teach with)
GIMP .DDS plug in (Will show you how to install later, you will need either or depending on whether you're 32 or 64 bit)
Python - link below, important to follow carefully.

Step 1
First we shall do the most basic stepping in creating a new Mod, actually creating the mod folder. Go to your Mount and Blade Warband modules folder (Usually C:\Program Files (x86)\Steam\steamapps\common\MountBlade Warband\Modules), find the Napoleonic Wars folder, copy it, and paste it right into the modules folder again. Wait for it to complete, and then you should have a folder called "Napoleonic Wars - Copy". Rename this folder to "Testmod". You have now created a new module.

Now we shall start on Coding. Coding is the most essential part to modding, responsible for any changes beyond cosmetic. Many beginners don't realise this, and think they can create a mod simply by changing models and textures, in reality this will never go beyond a reskin. While it is possible to edit code by editing the text files, it's not a very effective method and has severe limitations. To really code in Napoleonic Wars you need the module system. The module system is essentially the same as the text files, but put in a manner which is easily understandable and editable, what may be random numbers in the text, is an item attribute in the MS. When you are finished editing the MS it is compiled back into text files which the game reads. However, to do this compiling, you need Python installed to your computer, so before we begin looking at the module system, we must install Python.

Step 2
First you will need to download python, this can be somewhat complicated. Make sure you get this version linked, do not go for the 3+ version, only 2.7 is compatible with the module system.

The picture below shows the version you need.

Now you need to install Python. This is where you need to be cautious, do not try to be smart, make sure you install it in the default location that it asks which is almost always C:\Python27.

Once installed, you need to go to your Environment Variables and make sure Python is at the end of your Path.
To find this:
Windows XP: My Computer (right-click) -> Properties -> Advanced -> Environment Variables
Windows 7/8: My Computer (right-click) -> Properties -> Advanced system settings -> Environment Variables
Here is an Image explaining it for Windows 7/8 in 7 Steps.

Important Notice, the path variable contains things very important to your PC, do not edit or delete anything in the line or you could break your PC, only follow the next instruction.

Now, at Step 7 in the image, go to the very end Variable value line. It should display ;C:\Python27 at the end of the line as in the image above. If it does not, don't worry, not every PC automatically displays it, all you need to do is simply paste ;C:\Python27 at the very end. Once done, click OK to confirm the changes on the opened windows, and then close them.

Step 3
Now that this is done we can get onto the code. If you haven't already, download the Napoleonic Wars module system.
Extract the ZIP folder, giving you a regular folder named "mb_warband_napoleonic_wars_source_1104". Enter this folder and find your way to the folder called "mm dev - MS" following this directory "C:\Users\Will\Downloads\mb_warband_napoleonic_wars_source_1104\Napoleonic Wars Sourcecode\Sourcecode\mm dev - MS"

You will be looking at a large list of Python files, this is the module system for NW, the source code containing all the game information. You will see Header files, ID files, Module Files, and Process files. Most of the time we are only interested in the Module files, the rest are for more complex coding, such as writing your own scripts, so we wont need them much.

The best program to read these files is the text editor Notepad++. Download it here and install it if you haven't yet.

Then, in the module system folder "mm dev - MS", navigate to the file "" and right click it, and open it with Notepad++
You will see something like this.

The line which says "export_dir = "C:/Program Files (x86)/Mount&Blade Warband/Modules/mm dev/" is the export directory to the module, except currently it is not directed at your Testmod, so we need to change this.
Go to your Warband module folder (Usually C:\Program Files (x86)\Steam\steamapps\common\MountBlade Warband\Modules), and open the Testmod folder. Click the Address directory bar at the top and highlight the entire directory address, and copy it like below.

Then, back in Notepad++, replace the default directory of C:/Program Files (x86)/Mount&Blade Warband/Modules/mm dev/ with your Testmod directory, keep it within the quotation marks. Then, we need to change all Backslashes (\), into Forward slashes (/). Make sure you have a slash at the end too, but before the final quote mark. Module_info should now look something like this

Ignore the green line below, any greenline is not read by the module system, it is struck out, they are usually used for making notes within the code. This can be done by placing a # in front of any text.
Now, save the file, do not rename it, just save it in the regular manner.

Now we have to test if everything is set up correctly. Go back to the "mm dev - MS folder" containing the Python files. Scroll to the top (Make sure you're folder is in name order), and you should see a Windows Batch file called "build_module". Double click this, a black command window will open. If everything is in order, you should soon see a line of "Exporting _____" until the end, where it says "Press any key to exit" As shown in this image below.

If it looks like this, you have been successful and your module system and python is correctly installed and directed. Now you can begin to code your mod for real.
You may, however, have encountered an error saying "Python not recognized", this is a common error and results from the path we did before being incorrectly set up. If you have this error, go back to before and make sure your path is correct, otherwise check out this thread specifically for this problem.,35044.0.html

Step 4
Now, onto editing our Testmod. As stated at the beginning, we will be creating a new Troop in the mod which should cover ever aspect of modding. So to begin, we will need to code our new soldier into the game. In Your "mm dev - MS folder", scroll down to the file called "" and open it in Notepad++. This file contains the code for all the soldiers and units which exist within Napoleonic Wars, scrolling down you will first see the code for the Bots, then for the multiplayer units, and near the bottom you'll see unfinished code for the NW singleplayer companions which was never completed. Do not edit anything yet but familiarise yourself with the unit code. For example, on line 459 we see the Code for the first British troop, the 33rd Ranker.

The Red box contains the names of the unit, the first part "british_infantry", is the String name of the unit, this is the part referenced in other files, usually as "trp_british_infantry". The second part "33rd Regiment of Foot" is the name of the unit displayed in game, and the "Line Infantry" part, is the subheader of the unit you see below the unit name. You need not worry about "tf_guarantee_all" in NW other than that all units use this. "fac_britain" means the unit is on the British faction, for sub units such as sergeants, this becomes "fac_british_ranks". The blue box contains the units inventory, his clothing and weapons, this is fairly obvious, the units inventory contains his tunic, trousers, hat, and musket with ammo. The green box is the units stats, all soldiers in NW are set to level 20, the "wpex" numbers are the skills, in the order of Swords (50), Two handed weapons (5), Polearms (130), Archery (5), Crossbows, which are Firearms (150) and throwing (5). The 5s are skills not used in NW such as archery, but the infrastructure is there for if you want a mod with archery for example. The Ironflesh, powerstrike and Athletics are attributes the unit has, remember back to Native, Ironflesh adds 2HP per level, Powerstrike adds extra damage to your melee, and athletics increases the units running speed. Different attributes can be added or removed which we'll do later. Swadian face can be ignored, it just has to be there.

Step 5
Now that you're familiar with how the unit code works, we can create our own soldier. Because Britain already has 6 Infantry types, which fills the selection box, and we don't want to delete or overwrite existing units, we will be adding a new troop to the Austrian Infantry. Scroll down to line 1106 in Module_troops. This is the start of the Austrian units. First, highlight and copy the entire first Austrian Infantry unit as shown below.

Then, scroll down to the bottom of the Austrian Infantry, the last Austrian infantry unit being "austrian_infantry_rifle_horn", and paste the copied troop directly below this unit and between the austrian_hussar . Such as below.

Make sure the blue square brackets line up as well. Now we have pasted a new troop, it's time to start editting him. Where it says "austrian_infantry", change it to say "test_infantry". Where it says "Infantrie Regiment Erzherzog Rudolf Nr. 14", change it to say "Test Soldier", and where it says "Line Infantry", change it to say "Test Infantry". It should now look like this image.

Now, save the file, and build your module as before. Everything should export correctly as before. If you encounter an error in exporting, it will most likely be a Syntax error, which usually results from a misplaced or deleted "," or "[,]". Check your troop line very carefully to make sure everything is in the same position as the other troops to fix this.

If it has built correctly, it's time to load up the test mod. Start Warband, in the module list at the start, select "Testmod" and play, in the same way you would select any module. Go onto Multiplayer, host your own game, and select the faction of Austria and start. At the bottom of the Infantry tab you should see your new troop, like in the image below

Step 6
You have now made a new soldier in NW. Now we shall change some of the stats. Let's make him better at shooting. As mentioned above, this part "wpex(50,5,130,5,150,5)" is the weapon skills. 150 is the soldiers skill with a firearm, this determines his accuracy, and how large the reticle will go when moving while aiming. Change the 150 to 300, this should make him considerably more accurate and noticeable in game. Now lets make him faster, where it says "knows_athletics_3", change the 3 to an 8. Let's also add a new attribute to him, on cavalry units you will notice the attribute "knows_riding_X", this determines the riding skill, and is needed to ride horses, so lets give our unit the ability to ride. Just after "knows_common|" and before "knows_ironflesh_3", type in or copy "knows_riding_6|", the "|" is important as it separates the different attributes. The 3rd line of your Test soldier should now look like this image.

Now lets save the file, and build the module again as before. Wait for it compile and hopefully there should be no errors. If there are none, load up the mod. Check the Austrian faction and your Test soldier as before. This time you should notice he is much more accurate when aiming, runs a lot faster, and can ride horses (you should spawn as cavalry, then respawn as the test soldier to test this). If thats all correct, onto the next part.

Step 7
The test soldiers musket is a bit boring, so we're going to give him a new one, a much better one. For this you will need to open the file "". This contains all the items used in NW. Back in module_troops, at our test troop you will see in his inventory that he uses "itm_austrian_musket". The "itm_" prefix is given to all items in inventories, but isn't mentioned within "module_items" itself. So, within "module_items" either manually search for "austrian_musket", or use Control+f, the search feature, to find it. You will find the code for the austrian_musket on line 260, it looks like this, but without the coloured boxes obviously.

It works in a similar way to the troop code. The red section is the names, the first part "austrian_musket" is the items string, it is the reference used in other files, such as in "module_troops" where it's always given the prefix "itm_". The second part "Infantry Musket", is the name of the item displayed in game. The third part, "austrian_musket" within the brackets, is the name of the mesh, the actual model the game loads for this item, which we will cover later. The blue section contains the "flags" the item uses, these are attributes given to the weapon, they are mostly self explanatory, it's obvious that "itp_cant_reload_on_horseback" means the weapon can't be reloaded on horseback, or that "itp_type_crossbow" means it's a crossbow type weapon (all firearms are built on warbands crossbows) and not a one handed melee weapon which would be "itp_type_one_handed_wpn". This green section is also quite obvious, these are the stats of the weapon, spd_rating is the weapons reload/aiming speed, a higher number means it reloads and aims faster. Weight is the weight of the weapon, in Kilograms, a heavier weight makes you run slower while holding it. Shoot_speed is probably the most complex, this is the velocity of the projectile the weapon fires, so it governs how long it takes for the bullet to hit its target, and governs the amount of bullet drop, it also governs the damage drop off of the projectile over distance, plus, a higher shoot_speed increases the weapons accuracy, alongside the accuracy stat also there. max_ammo is the amount of shots the weapon has before reloading. Thrust_damage is the amount of damage the weapon does. The section below is also important, it's the melee mode for the musket, its enabled by the shooting musket having the flag "itp_next_item_as_melee"

Now that that is covered, we can create a new musket, and change it. Copy the entire austrian_musket code including the melee section. Then make a space below it, and paste it there. There will now be two austrian_muskets. Now, on the new copied musket, change the first "austrian_musket" to "test_musket", and below that change "austrian_musket_melee" to "test_musket_melee". Now, change the in game name from "Infantry Musket" to "Test Musket" on both the shooting and melee version again. Leave the mesh name alone for now. On the shooting Test Musket, change the spd_rating from 23 to 50. Change the shoot_speed from 250 to 400. Then, change the accuracy from 75 to 95. Now change the max_ammo from 1 to 5, this will give the weapon 5 shots before it needs reloading. Now on the shooting Test Muskets flags, remove the part "|itp_cant_reload_on_horseback|itp_cant_reload_while_moving", make sure you only remove one of the "|"s and not both, they are needed to seperate the flags.
Your module_items should now look like below.

Now its time to save and build your module again like before. Don't start up the mod yet though, now we need to give the new musket to the new soldier. Simply copy "test_musket", go to module_troops, to the test soldier, and replace "austrian_musket" with "test_musket", make sure to keep the prefix of "itm_". So his inventory should now be-

Now you can save module_troops, and build your module again. Start up the mod, go to the test soldier, and try out the new musket. It should be very accurate, have 5 shots, and allow you to reload while moving.

Step 8
At this point we have finished coding the troop for now, later on we will give him a new uniform, but it would be quite pointless to do that before we've made a new uniform. But first, lets do a few more basic code tweaks. Let's get rid of that pesky smoke from muskets, just so you know how to tweak it. Go to the module system folder and open "", scroll down to line 1180. Here you will see the code for the smoke which comes out the muskets barrel, luckily there is an explanation along side it. It works the same as most code items and you're probably beginning to see a pattern, fire we have "musket_smoke" and as usual this is the reference string, then we have some particle specific flags, and then "prtcl_dust_a" is the name of the particle model it actually uses. The second line explains itself, we have 75, which is the number of the particles, the next is the life in seconds that the particles last, and the rest involves more complicated things, such as how quickly it falls or rises, whether it falls or rises, how fast it shoots out, and more. We're only interested in removing the smoke, for this, we want to take the first two numbers, the number of particles and the life, and change them both to 0. Then, scroll down a small amount and you will see "pan_smoke", this is the smoke which comes out of the muskets pan, where the flint strikes, lets also change the number of particles and life to 0 here. It should now look like this image.

Save the file, and build the module as before. Load up the game, and fire your musket, you'll see that there is now no smoke at all when firing, only the flash remains.

This concludes the first part of the tutorial which covers basic coding for NW, the next part will cover Openbrf, basic modelling and texturing.

Reserving this post. I will get around to writing the rest one day.


This will be really useful, thanks a ton

Very nice tutorial !


[0] Message Index

[#] Next page

Go to full version