Adding chapters to your mod: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (Reverted edit of C4tpaSacel, changed back to last version by Etset)
(cleanup)
Line 1: Line 1:
Adding chapters to your mod is a little complicated because you need to modify a number of files in order to add new chapters.
{{toc-right}}


{{warning|'''Half-Life 2 uses unicode for the localization file. Some text editors may save the file as ASCII-encoded.<br>Use Notepad or another Unicode-savvy editor to edit these files.'''}}
'''Chapters''' are used to split single-player mods down into manageable chunks. They give your story more structure and allow players to jump into the game half-way through if they so desire. They can also be used to control which background maps/images are displayed.


== Chapter config files ==
Adding chapters to your mod is a little complicated, because you need to modify a number of files in order to add new chapters.


Create a chapter1.cfg file and put it in the cfg folder like so <code>yourmodfolder/cfg/chapter1.cfg</code>. Then edit the file to read ...
== Scripts ==


map Map1
=== Registering a chapter ===


Replacing Map1 with the name of your own map. Do this for each chapter in your mod.
Create <code>\mod\cfg\chapter1.cfg</code>. This will create a chapter, and contains the [[console command]]s that the game will run when it is started. Typically just:


== Strings file ==
map <first map of the chapter>


Goto your <code>yourmodfolder/resource</code> folder and copy the HL2_english.txt file and give it the name YourModName_english.txt. (Again replacing YourModName with the name of your mod) Now you will need to edit the YourModName_english.txt file. At the top of the file add the following lines above HL2_Chapter1_Title like so ...
Do this for all your chapters.


"YourModName_Chapter1_Title" "Title of the chapter goes here"
=== Localising names ===
 
"HL2_Chapter1_Title" "POINT INSERTION"
Create (or open, if it exists already) <code>\mod\resource\<modname>_english.txt</code> (or <code>_french</code>, <code>_japanese</code>, etc). This is your mod's [[localisation]] file, where you write the [[unicode]] titles for your chapters.
 
Yours should look something like this:
 
<source lang=ini>
lang
{
Language "English"
Tokens
{
modname_Chapter1_Title "Chapter 1 title"
}
}
</source>
 
If there are existing tokens in the file, don't remove them. Just add yours somewhere.
 
{{note|Localization files must be saved in the '''UCS-2 Little Endian''' format. In Notepad's "Save As..." dialogue this is called "Unicode".}}
 
{{note|Wrap any keys or values with whitespace in "quote marks".}}


You can leave the original HL2_Chapter1_Title title entries as they will not affect your mod by being there.
=== Fixing on-screen titles ===


== Chapter titles ==
<code>\mod\scripts\titles.txt</code> defines what appears on-screen when a new chapter starts.


Open up the <code>yourmodfolder/scripts/titles.txt</code> file and scroll down to the CHAPTER TITLES section and modify the chapters entries like so ...
Find the "chapter titles" section and modify it like so:


  //CHAPTER TITLES
  //CHAPTER TITLES
Line 36: Line 55:
  }
  }


== Chapter images ==
This file should be saved as normal ANSI.


[[image:CBXChapter1.gif|thumb|Sample Chapter Image]]
== Images ==


Next you will need to create [[VMT|*.vmt]] and [[VTF|*.vtf]] image files for your chapters. Place the [[VMT|*.vmt]] and [[VTF|*.vtf]] files into the <code>yourmodfolder/materials/vgui/chapters/</code> folder. Be sure to name your images chapter1.vtf, chapter1.vmt and chapter2.vtf, chapter2.vmt respectively.
=== Thumbnails ===


Make sure that:
[[File:CBXChapter1.gif|right|border|A chapter image]]


