Adding chapters to your mod: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
 
(69 intermediate revisions by 29 users not shown)
Line 1: Line 1:
[[Category:Level Design]] [[Category:Tutorials]] [[Category:Programming]]Adding chapters to your mod is a little complecated because you need to modify a number of files in order to add new chapters.
{{LanguageBar}}
{{toc-right}}


=== STEP 1: Chapter config files ===
{{Tutorial Skill Level|skill=1}}
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 ...
<pre>
map Map1
</pre>


Replacing Map1 with the name of your own map. Do this for each chapter in your mod.
'''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.


=== STEP 2: Strings file ===
Adding chapters to your mod is a little complicated, because you need to modify a number of files in order to add new chapters.
Goto your <code>yourmodfolder/resource</code> folder an 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 fallowing lines above HL2_Chapter1_Title like so ...
<pre>
"YourModName_Chapter1_Title" "Title of the chapter goes here"


"HL2_Chapter1_Title" "POINT INSERTION"
== Scripts ==
</pre>
You can leave the original HL2_Chapter1_Title title entries as they will not affect your mod by being there.


=== STEP 3: Chapter titles === 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 ...
=== Registering a chapter ===
<pre>
//CHAPTER TITLES


$fadein 0.01
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:
$holdtime 3.5
$position -1 0.58


CHAPTER1_TITLE
map <first map of the chapter>
 
Do this for all your chapters.
 
=== Localising names ===
 
Create (or open, if it exists already) <code><mod>\resource\<mod>_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
{
{
#YourModName_Chapter1_Title
Language "English"
Tokens
{
modname_Chapter1_Title "Chapter 1 title"
}
}
}
</pre>
</source>


=== STEP 4: Chapter images ===
If there are existing tokens in the file, don't remove them. Just add yours somewhere.
[[image:CBXChapter1.gif|thumb|Sample Chapter Image]]
Next you will need to create [[Vmt|*.vmt]] and [[Vtf|*.vtf]] image files for your chapters. Place the *.vmt and *.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 respectivly.


Make sure to make the image files 256x128 in size (IE: Power of 2). Also be aware that when your chapter is selected in the new game dialog that only a portion of the image will be visible from the top left corner pixel 1,0 to the bottom right corner pixel 152,86.
{{note|Localization files must be saved in the '''UCS-2 Little Endian''' format. <br>In Notepad's "Save As..." dialogue this is called "Unicode".<br> In Notepad++, in Toolbars > Encoding, this is called "UCS-2 LE BOM".}}


=== STEP 5: The map list ===
{{note|Wrap any keys or values with whitespace in "quote marks".}}
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 ...
<pre>
Map1
Map2
</pre>


=== STEP 6: Chapter map loading images ===
=== Fixing on-screen titles ===
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.
 
<pre>
<code><mod>\scripts\titles.txt</code> defines what appears on-screen when a new chapter starts.
"chapters"
 
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 ===
 
[[File:CBXChapter1.gif|right|border|A chapter image]]
[[File:HL2_Update_-_Custom_highres_chapters_thumbnail_demo.jpg|right|thumb|Using lower resolution 256x128 chapter image and having VGUI scale higher than 1, will either cause the image to look blurry, or pixelated (depends whether "Point Sample" VTF flags is used), on higher resolution display with the game running at higher UI scale. Using higher resolution thumbnail makes it less blurry/pixelated.]]
You need to [[Creating a Material|create thumbnails]] for each of your chapters. They should be in {{code|<mod>\materials\vgui\chapters\}} and named chapter1, chapter2, chapter3 etc.
 
{{note|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.
{{Note|For {{hl2|2}} 20th anniversary (and also games on {{tf2branch|2}}), which support VGUI High-DPI scaling, higher resolution such as 512x256 can be also used, to make chapter thumbnail less blurry or pixelated on higher DPI display. You will need to add {{code|[[$basetexturetransform]]}} if you use high resolution.}}
}}
{{note|For the Gamepad UI (used on {{steamdeck|4}} by default), the chapter thumbnails are instead located in {{code|materials\gamepadui\chapter#.vtf}}, and they are in higher "2048x1024" resolution.}}
{{note|Since these are UI textures, they should be compiled without [[mipmap]]s and with level of detail disabled. The [[Vtex (Source 1)|VTEX]] commands for this are <code>nomip</code> and <code>nolod</code>.
Disabling mipmapping are not required for Gamepad UI thumbnails.
}}
 
Your material should look something like this:
{{codeblock|<nowiki>"UnlitGeneric"
{
{
1 "YourImage1"
"$baseTexture" "VGUI/chapters/chapter1"
2 "YourImage3"
"$vertexalpha" 1
3 "YourImage3"
"$basetexturetransform" "center 0 0 scale 2 2 rotate 0 translate 0.00 0.000" // Not required for 256x128, but required for higher resolutions VTFs.
4 "YourImage4"
For example: if 256x128 x 2 = 512x256, set scale to "2 2" respectively.
5 "background03"
}</nowiki>}}
6 "background03"
 
7 "background04"
=== Backgrounds ===
8 "background04"
 
9 "background05"
<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).
9a "background05"
 
10 "background06"
Here is what it might look like:
11 "background06"
 
12 "background07"
chapters
13 "background07"
{
14 "background07"
1 "my_background01"
15 "background07"
2 "my_background02"
}
3 "my_background03"
</pre>
}
Be sure to create your images 1024x1024. The trick to creating a image that is displayed properly in either 4:3, 16:9, or 16:10 is to create a 1024x768 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.
 
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 ===
 
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 work around this issue by starting your mod off with all chapters unlocked (set <code>sv_unlockedchapters</code> to the number of chapters your mod has in <code><mod>\cfg\modsettings.cfg</code>). To [[Unlocking chapters in your mod|actually unlock chapters]], you will need to edit your mod's code, or hack it within maps. The latter method is not recommended unless you are modding a game such as Portal that does not provide code.
 
=== 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 <code>OnNewGame</code> output to spawn a [[point_template]].
 
=== The map list ===
 
This is not necessary but is used to easily find the names of maps without quitting and relaunching the game. <BR>
Create <code><mod>\maplist.txt</code> and list of maps that your mod will use. For example:
 
Map1
Map2
 
== Creating chapters with XBLAH's Modding Tool ==
Chapters for single-player games can be created with {{Xblahmt|4}} through an UI. The modder can easily create new chapters, select the chapter images, chapter background images, the first map of the chapter, the background map, and the tool will do the dirty work of creating the required vtfs, vmts and scripts. It gives the option to automatically blur the background images, so the modder can just take a screenshot of the background map and the tool will apply the usual blur. This replaces the need of saving VTFs, creating chapter images with weird proportions, and so on.
 
<br/><span style="color: #FFFFFF; font-weight: bold">Where to find it</span><br/>
This can be accessed within the tool through '''Mod > Chapters'''.
 
<br/><span style="color: #FFFFFF; font-weight: bold">How to use it</span>
 
You can insert a new chapter by clicking [[File:XBLAH's Modding Tool - Add Button.png|Add button]] button.


=== Additional notes ===
Select a chapter ID (Example 1, 2, 3, or A, B, C, etc) and a chapter title. Right click the picture box next to the Chapter Image label and select a screenshot to show up in the New Menu window. Right click the picture box next to the Chapter Background label and select a screenshot to show up as the menu background (or as the loading screen if a background map is set). Select the map that will load when the user selects that chapter, and, optionally, select a background map.
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 ...
<pre>
sv_unlockedchapters "1"
</pre>


[[File:XBLAH's Modding Tool - Chapters v1.17.0.png]]


'''This tutorial also needs to describe how to have your map unlock chapters. I currently have not got to this point yet. Someone please add the info to this page as a step 7. In time (when I know how) I will add the info'''
== External links ==


--[[User:Createdbyx|Created by: X]] 13:26, 31 Aug 2005 (PDT)
*[https://modding-assets.net/source/tools/modding/xblah-modding-tool/ XBLAH's Modding Tool Homepage]
[[Category:Level Design]]

Latest revision as of 06:38, 12 March 2025

English (en)Français (fr)Русский (ru)Translate (Translate)


Skill Level

This tutorial expects you to have this amount of knowledge within the topic to follow along smoothly.

Novice Familiar Competent Proficient Expert


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\<mod>_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".
In Notepad++, in Toolbars > Encoding, this is called "UCS-2 LE BOM".
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
Using lower resolution 256x128 chapter image and having VGUI scale higher than 1, will either cause the image to look blurry, or pixelated (depends whether "Point Sample" VTF flags is used), on higher resolution display with the game running at higher UI scale. Using higher resolution thumbnail makes it less blurry/pixelated.

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

Note.pngNote: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.
Note.pngNote:For Half-Life 2 Half-Life 2 20th anniversary (and also games on Team Fortress 2 branch Team Fortress 2 branch), which support VGUI High-DPI scaling, higher resolution such as 512x256 can be also used, to make chapter thumbnail less blurry or pixelated on higher DPI display. You will need to add $basetexturetransform if you use high resolution.
Note.pngNote:For the Gamepad UI (used on Steam Deck Steam Deck by default), the chapter thumbnails are instead located in materials\gamepadui\chapter#.vtf, and they are in higher "2048x1024" resolution.
Note.pngNote: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.

Disabling mipmapping are not required for Gamepad UI thumbnails.

Your material should look something like this:

"UnlitGeneric" { "$baseTexture" "VGUI/chapters/chapter1" "$vertexalpha" 1 "$basetexturetransform" "center 0 0 scale 2 2 rotate 0 translate 0.00 0.000" // Not required for 256x128, but required for higher resolutions VTFs. For example: if 256x128 x 2 = 512x256, set scale to "2 2" respectively. }

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 work around this issue by starting your mod off with all chapters unlocked (set sv_unlockedchapters to the number of chapters your mod has in <mod>\cfg\modsettings.cfg). To actually unlock chapters, you will need to edit your mod's code, or hack it within maps. The latter method is not recommended unless you are modding a game such as Portal that does not provide code.

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

This is not necessary but is used to easily find the names of maps without quitting and relaunching the game.
Create <mod>\maplist.txt and list of maps that your mod will use. For example:

Map1
Map2

Creating chapters with XBLAH's Modding Tool

Chapters for single-player games can be created with XBLAH's Modding Tool XBLAH's Modding Tool through an UI. The modder can easily create new chapters, select the chapter images, chapter background images, the first map of the chapter, the background map, and the tool will do the dirty work of creating the required vtfs, vmts and scripts. It gives the option to automatically blur the background images, so the modder can just take a screenshot of the background map and the tool will apply the usual blur. This replaces the need of saving VTFs, creating chapter images with weird proportions, and so on.


Where to find it
This can be accessed within the tool through Mod > Chapters.


How to use it

You can insert a new chapter by clicking Add button button.

Select a chapter ID (Example 1, 2, 3, or A, B, C, etc) and a chapter title. Right click the picture box next to the Chapter Image label and select a screenshot to show up in the New Menu window. Right click the picture box next to the Chapter Background label and select a screenshot to show up as the menu background (or as the loading screen if a background map is set). Select the map that will load when the user selects that chapter, and, optionally, select a background map.

XBLAH's Modding Tool - Chapters v1.17.0.png

External links