Making Your Portal Mod: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(A couple of the modifications were inaccurate, but not most of them, so I modified them rather than reverting.)
(Implemented Cleanup -> Rewrite)
Line 1: Line 1:
{{cleanup}}
This article will discuss how to create a Portal content mod, from scratch. Part
Modding Portal isn't hard as it seems. In fact, it's only slightly more difficult than modding any other Source-based game released before Alien Swarm (such as Half-Life 2). However, you will need to use a completely different method to modding Half-Life 2, but it is in no way more difficult.
of the reason for creating the mod from scratch is that Valve does not provide a
You do not need any tools to do this (apart from Windows, Steam and a copy of Portal on Steam).
specific SDK or mod template for Portal. Another reason is that creating the mod
Remember, you can't modify the executables, libraries, or anything like that. You CAN modify/create scenes, scripts, sounds, textures, models, or anything else that isn't completely built into the game.
from scratch is not difficult and is of general interest to Source SDK
developers that would like to learn more about how everything works. So, let's
get started.


== Step 1 - Getting Started ==
In a Windows Explorer window, navigate to the "steamapps\sourcemods" subdirectory in the directory where Steam is installed.
Inside, create a folder. For this tutorial I will use "MyPortalMod". You can use anything -- it does not affect the mod's actual name.
Then, make the following folders:
* cfg
* resource
* maps
* materials -- Optional
* models -- Optional
* sound -- Optional
* scripts -- Optional
* scenes -- Optional