*The image files are 256x128 in size, i.e., a power of 2. (When your chapter is selected in the new game dialogue that only the portion from 0,0 to 152,86 will be visible.)
You need to [[Creating a Material|create materials]] for each of your chapters. They should be in <code>\mod\materials\vgui\chapters\</code> and named chapter1, chapter2, chapter3 etc.
*The images are marked with <code>[[nomip]]</code> and <code>[[nolod]]</code>. The same goes for your menu backgrounds: without these parameters, people using medium or low texture detail will have blurry menu graphics. '''You can't set these options in the .vmt!''' You set them using a text file with the same name as the .tga image you are compiling; see [[Vtex_compile_parameters|Vtex compile parameters]] for more information.


The .vmt file should look like this
* The images displayed in the new game dialogue are 152x86. Since texture dimensions must both be a power of two, your VTFs will be 256x128 with a border to the right and bottom.
* Since these are UI textures, They should be compiled without [[mipmap]]s and with level of detail disabled. The [[VTEX]] commands for this are <code>nomip</code> and <code>nolod</code>


  "UnlitGeneric"
Your material should look something like this:
 
  UnlitGeneric
  {
  {
  "$basetexture" "vgui/chapters/chapter1"
  $basetexture vgui/chapters/chapter1
  "$vertexalpha" 1
  $vertexalpha 1
  }
  }


== The map list ==
=== Backgrounds ===
Now that you have your images setup do not forget to create a <code>yourmodfolder/maplist.txt</code> file containing a list of maps that your mod will use. For example inside a maplist.txt file would look like ...
 
Map1
Map2


== Chapter map loading images ==
<code>\mod\scripts\chapterbackgrounds.txt</code> ties background maps and images to chapters. A background will not be used until the chapter it is associated with has been unlocked (see next section).


You will need to edit the <code>yourmodfolder/scripts/chapterbackgrounds.txt</code> file and specify what loading images you want to be displayed while your mod is starting and the background map is loading. Below is an example of what a chapterbackgrounds.txt might look like.
Here is what it might look like:


  "chapters"
  chapters
  {
  {
  1 "YourImage1"
  1 "my_background01"
  2 "YourImage3"
  2 "my_background02"
  3 "YourImage3"
  3 "my_background03"
4 "YourImage4"
5 "background03"
6 "background03"
7 "background04"
8 "background04"
9 "background05"
9a "background05"
10 "background06"
11 "background06"
12 "background07"
13 "background07"
14 "background07"
15 "background07"
  }
  }


