Unlocking chapters in your mod: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (fixed code tags)
Line 5: Line 5:
Your maps should be renamed to conform to a pattern
Your maps should be renamed to conform to a pattern
== Updating ==
== Updating ==
In <code>gameinterface.cpp</code>, modify <code>void UpdateChapterRestrictions( const char *mapname )</code> to conform to your maps' naming format.
In <code>gameinterface.cpp</code>, modify <code>void UpdateChapterRestrictions( const char* mapname )</code> and the array <code>static TITLECOMMENT gTitleComments[]</code> to conform to your maps' naming format.
 
Each TITLECOMMENT in gTitleComments contains a <code>char* pBSPName</code> (the map name or part of a map name) and a <code>char* pTitleName</code> (the chapter that map or set of maps is part of). If you want the map e2m4 to be part of Chapter 2 of the mod "Doom", add <code>{"e2m4", "#Doom_Chapter2_Title"}</code> to the array (with a trailing comma if it's not last, of course). Replace "e2m4" with simply "e2" and ALL maps starting with "e2" will be part of Chapter 2.
 
Note the comment right above gTitleComments, which reads "This list gets searched for the first partial match, so some are out of order". Meaning, if e2m9 is part of Chapter 3 and the rest of the "e2" maps are in Chapter 2,  then <code>{"e2m9", "#Doom_Chapter3_Title"}</code> must come <b>before</b> <code>{"e2", "#Doom_Chapter2_Title"}</code> in the array.
 
Note that UpdateChapterRestrictions has an inherent flaw which only comes to light when Steam runs a Source mod. Steam puts the mod's entire path in the command line; a mod in C:\Steam\SteamApps\SourceMods\MyMod will be run with <code>hl2.exe -game "C:\Steam\SteamApps\SourceMods\MyMod"</code>.
 
But UpdateChapterRestrictions() assumes "-game" to be just "MyMod", so <code>char chapterNumberPrefix[64]</code> ends up as <code>#C:\Steam\SteamApps\SourceMods\MyMod_chapter</code>, rather than <code>#MyMod_chapter</code> as it should be.
 
The solution, then, is to lop off the path bit by bit until only the mod folder is left. Paste this
// in case "-game" is a full path -- we want only the name of the mod folder
char* subdir = strtok( pGameDir, "/\\" );
while (subdir)
{
pGameDir = subdir;
subdir = strtok(0, "/\\");
}
 
immediately after
strlwr( chapterTitle );
 
 
Then replace
const char *pGameDir = CommandLine()->ParmValue( "-game", "mymod" );
with
char *pGameDir = (char*)CommandLine()->ParmValue( "-game", "mymod" );
strlwr( pGameDir );
// Because chapterTitle was made lowercase, the mod name must be lowercase too


=Map Hack Approach=
=Map Hack Approach=

Revision as of 00:48, 13 September 2005


VALVe Approach

Renaming

Your maps should be renamed to conform to a pattern

Updating

In gameinterface.cpp, modify void UpdateChapterRestrictions( const char* mapname ) and the array static TITLECOMMENT gTitleComments[] to conform to your maps' naming format.

Each TITLECOMMENT in gTitleComments contains a char* pBSPName (the map name or part of a map name) and a char* pTitleName (the chapter that map or set of maps is part of). If you want the map e2m4 to be part of Chapter 2 of the mod "Doom", add {"e2m4", "#Doom_Chapter2_Title"} to the array (with a trailing comma if it's not last, of course). Replace "e2m4" with simply "e2" and ALL maps starting with "e2" will be part of Chapter 2.

Note the comment right above gTitleComments, which reads "This list gets searched for the first partial match, so some are out of order". Meaning, if e2m9 is part of Chapter 3 and the rest of the "e2" maps are in Chapter 2, then {"e2m9", "#Doom_Chapter3_Title"} must come before {"e2", "#Doom_Chapter2_Title"} in the array.

Note that UpdateChapterRestrictions has an inherent flaw which only comes to light when Steam runs a Source mod. Steam puts the mod's entire path in the command line; a mod in C:\Steam\SteamApps\SourceMods\MyMod will be run with hl2.exe -game "C:\Steam\SteamApps\SourceMods\MyMod".

But UpdateChapterRestrictions() assumes "-game" to be just "MyMod", so char chapterNumberPrefix[64] ends up as #C:\Steam\SteamApps\SourceMods\MyMod_chapter, rather than #MyMod_chapter as it should be.

The solution, then, is to lop off the path bit by bit until only the mod folder is left. Paste this

// in case "-game" is a full path -- we want only the name of the mod folder
char* subdir = strtok( pGameDir, "/\\" );
while (subdir)
{
	pGameDir = subdir;
	subdir = strtok(0, "/\\");
}

immediately after

strlwr( chapterTitle );


Then replace

const char *pGameDir = CommandLine()->ParmValue( "-game", "mymod" );

with

char *pGameDir = (char*)CommandLine()->ParmValue( "-game", "mymod" );
strlwr( pGameDir ); 
// Because chapterTitle was made lowercase, the mod name must be lowercase too

Map Hack Approach

This tutorial will demonstrate one way to unlock chapters for your game mods using entities. If you are unfamilair with adding chapters to your mod read and review the Adding chapters to your mod tutorial before this one.

Create the trigger once brush

Create a trigger_once brush in Map2. This will be used as the trigger that will begin the process of unlocking a chapter. Map2 is the map that will be considered the first map for the second chapter. Be sure to give the trigger_once brush a name, something like Trigger001_UnlockChapter2 for example.

Create the point entities

Use the entity tool the create a logic_relay entity. Set the name of the logic_relay entity to Logic001_UnlockChapter2. Set the logic_relay Start Disabled property to Yes.

Now use the entity tool to create a point_clientcommand entity, and set the name to UnlockChapter2.

Add the outputs for the logic relay

Open the object properties dialog for the logic_relay entity we created earlier, and select the Outputs tab. Now add a output using the add button and fill in the info as it appears in the picture below...
UnlockChapObjectProps.png

Add the outputs for the trigger_once brush entity

Next open the object properties dialog box for the trigger_once entity we created earlier called Trigger001_UnlockChapter2, and select the Outputs tab. Now add a output using the add button and fill in the info as it appears in the picture below...
UnlockChapObjectProps2.png

Testing

Now save and compile your map. And run your mod. After your mod is loaded play the map and walk thru the invisible trigger_once entity. After you have walked through it press escape and select New Game from the game menu. You should that chapter 2 in your mod has been unlocked.

After you quit the game open up the yourmodfolder/cfg/config.cfg file and scroll down near the botton of the file and you will notice that the line that used to read sv_unlockedchapters "1" now reads sv_unlockedchapters "2".