General Half-Life 2/Entities
description
Using various Source entities to replicate adventure game dialogue trees.
keywords
adventure, trees, dialogue, game_ui.
I wrote this tutorial a few months ago for a project that I was working on and thought it would be useful for other people interested in adding dialogue trees to their SP campaigns. Please be warned that this tutorial and the related video contains extremely foul language and is intended for a MATURE audience only!
Firstly you need to figure out what you want the player to be able to say and create a dialogue tree texture in your favorite paint program (I use photoshop). The reason I decided to use a texture as opposed to the game_text entity was simply because game_text is too limiting for multiple lines of dialogue. You could modify the titles.txt file and use an env_message entity, but I thought using an env_screenoverlay would be better. (If you really want to get fancy you could create a custom dialogue background for the text to display in) Create a 512x512 pixel image with a black background and whatever font color you want. I choose lime green (0 255 0) as I find this displays best on any background. Now you need to type out your 4 dialogue options and assign the W,S,A,D keys to each one. I just came up with 4 random options (warning, coarse language): http://www.interlopers.net/images/hl2tu ... _tut01.jpg
Now you can flatten your image and select all + copy the image onto a new alpha channel then save the file as "dialogue01.vtf" (with "compressed texture with alpha" as the format type from the drop down) to your mod directory (in this case episode 2) /materials/dialogue/

Don't forget to create a vmt file with the same name to go with the new texture
- Code: Select all
"UnlitGeneric"
{
"$basetexture" "dialogue/dialogue01"
"$translucent" "1"
"$nodecal" "1"
}
Now we need to record the dialogue for the different options (I used Cool Edit Pro 2.0). Save the recordings as 44100 stereo wav files and name them accordingly. (dialogue01.wav dialogue02.wav etc.) in your mod directory /sound/dialogue/

Next you can launch Hammer and create a new test map (square room with light and info_player_start entities). Start by placing your NPC entity in the game. I chose Barney (npc_barney) and go to the Flags tab and check off "Wait Till Seen", "Gag", "Fall to ground" and "Ignore player push".

I like to set up all my entities before I start adding input/outputs because it makes things easier with Hammer's drop down list for choosing entities to point to, so next thing to create is the game_ui entity which you should name "dialogue_menu01". Doesn't matter where you place the entity, but for ease of use, I stacked all of my entities on top of each other to the left of the NPC.

Now create an env_screen_overlay entity and name this "dialogue_overlay01". For the Overlay Name 1 area we enter "dialogue/dialogue01.vtf" (why there is no browse option I don't know).

Next we create an ambient_generic entity and name it "dialogue01". For the SoundName you can hit Browse and then type "dialogue" into the filter area and it should bring up all of your dialogue wav files. Choose dialogue01.wav and press OK.

Now close the properties window and with the ambient_generic entity selected choose Edit - Copy (CTRL+C) and then choose Edit - Paste Special. This will bring up a very handy window that will allow us to paste in multiple copies of the ambient_generic entity as well as having Hammer re-name the files and spacing them out properly in the editor.
Number of copies = 3
Start at center from original = Yes
Z = 32
And check "Make pasted entity names unique"

This will create 3 copies of our original ambient_generic and place them perfectly in the editor with only minimal tweaking.

Select the second ambient_generic from the bottom and edit the properties
change the Name to dialogue02 (for some reason the unique names drops the 0, I don't know why) and then browse to dialogue02.wav and press ok. Repeat this step for both the 3rd and 4th ambient_generic entities naming appropriately (dialogue03 and dialogue03.wav etc.)
Now that we have all of our entities in place, we can give each of them the proper Outputs so everything works.
Starting with our NPC entity, bring up the properties window and click on the Outputs tab.
Press the Add button and enter the following:
My Output Named = OnPlayerUse
Targets Entities Named = dialogue_menu01
Via This Input = Activate
Via a paramiter override of = <none>
After a delay of = 0.00
Now you can select the Output we just created and hit the Copy and Paste buttons. Now choose either of the two Outputs (since they're both the same) and change the following:
Target Entities Named = dialogue_overlay01
Via This Input = StartOverlays

Now press the Apply button and close the properties window.
Now this is where the long part comes in, but its still very easy to implement. Select the game_ui entity (dialogue_menu01) and select the Outputs Tab. Click Add and enter the following:
My Output Named = PressedBack
Targets Entities Named = dialogue01 (This is the first error I found. To match our dialogue texture, this needs to be targeting the dialogue02 ambient generic)
Via This Input = PlaySound
Via a paramiter override of = <none>
After a delay of = 0.00
Now with the Output Selected, Copy and Paste a duplicate and change the following:
Targets Entities Named = dialogue_overlay01
Via This Input = StopOverlays
After a delay of = 0.10
Copy and Paste again and change the following:
Targets Entities Named = dialogue_menu01
Via This Input = Deactivate
After a delay of = 0.10
Now you should have 3 Outputs in total that should look as follows:

From here its a lot faster. Simply select all 3 of your Outputs (CTRL + Left Click) and Press Copy and Paste.
Now with all 3 of the newly pasted Outputs still selected, simply change the "My Output Named" area from "PressedBack" to "PressedForward".
Now select the PressedForward "dialogue01" Output and change the "Targets entities named" to "dialogue02" and if you followed everything correctly your Outputs should look like this now:
(In correlation with the first error, this actually needs to be set to dialogue01)

Hitting Paste again (WITHOUT pressing Copy) will paste in the original 3 Outputs as duplicates and this time (again with the pasted outputs still selected) you change the "Targets entities named" to "PressedMoveLeft" making sure to change the "dialogue01" area to dialogue03 and then press Paste one more time and change "Targets entities named" to "PressedMoveRight" changing the "dialogue01" area to dialogue04.
If all of that made sense, you chould now have 3 Outputs for each of the directional keys (IE WSAD) with each key targeting one of the 4 ambient_generic (dialogue01,02,03 and 04) entities which should look like this:

Now at this point you should save your map file if you haven't already done so. I called my map "dialogue.bsp" in keeping with the naming conventions of this entire tutorial.
Provided I haven't forgotten anything, you can now compile your map and load it up in HL2 Episode 2. When you spawn in the game, you can walk over to Barney (or whoever your NPC) and pressing the Use key on them will open your dialogue tree and allow you to choose between the 4 dialogue options with the W,S,A,D keys. Upon choosing your dialogue option, the dialogue window will close and you can resume play as normal.
To view a video of the results of this tutorial, visit http://www.vimeo.com/1893591
Now the tricky part is going to be figuring out how to have the dialogue options you choose affect what happens in the game. Unfortunately that might require a separate tutorial so until then... Good luck!
- TorQueMoD