Game Career Guide is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Get the latest Education e-news
 
  • DIY RPG: Make Your Own RPG With The Source Engine

    [08.02.12]
    - Ben Evans
  •  

    Importing your own audio

    Our RPG is going to be extremely boring without any recorded dialogue to convey the story, so we're going to use Audacity to record your own dialogue. You must have a microphone for this part. Due to the way the Face Poser application works, you're going to want to record one sentence at a time. Recording audio in Audacity is easy. All you need to do is get your mic set up correctly, hit the red button to record, and save your audio as a .wav file when you're finished. If you have any problems, Audacity's help menus have lots of useful information. When you're done recording your dialogue, create a folder named "RPG" and save each sentence as a .wav file into it. Move that RPG folder to C:/Program Files/Steam/steamapps//half-life episode two/ep2/sounds/. It's important to save the audio into a folder one level above the sounds folder because the engine will not read the sound file otherwise.

    Next, let's create a sound_script file so that the engine will be able to reference our sounds in the editors and the game. Launch GCFScape, go to File, Open, go over to your steamapps folder, and open up the "episode two content.gcf" file. After GCFScape has loaded that file, we'll need to find a file named "game_sounds_manifest.txt," which is located in the /steamapps//ep2/scripts/ folder. Right-click on the file and click Extract, and place the manifest within /steamapps//half-life 2 episode two/ep2/scripts. We're done with GCFScape, so you can close it now.

    Go to the scripts folder and open up the game_sounds_manifest.txt file we just extracted. In this text file we can see all of the sound scripts that the game will use when it loads, and we need to add our own to this list. Under the last line of code, within the last bracket, add your own entry like Listing 1.


    Now we're going to create the "rpg_sounds.txt" file that we are referencing, so save the manifest file and close it now.

    In the scripts folder, right-click and select New, Text Document. Rename this new text file to "rpg_sounds.txt." After you rename the text file, open it up and add the code in Listing 2.


    The first line is the name of the sound that will appear in Face Poser: "rpg _sounds" is the prefix, and the second part is the name. You can change this naming convention to whatever you like. The next four lines tell the engine how to deal with the sounds, and we'll leave them as they are for now. The last line is the .wav file it will load and contains a relative path to the "sound" folder, located in /steamapps//half-life 2 episode two/ep2/sound/. All you need to do is put the folder with your audio files into that "sound" folder and make sure the file names and extensions match what it says in the script file. Save and close the text file when you are done.

    If you're running Windows Vista or Windows 7, we'll need to help Face Poser out a little bit. As mentioned earlier, you'll need to download and install the Phoneme Extractor patch in order to do this. Follow the instructions and replace the necessary files. This patch will allow Face Poser to correctly translate the audio files and sound scripts into the phoneme facial expressions that will be animated on the characters. It's important to note that Source SDK refreshes itself each time it is launched, so this patch fix needs to be done each time Source SDK is opened. Yes, it is a bit of a pain, but it's way easier and faster than trying to line up phonemes to the audio manually.

    With Face Poser open, we're going to start a new scene. Under the Choreography menu tab click "New," which will create a new scene to work with. It'll prompt you to save the scene, so name it something you can remember, and then place it in /steamapps//half-life episode two/ep2/Scenes/RPG_MOD/. It'll make it easier to find later on if you give the scene name a prefix, such as "RPG_". Next, Face Poser will ask you to name your first Actor. Name your actor "!_target" where is a number between 1 and 8, because we can have up to eight individual NPCs in each scene. Hammer will use whichever NPC you select in the editor based on this name. We currently only have one character, so name the actor "!_target1." Right-click on the Actor name that has appeared in the Choreography window and then go to New, Channel to bring up the Create Channel box. Name this channel "Audio." We'll need to make a second channel for animations, so repeat the last step and name it "Anim."

    Now we're going to sort out the audio. In the list of tabs at the bottom of the Face Poser screen, double-click Phoneme Editor and it will bring up a new window. Click on Load and select the .wav file you want to add to the character. The file will be displayed as a waveform diagram in the Phoneme Editor window after it is loaded. Press the Re-extract button, and Face Poser will prompt us to write out the sentence text of the same dialogue audio clip we selected. Write out the line and then press OK. The words you entered should now be placed at the appropriate points over the waveform, so right-click on the waveform and hit Commit extraction to apply the phonemes to your waveform. If you play it by pressing your space bar you should see the Actor in the window move their mouth. Hit Save on the Phoneme Editor window and then close it.

    We need to add that .wav file to our actor, so right-click on the Audio channel and click WAV File, and then check Show All Sounds. We need to locate the sound name that we gave our .wav file in the sound script file; in our example it will be named "CitizenHomie/FemaleCitizen_Line1-try2 - Processed.wav," but you should look for whatever name you added into your own sound script. You can use the filter field to help you find it. Once you find it, select it and hit OK. This will place it on your Audio channel. When you play through the sound, it should make your actor's mouth animate to speak the dialogue. Look at Figure 9 for an example of what everything should look like once you're done.


    Figure 9: Once your dialogue animation is set up in Choreography, it will look like this.

    If you wanted to add gestures, facial expressions, and other animations, you'd do that now. We won't cover that in this tutorial, but there are plenty of resources online that explain how to do those things, such as design3's Source Engine section. Next save your scene by going to Choreography, Save. Now that we have our scene saved, we're ready to attach it to our NPC.

    Applying custom audio to NPCs

    Now we need to set our dialogue up in our level. We're going to add our scene to the scene_start and scene_end entities we created while building our instance earlier. Hit Alt + Enter to open up the Object Properties window of the scene_start entity and you'll see an option named "Scene file." Select this option and then browse for your scene under the "scenes" folder. We'll need to assign an NPC to use the scene, so select the Target 1 option and choose the NPC with the name of your actor in Face Poser. Hit Apply to save these changes. Then repeat that same process for the scene_end entity.

    All we need to do now is trigger the scene to start playing. We'll need to trigger the scene from another entity at the point where we want the scene to be acted out. For example, you can use a trigger_once brush with the output of "On trigger, entities named scene_start, Start." Our quest instance that we set up earlier has two button brushes that should already start our scenes, so just double-click on the brush to open up the Properties panel and change the Scene File field to the scene you want your NPC to act out.

    Triggering events

    In order for this RPG to work, we need a system that allows each quest to know when the player has completed a specified task. This is so the game can progress and won't just stop dead in its tracks. The best thing to do is have a single entity that performs all the necessary outputs once the quest is completed. We'll use our relay_complete entity for this task.

    Here's an example of a quest:

    - Player needs to kill five enemies.

    - On each kill, a math_counter entity increases by one.

    - When it hits its max limit, five in this example, it outputs a trigger to our logic_relay.

    - logic_relay runs all necessary outputs like stopping enemies spawning, activating the quest giver, activating sprites, and so on.

    Using relays keeps the number of outputs low and in one place instead of spread across multiple entities, which can get very confusing on complex maps.

    Setting up autosave

    Everybody hates it when a single crash erases their last hour of gameplay, so it's vital to have an autosave feature just in case it happens to our players. Fortunately, autosave is easy to implement. All we need is a logic_autosave entity. Find it on the entity list and place it in your map near any other logic entities you have, such as environmental lighting or auto_logic. The placement isn't too important, but it's good to have similar entities located close to together to make them easier to find. Let's name it "Global_autosave." The autosave entity works off inputs from other entities, so we're going to make our end relays for each quest output a trigger to our autosave in order to save the game. Open up the Outputs tab on our relay_complete and add this output: "On Trigger" the entities named "Global_autosave" via this input "Save." And that's all there is to it! Now the game should save the player's progress every time we finish a quest.

    Game ending

    Our game is going to have to end at some point, and it'll look bad if it just cuts back to the main menu, so we're going to use another group of entities to roll the credits first. Create the entities shown in Figure 10 and place them in a suitable place in the level, somewhere that is easy to access and remember.


    Figure 10: You'll need to use these entities to make your ending credits sequence.

    Once you've made the core entities for the ending credits, all you need to do is link them with triggers. Open up the output tab on your end_relay and create these new outputs: On trigger, env_fade, fade, 0 seconds On trigger, end_text, display, 1 seconds, On trigger, point_clientcommand, disconnect, 5 seconds. This will make the screen fade to black, your credits will fade in, and then a few seconds later the game will disconnect the player using the client command.

    Now you just need to compile your map. Compiling is the process of packaging everything and making a .BSP file that the game can read. To compile, just go to File, Run Map. This will bring up the Run Map options window with some different compile options, such as launching the game after the compile finishes. Just hit OK to compile the map and you're good to go!

    Quest complete

    Now you should have the basic tools you need to build your own RPG prototype. We've shown you how to create quests, incorporate your own dialogue, and use logic to enhance your game, so now it's your job to keep testing and refining those quests, level, and dialogue decisions. You can make any sort of quest you can possibly imagine, or add a multiplayer co-op component like the Synergy mod, or even use elements from other Valve games like Left 4 Dead. Get in there and start modding!

    Ben Evans is a game developer with experience in level design, 3D art, and coding. He's a frequent design3 contributor, especially when it comes to Source engine tutorials. He is also the current lead programmer at Stupor Studios and can be found on Twitter as @The_BenEvans.

    Special thanks to Ross Scott, the director of the Machinima series Civil Protection and Freeman's Mind, for providing dialogue writing and audio recording.

Comments

comments powered by Disqus