From The Battle for Wesnoth Wiki
Revision as of 00:44, 25 January 2007 by NeoPhile (talk | contribs) (Using your new unit: Corrected/clarified info, fixed double-spaces after periods.)

Making new units is fairly easy. Unit configuration files are plain text files that you can edit with any editor such as Notepad, TextEdit, gedit, pico, vi, emacs, etc. You will need to become familiar with WML in order to make a new unit. This page contains a more in-depth discussion of Unit WML syntax and will walk you through the creation of a new unit and discuss how you can use it in-game.

Recommended procedure

The easiest way to make a new unit is to copy and paste an existing unit, then modify it. Navigate to the game's data/units directory and copy any unit. When you are editing the unit, attention to detail is key. If you forget to modify each key (for example, the unique id key), problems will result.

P.S. Make sure you use gimp to create a blank background.

Using your new unit

Any unit in the game's ./data/units directory or userdata/data/units will be recognized by the game. If you only want to put use it once or twice as a special unit, that's all you need to do. However, just because you made a new unit does NOT mean that it can be recruited. Each scenario and multiplayer era has a specific recruit list. If your unit is not on the list, you can't recruit it. This means you need to modify the recruit= key in the appropriate configuration file. BuildingMultiplayer describes different ways you do this for multiplayer. To add a unit to a campaign, read about scenarios, sides, and recruit lists in BuildingScenarios. File:Paladin 605.jpg

Distributing your unit

If you made a single unit, post it on the forum. If you made a whole group of units, you can make them into a multiplayer faction or you can upload a unit pack.

If you want to make a faction, follow the instructions in the BuildingFactions article. You should create a new era and add your units as one of the factions. You will not be able to add your units to any era that ships with the game.

If you want to make a unit pack, the procedure is easier. Unit packs are distributed for campaign writers who want to use your units in their campaigns/eras. They download your unit pack and copy/paste the units and images into their campaign/era.

  • Navigate to the userdata/data/campaigns directory. Everything from now on will occur relative to here. The era we'll use as an example will be called MyUnitPack
  • Create a text file called MyUnitPack.cfg. Add the following lines:
#		#define USE_MYUNITS		#<- replace MYUNITS with something descriptive
#		#enddef
#		#ifdef USE_MYUNITS		#<- replace MYUNITS with something descriptive
#		{@campaigns/MyUnitPack/}
#		#endif
  • These lines are commented out (with the #). That way when the unit pack ships it won't affect the game. If someone wants the game to be able to see these units, he can uncomment those lines and it will work. However, this usually causes problems in multiplayer (you will be using units no one else has), but it can be fun for campaigns.
  • NOTE: the commenting/uncommenting trick will only work if the units branch off of an existing unit. Custom L1 units will NOT show up in game automatically without editing another configuration file somewhere (scenario config file or multiplayer.cfg)
  • Create another text file called MyUnitPack.pbl. (See PblWML for more details about *.pbl files.) Add the following lines to it:
author="your name"
icon="any image file in the game's ./images directory"
title="My Awesome Unit Pack"
description="New race of lizard men."
  • Create a folder called MyUnitPack. Navigate to it.
  • Create two subdirectories: units and images. Place your unit cfg files and artwork into those subdirectories
  • Create a text file called MyUnitPack.cfg (or another name of your choosing). Add the following lines:
  • You should be ready to distribute your unit pack on the campaign server now
  • PLEASE change the names to something unique before you publish

Unit WML discussion

Units are enclosed in [unit] tags.

This section only provides some tips and pointers in making a unit. Feel free to add pointers of your own. For the full, current, complete WML reference on what to put in your [unit], see and frequently revisit The Unit WML reference page.

  • The first attribute of a unit is the id key, which is a unique identifier for the unit. As value of the type attribute for these units, the id key is used. (See BuildingScenarios).
  • When referencing the unit in a type key, the id must be reproduced verbatim, without typos, and in a case-sensitive manner. If you don't do this, the key won't work. If you can't recruit in a scenario, it's probably because you have a typo in one of the unit ids and the recruit key was invalidated.
  • It also has a name key, which is the (translatable) name of the unit, and is displayed on the Status Table when a unit of this type is selected. It does not need to be unique (but it helps).
  • Do not set movement to 0. It creates weird infinite movement behavior. This might be fixed in the future. For now, to make an immobile unit, set movement to 1 use [movement_costs] to make it unable to move onto any terrain.
  • Also, make sure you give the unit at least one [attack]. If not, there is a bug in the game code that will cause the game to crash when it attempts to find attacks. This may also be fixed in the future.
  • See BuildingScenariosIntermediate for more information on attacks.

See Also