== Step 2 - Create files ==
{{note| Portal modification is different from some of the other Source based games in that source code to build the <code>client.dll</code> and <code>server.dll</code> files is not provided by Valve. However, a modder can still modify anything that isn't built directly into the game, which includes scenes, scripts, sounds, textures, and models, to name a few.}}
Create and open a file called GameInfo.txt.


Copy and paste this into the file and then we'll go through what it means.
 
<pre>"GameInfo"
== Prerequisites ==
 
To follow along with this article, you will need a copy of Portal and the Source
SDK, installed on Steam.
 
The article uses a command shell to describe simple file manipulations. The
commands used are:
{| class=standard-table
! Command              || Description
|-
| <code>cd</code>      || Change directory
|-
| <code>mkdir</code>    || Create a directory
|-
| <code>new-item</code> || Create an empty file (roughly)
|}
 
 
== Creating the Mod ==
 
Creating the mod consists of creating a game folder and filling it with
configuration files and mod-related content. Let's assume we are creating a mod
named "My Portal Mod". Further, let <code>[Steam Root]</code> be Steam's
installed path on your machine. (e.g. <code>C:\Program Files (x86)\Steam</code>)
 
 
=== Create the Game Folder ===
 
Navigate to your <code>SourceMods</code> directory and create a folder named
"MyPortalMod".
 
    $> cd "[Steam Root]\steamapps\SourceMods"
    $> mkdir MyPortalMod
 
In this new directory, create a file called <code>GameInfo.txt</code>.
 
    $> new-item GameInfo.txt -type file
 
Edit the contents of <code>GameInfo.txt</code> so that they look similar to the
following snippet. For details about the structure of this file, see
[[Gameinfo.txt]].
 
<source>
"GameInfo"
{
{
  game     "MyPortalMod"
    game   "My Portal Mod"
  title       "MyPortalMod"
    title "My Portal Mod"
  type     singleplayer_only
    type   singleplayer_only
  "icon"     "icon"
    icon   "myportalmod" // Assumes myportalmod.tga is in the same directory as GameInfo.txt
 
    nodifficulty  1
    hasportals    1


  nodifficulty  1
    FileSystem
  hasportals  1
    {
        SteamAppId  400
        ToolsAppId  211     


  FileSystem
        SearchPaths
  {
        {
      SteamAppId            400
            Game  |gameinfo_path|.
      ToolsAppId            211     
            Game  portal
            Game  hl2
        }
    }
}
</source>


      SearchPaths
Restarting Steam at this point will create an entry in the game Library for the
      {
mod. Deleting the game folder we created or removing the
        Game            |gameinfo_path|.
<code>GameInfo.txt</code> file will remove the entry.
        Game            portal
        Game            hl2
      }
  }
}</pre>


* <code>game "MyPortalMod"</code> tells Steam that the name of this game is MyPortalMod. This will appear in the Steam menu.


* <code>title "MyPortalMod"</code> tells Source that it should display the title MyPortalMod on the titlescreen.
=== Configure the Mod ===


* <code>type singleplayer_only</code> tells Source that this is NOT a multiplayer game. This makes the "multiplayer" tab not appear in Options.
==== Initial Setup ====


* <code>"icon" "icon"</code> tells Steam to look for a file called icon.tga, which will be the game's icon. Note: The FIRST "icon" is telling Steam this is the icon line, the SECOND icon is telling it to look for a file called icon.tga.
Let's add some standard folders to the game directory that will hold our mod's
configuration files and content. Add the following folders to your game
directory:
* <code>cfg</code>
* <code>resource</code>
* <code>maps</code>.


* <code>nodifficulty 1</code> tells Source not to show difficulty settings.
While we're at it, let's add the following optional folders, for custom content
like models and sounds:
* <code>materials</code>
* <code>models</code>
* <code>scenes</code>
* <code>scripts</code>
* <code>sound</code>


* <code>hasportals 1</code> tells Portal's Source that this game includes portals. If on, the "Portals" tab will appear in options.
    $> cd "[Steam Root]\steamapps\SourceMods\MyPortalMod"
    $> mkdir cfg
    $> mkdir resource
    $> mkdir maps
    $> mkdir materials
    $> mkdir models
    $> mkdir scenes
    $> mkdir scripts
    $> mkdir sound


The rest is telling Steam to load Portal's Source engine and models.


Now, create a file called maplist.txt. In this, put all of your mod's map names without the ".bsp" extenstion.
==== Create a Map List ====
This allows the game to precache the first .125 milliseconds of sound in the map, which is enough time to load the rest.


Change to your cfg directory and make a file called chapter1.cfg.
In your game directory, create a file called <code>maplist.txt</code>. In it, we
Add all the lines you want executed in the developer console when you load the first chapter of your mod to this file.
will list all of the mod's map names (excluding the <code>.bsp</code>
Usually all you'd do is type in map and then the name of the first map of chapter 1 without the ".bsp" extenstion.
extension). This file allows the game to pre-cache the first .125 milliseconds
If you want more chapters make chapter2.cfg, chapter3.cfg, and so on.
of sound for a map, which is enough time to load the remainder. {{confirm}}


Now, switch to your resources folder and create a file called MyPortalMod_english.txt with the name of your mod's folder replacing MyPortalMod. Type in
    $> cd "[Steam Root]\steamapps\SourceMods\MyPortalMod"
    $> new-item maplist.txt -type file


<pre>"lang"
The following is a sample <code>maplist.txt</code> for a mod with two maps,
{
named <code>myportalmod_map_00.bsp</code> and
"Language" "english"
<code>myportalmod_map_01.bsp</code>.
"Tokens"
{</pre>


Then type in text like this:
<source>
<code>"MyPortalMod_chapter1" "First Chapter"</code>
myportalmod_map_00
MyPortalMod is the name of your mod's folder. First Chapter is the name of your first chapter.
myportalmod_map_01
Add additional lines with chapter2, chapter3, etc. instead of chapter1 for additional chapters.
</source>
At the end, put:
 
<pre>
 
}  
==== Create Chapter Configuration Files ====
 
Change to your mod's <code>cfg</code> directory. Create configuration files for
each chapter of your mod, starting with <code>chapter1.cfg</code> and continuing
on to <code>chapter2.cfg</code>, etc. For example:
 
    $> cd "[Steam Root]\steamapps\SourceMods\MyPortalMod\cfg"
    $> new-item chapter1.cfg -type file
    $> new-item chapter2.cfg -type file
 
In these files, you will issue whatever commands you want to be executed by the
developer console when the chapter is first loaded. Typically, a command to load
the chapter's corresponding map is used.
 
The following is a <code>chapter1.cfg</code> example:
<source>
echo "==== /cfg/chapter1.cfg: Execution Started"
 
map myportalmod_map_00
 
echo "==== /cfg/chapter1.cfg: Execution Ended"
</source>
 
 
==== Create a Localization File ====
 
Create a localization file, called <code>MyPortalMod_english.txt</code>, in your
game directory's <code>resource</code> folder.
 
    $> cd "[Steam Root]\steamapps\SourceMods\MyPortalMod\resource"
    $> new-item MyPortalMod_english.txt -type file
 
Modify the contents of <code>MyPortalMod_english.txt</code> so that it is
similar to the following:
<source>
"lang"
{
    "Language" "english"
    "Tokens"
    {
        "MyPortalMod_chapter1"  "The First Chapter"
        "MyPortalMod_chapter2"  "The Second Chapter"
    }
}
}
</pre>
</source>
Save the file AS UNICODE. IT HAS TO BE UNICODE.


== Step 3 - Setting up Source SDK and Hammer to work with your mod ==
In this case, <code>MyPortalMod</code> is used because it is the name of the
Go into Source SDK and select Edit Game Configurations > Add. Type in the name you want your mod to be listed as in the Source SDK in the Name box and the path to your mod folder in the Directory box.
mod's game directory. "The First Chapter" is an english title for the mod's
first chapter. Add any additional chapters for your mod by following the
pattern in "Tokens".


In Hammer Editor select Tools > Options. Then make sure you are on the Game Configurations tab and choose Add. Double-click on portal.fgd and click Open.


==See Also==
{{warning| <u>'''This file must be saved in a Unicode format.'''</u>}}
 
 
{{confirm| Which unicode formats are acceptable? The author used UTF-8.}}
 
 
== Setting Up Hammer ==
 
{{note| If you have not yet created a mod from the 'Source SDK' tool (creating a 'Source code only' mod doesn't count), then you will need to first create one. Otherwise, you will not be allowed to add a game configuration file for MyPortalMod. This configuration file is required to save Hammer settings specific for the MyPortalMod mod. See [[Create a Mod]] for details on this process. Do not create a 'Source code only' mod.}}
 
 
Launch the 'Source SDK' from your Steam Library 'Tools' section. Make sure that
the 'Engine Version' pull-down has "Source Engine 2009" selected. Select 'Edit
Game Configurations'. From the pop-up menu, select 'Add'. A second pop-up will
appear, asking for a name and a directory. Enter the name that you want your
mod to be listed as (with respect to the 'Source SDK' tool) and enter the path to
your game directory (<code>[Steam Root]\steamapps\SourceMods\MyPortalMod</code>).
Then select 'OK' for the second and first pop-ups. Assume we named our game
configuration "My Portal Mod".
 
{{Image: Making_your_portal_mod_00.png}}
 
Restart the 'Source SDK' tool. Set 'Engine Version' and 'Current Game' to
'Source Engine 2009' and 'My Portal Mod', respectively. Now, select 'Hammer
Editor'. In the editor, select <code>Tools > Options</code>. A 'Configure
Hammer' pop-up should appear. Select the 'Game Configurations' tab and then hit
the 'Add' button for 'Game Data Files'. Select the file <code>portal.fgd</code>
and accept the changes. These configurations will be saved and restored the next
time you open Hammer from the 'Source SDK' tool with your mod name selected.
 
 
== See Also ==
 
* [[Portal mod template]]
* [[Portal mod template]]
<!-- This comment is 80 characters wide. -------------------------------------->

Revision as of 23:01, 30 August 2012

This article will discuss how to create a Portal content mod, from scratch. Part of the reason for creating the mod from scratch is that Valve does not provide a specific SDK or mod template for Portal. Another reason is that creating the mod from scratch is not difficult and is of general interest to Source SDK developers that would like to learn more about how everything works. So, let's get started.


Note.pngNote: Portal modification is different from some of the other Source based games in that source code to build the client.dll and server.dll files is not provided by Valve. However, a modder can still modify anything that isn't built directly into the game, which includes scenes, scripts, sounds, textures, and models, to name a few.


Prerequisites

To follow along with this article, you will need a copy of Portal and the Source SDK, installed on Steam.

The article uses a command shell to describe simple file manipulations. The commands used are:

Command Description
cd Change directory
mkdir Create a directory
new-item Create an empty file (roughly)


Creating the Mod

Creating the mod consists of creating a game folder and filling it with configuration files and mod-related content. Let's assume we are creating a mod named "My Portal Mod". Further, let [Steam Root] be Steam's installed path on your machine. (e.g. C:\Program Files (x86)\Steam)


Create the Game Folder

Navigate to your SourceMods directory and create a folder named "MyPortalMod".

   $> cd "[Steam Root]\steamapps\SourceMods"
   $> mkdir MyPortalMod

In this new directory, create a file called GameInfo.txt.

   $> new-item GameInfo.txt -type file

Edit the contents of GameInfo.txt so that they look similar to the following snippet. For details about the structure of this file, see Gameinfo.txt.

"GameInfo"
{
    game   "My Portal Mod"
    title  "My Portal Mod"
    type   singleplayer_only
    icon   "myportalmod"  // Assumes myportalmod.tga is in the same directory as GameInfo.txt

    nodifficulty  1
    hasportals    1

    FileSystem
    {
        SteamAppId  400
        ToolsAppId  211      

        SearchPaths
        {
            Game  |gameinfo_path|.
            Game  portal
            Game  hl2
        }
    }
}

Restarting Steam at this point will create an entry in the game Library for the mod. Deleting the game folder we created or removing the GameInfo.txt file will remove the entry.


Configure the Mod

Initial Setup

Let's add some standard folders to the game directory that will hold our mod's configuration files and content. Add the following folders to your game directory:

  • cfg
  • resource
  • maps.

While we're at it, let's add the following optional folders, for custom content like models and sounds:

  • materials
  • models
  • scenes
  • scripts
  • sound
   $> cd "[Steam Root]\steamapps\SourceMods\MyPortalMod"
   $> mkdir cfg
   $> mkdir resource
   $> mkdir maps
   $> mkdir materials
   $> mkdir models
   $> mkdir scenes
   $> mkdir scripts
   $> mkdir sound


Create a Map List

In your game directory, create a file called maplist.txt. In it, we will list all of the mod's map names (excluding the .bsp extension). This file allows the game to pre-cache the first .125 milliseconds of sound for a map, which is enough time to load the remainder. [confirm]

   $> cd "[Steam Root]\steamapps\SourceMods\MyPortalMod"
   $> new-item maplist.txt -type file

The following is a sample maplist.txt for a mod with two maps, named myportalmod_map_00.bsp and myportalmod_map_01.bsp.

myportalmod_map_00
myportalmod_map_01


Create Chapter Configuration Files

Change to your mod's cfg directory. Create configuration files for each chapter of your mod, starting with chapter1.cfg and continuing on to chapter2.cfg, etc. For example:

   $> cd "[Steam Root]\steamapps\SourceMods\MyPortalMod\cfg"
   $> new-item chapter1.cfg -type file
   $> new-item chapter2.cfg -type file

In these files, you will issue whatever commands you want to be executed by the developer console when the chapter is first loaded. Typically, a command to load the chapter's corresponding map is used.

The following is a chapter1.cfg example:

echo "==== /cfg/chapter1.cfg: Execution Started"

map myportalmod_map_00

echo "==== /cfg/chapter1.cfg: Execution Ended"


Create a Localization File

Create a localization file, called MyPortalMod_english.txt, in your game directory's resource folder.

   $> cd "[Steam Root]\steamapps\SourceMods\MyPortalMod\resource"
   $> new-item MyPortalMod_english.txt -type file

Modify the contents of MyPortalMod_english.txt so that it is similar to the following:

"lang"
{
    "Language" "english"
    "Tokens"
    {
        "MyPortalMod_chapter1"  "The First Chapter"
        "MyPortalMod_chapter2"  "The Second Chapter"
    }
}

In this case, MyPortalMod is used because it is the name of the mod's game directory. "The First Chapter" is an english title for the mod's first chapter. Add any additional chapters for your mod by following the pattern in "Tokens".


Warning.pngWarning: This file must be saved in a Unicode format.


Confirm: Which unicode formats are acceptable? The author used UTF-8.


Setting Up Hammer

Note.pngNote: If you have not yet created a mod from the 'Source SDK' tool (creating a 'Source code only' mod doesn't count), then you will need to first create one. Otherwise, you will not be allowed to add a game configuration file for MyPortalMod. This configuration file is required to save Hammer settings specific for the MyPortalMod mod. See Create a Mod for details on this process. Do not create a 'Source code only' mod.


Launch the 'Source SDK' from your Steam Library 'Tools' section. Make sure that the 'Engine Version' pull-down has "Source Engine 2009" selected. Select 'Edit Game Configurations'. From the pop-up menu, select 'Add'. A second pop-up will appear, asking for a name and a directory. Enter the name that you want your mod to be listed as (with respect to the 'Source SDK' tool) and enter the path to your game directory ([Steam Root]\steamapps\SourceMods\MyPortalMod). Then select 'OK' for the second and first pop-ups. Assume we named our game configuration "My Portal Mod".

A screenshot showing configuration settings.

Restart the 'Source SDK' tool. Set 'Engine Version' and 'Current Game' to 'Source Engine 2009' and 'My Portal Mod', respectively. Now, select 'Hammer Editor'. In the editor, select Tools > Options. A 'Configure Hammer' pop-up should appear. Select the 'Game Configurations' tab and then hit the 'Add' button for 'Game Data Files'. Select the file portal.fgd and accept the changes. These configurations will be saved and restored the next time you open Hammer from the 'Source SDK' tool with your mod name selected.


See Also