{{note|If you do not want background maps for your mod, create a <code>valve.rc</code> in your <code>cfg</code> folder without the <code>startupmenu</code> command in it.}}
Each value should be the name of a map in <code>\mod\maps\</code> (unless you don't want background maps at all) and a material in <code>\mod\materials\console\</code>. It's okay to omit a chapter.
 
See [[Menu Background Map]] for more details.
 
== Maps ==
 
=== Unlocking chapters ===


// load the base configuration
By default, all chapters except the first start off locked. Unfortunately, Valve's not-terribly-good method of unlocking requires your maps to have the same names as theirs!
//exec default.cfg
 
You can overcome this issue by starting your mod off with all chapters unlocked (edit the <code>sv_unlockedchapters</code> line in <code>\mod\cfg\config.cfg</code>), [[Unlocking chapters in your mod|or by changing your mod's programming]]. Hacking it within maps is not recommended.
// Setup custom controller
 
exec joystick.cfg
=== Equipping players ===
// run a user script file if present
exec autoexec.cfg
//
// stuff command line statements
//
stuffcmds


Be sure to create your images 1024x1024. The trick to creating an image that is displayed properly in either 4:3, 16:9, or 16:10 is to create a 1024x768 (or 1280x1024 to scale down) image then resize it to 1024x1024 before saving it. For widescreen you would start by creating 1280x800 for example, then resize it to 1024x1024. See [[Creating Menu Background Maps]] for more info on this topic.
Players who start a new game at a chapter half-way through your mod will drop into the world without any items. To equip them with the weapons and other goodies they are supposed to have, use a [[logic_auto]]'s <code>OnNewGame</code> output to spawn a [[point_template]].


== Additional notes ==
=== The map list ===


If you want your chapters to be unlocked when you first play your mod then be sure to edit the <code>yourmodfolder/cfg/config.cfg</code> file. Scroll down to about line 162 and edit the line ...
Create <code>\mod\maplist.txt</code> and list of maps that your mod will use. For example:


  sv_unlockedchapters "1"
  Map1
Map2


For information on how to unlock chapters read the [[Unlocking chapters in your mod]] tutorial.
{{todo|Is this really necessary?}}


[[Category:Level Design]]
[[Category:Level Design]]
[[Category:Tutorials]]
[[Category:Tutorials]]
[[Category:Programming]]

Revision as of 04:41, 19 August 2009

Chapters are used to split single-player mods down into manageable chunks. They give your story more structure and allow players to jump into the game half-way through if they so desire. They can also be used to control which background maps/images are displayed.

Adding chapters to your mod is a little complicated, because you need to modify a number of files in order to add new chapters.

Scripts

Registering a chapter

Create \mod\cfg\chapter1.cfg. This will create a chapter, and contains the console commands that the game will run when it is started. Typically just:

map <first map of the chapter>

Do this for all your chapters.

Localising names

Create (or open, if it exists already) \mod\resource\<modname>_english.txt (or _french, _japanese, etc). This is your mod's localisation file, where you write the unicode titles for your chapters.

Yours should look something like this:

lang
{
	Language "English"
	Tokens
	{
		modname_Chapter1_Title	"Chapter 1 title"
	}
}

If there are existing tokens in the file, don't remove them. Just add yours somewhere.

Note.pngNote:Localization files must be saved in the UCS-2 Little Endian format. In Notepad's "Save As..." dialogue this is called "Unicode".
Note.pngNote:Wrap any keys or values with whitespace in "quote marks".

Fixing on-screen titles

\mod\scripts\titles.txt defines what appears on-screen when a new chapter starts.

Find the "chapter titles" section and modify it like so:

//CHAPTER TITLES

$fadein 0.01
$holdtime 3.5
$position -1 0.58

CHAPTER1_TITLE
{
#YourModName_Chapter1_Title
}

This file should be saved as normal ANSI.

Images

Thumbnails

A chapter image

You need to create materials for each of your chapters. They should be in \mod\materials\vgui\chapters\ and named chapter1, chapter2, chapter3 etc.

  • The images displayed in the new game dialogue are 152x86. Since texture dimensions must both be a power of two, your VTFs will be 256x128 with a border to the right and bottom.
  • Since these are UI textures, They should be compiled without mipmaps and with level of detail disabled. The VTEX commands for this are nomip and nolod

Your material should look something like this:

UnlitGeneric
{
	$basetexture vgui/chapters/chapter1
	$vertexalpha 1
}

Backgrounds

\mod\scripts\chapterbackgrounds.txt ties background maps and images to chapters. A background will not be used until the chapter it is associated with has been unlocked (see next section).

Here is what it might look like:

chapters
{
	1	"my_background01"
	2	"my_background02"
	3	"my_background03"
}

Each value should be the name of a map in \mod\maps\ (unless you don't want background maps at all) and a material in \mod\materials\console\. It's okay to omit a chapter.

See Menu Background Map for more details.

Maps

Unlocking chapters

By default, all chapters except the first start off locked. Unfortunately, Valve's not-terribly-good method of unlocking requires your maps to have the same names as theirs!

You can overcome this issue by starting your mod off with all chapters unlocked (edit the sv_unlockedchapters line in \mod\cfg\config.cfg), or by changing your mod's programming. Hacking it within maps is not recommended.

Equipping players

Players who start a new game at a chapter half-way through your mod will drop into the world without any items. To equip them with the weapons and other goodies they are supposed to have, use a logic_auto's OnNewGame output to spawn a point_template.

The map list

Create \mod\maplist.txt and list of maps that your mod will use. For example:

Map1
Map2
Todo: Is this really necessary?