This resource adds standard RPG Dialogs to the Torque Game Engine, including multiple choice questions and question linking(underlined words on a question that perform actions when clicked on).

RPGDialog was created by Nelson A. K. Gonsalves, contact me at dk_uo@yahoo.com or on the GarageGames Forums if you find bugs, oddities or if you have comments or suggestions.

This resource is free and may be used in whatever way you may want...

----------------------------->>New 1.3 Features

--->>Multiple actions can now be triggered by one response, thanks goes to BrokeAss Games for the idea :-)

--->>Its now possible to move answers up and down in the editor

--->>Warning: Version 1.0 .dla files are incompatible with version 1.3, I recommend opening them directly in a text editor and doing a quick replace all from "<" to "<END><", adding <END> to the end of each line and removing the <END> from the beginning of the line, that should make them 100% compatible.

----------------------------->>1.0 Features

--->>Multiple choice questions, present a question and a list of answers and do something depending on which answer the player picks, the choices are numbered and can be picked either by the mouse or by pressing the 1,2,...,9,0 keys on the keyboard, choices after 10 must be selected via mouse, the max number of choices is determined in $RPGDialogEditorPref::MaxOptions on the editor and $Pref::RPGDialog::MaxOptions on the client and is set to 100 as default, note that the $Pref::RPGDialog::MaxOptions will be set to $RPGDialogEditorPref::MaxOptions if it is avaible at the time of execution(if the editor is running).

--->>Question Links, Ex: "Hello, I'm >Mary<, how are you?"(actualy the word Mary would be underlined instead... but you get the point :P), clicking on the word Mary will trigger an action as if it was a choice in the Multiple choice window.

--->>Portraits, pictures that represent the NPC, change it depending on the choices of the player or even use them to show the mood of the NPC.

--->>Sounds, add voice overs or any sound effects that are triggered when the question is displayed.

--->>Fully functional in multiplayer games, only allowing one player to talk to each NPC at a time, sending a message telling the others that the NPC is busy if they try to talk to it. And doing a check to see if the conversation has ended every time someone tries to talk to the NPC to prevent "stuck in dialog" NPCs.(that could happen if someone lost their connection while on the dialog for example).

--->>Moving the player too far away from the NPC closes the Dialog automatically.

--->>Each option triggers a function, allowing complete customization of the actions caused by the dialog, either by using the included functions, altering them or creating your own.



----------------------------->>Installation Instructions

Note: The following instructions are based on the rw(Realm Wars) example program that comes with Torque.

--->>Copy the contents of the folder "New Files" into your Torque example directory.

--->>Add the following modifications:

>>In example\common\client\prefs.cs

Add to the end of the file:

$Pref::RPGDialog::ChatHudAnswerColor = "\c5";
$Pref::RPGDialog::ChatHudQuestionColor = "\c1";
$Pref::RPGDialog::Client::QuestionPath = "starter.fps/data/dialogs/dlq/";
$Pref::RPGDialog::MaxOptions = 100;
$Pref::Server::RPGDialog::ActionPath = "starter.fps/data/dialogs/dla/";

>>In example\common\server\prefs.cs

Add to the end of the file:
$Pref::Server::RPGDialog::ActionPath = "starter.fps/data/dialogs/dla/";

>>In example\common\main.cs

Around line 33 after: exec("./client/scriptDoc.cs");
   //----------------------------------------------------------------
   //RPGDialog Code Begin
   //----------------------------------------------------------------   
   exec("./RPGDialogEditor/ingameRPGDialogEditor.cs");   
   //----------------------------------------------------------------
   //RPGDialog Code End
   //----------------------------------------------------------------   
 
>>In example\common\prefs.cs

Add to the end of the file:

$Pref::Server::RPGDialog::ActionPath = "starter.fps/data/dialogs/dla/";

>>In example\starter.fps\client\scripts\client\config.cs

Add to the end of the file:

moveMap.bind(keyboard, "q", TalkTo);

>>In example\starter.fps\client\scripts\default.bind.cs

Comment/remove the following line around line 221:
 
moveMap.bindCmd(keyboard, "1", "commandToServer('use',\"Crossbow\");", "");

Add to the end of the file:

//----------------------------------------------------------------
//RPGDialog Code Begin
//----------------------------------------------------------------   
function TalkTo(%val)
{
   if(%val)
      commandToServer('RPGDialogRay');
}

moveMap.bind(keyboard, "q", TalkTo);
moveMap.bindCmd(keyboard, "1", "SelectAnswer(1);", "");
moveMap.bindCmd(keyboard, "2", "SelectAnswer(2);", "");
moveMap.bindCmd(keyboard, "3", "SelectAnswer(3);", "");
moveMap.bindCmd(keyboard, "4", "SelectAnswer(4);", "");
moveMap.bindCmd(keyboard, "5", "SelectAnswer(5);", "");
moveMap.bindCmd(keyboard, "6", "SelectAnswer(6);", "");
moveMap.bindCmd(keyboard, "7", "SelectAnswer(7);", "");
moveMap.bindCmd(keyboard, "8", "SelectAnswer(8);", "");
moveMap.bindCmd(keyboard, "9", "SelectAnswer(9);", "");
moveMap.bindCmd(keyboard, "0", "SelectAnswer(10);", "");

function OutOfRPGDialogFunction(%Number)
{
   switch(%Number)
   {
      case 1: commandToServer('use',"Crossbow");
      case 2: %Number=0;//Does nothing... just a placeholder.
      case 3: %Number=0;//Does nothing... just a placeholder.
      case 4: %Number=0;//Does nothing... just a placeholder.
      case 5: %Number=0;//Does nothing... just a placeholder.
      case 6: %Number=0;//Does nothing... just a placeholder.
      case 7: %Number=0;//Does nothing... just a placeholder.
      case 8: %Number=0;//Does nothing... just a placeholder.
      case 9: %Number=0;//Does nothing... just a placeholder.
      case 0: %Number=0;//Does nothing... just a placeholder.
   }
}
//----------------------------------------------------------------
//RPGDialog Code End
//----------------------------------------------------------------   

>>In example\starter.fps\client\scripts\optionsDlg.cs

Around line 225 right after
"$RemapName[$RemapCount] = "Fire Weapon";
 $RemapCmd[$RemapCount] = "mouseFire";
 $RemapCount++;"
add:
$RemapName[$RemapCount] = "Talk to NPC";
$RemapCmd[$RemapCount] = "TalkTo";
$RemapCount++;

>>In example\starter.fps\client\config.cs

Add to the end of the file:

moveMap.bind(keyboard, "q", TalkTo);

>>In example\starter.fps\client\defaults.cs

Add to the end of the file:
 
//----------------------------------------------------------------
//RPGDialog Code Begin
//----------------------------------------------------------------   
$Pref::RPGDialog::Client::QuestionPath="starter.fps/data/dialogs/dlq/";//RPGDialog Question Path.
$Pref::RPGDialog::MaxOptions = 100;//RPGDialog Max Options.
$Pref::RPGDialog::ChatHudQuestionColor="\c1";//Question text Color on the chat hud.
$Pref::RPGDialog::ChatHudAnswerColor="\c5";//Answer text Color on the chat hud.
//----------------------------------------------------------------
//RPGDialog Code End
//----------------------------------------------------------------   

>>In example\starter.fps\client\init.cs

Around Line 72 right after "exec("./ui/StartupGui.gui");" add:

   //----------------------------------------------------------------
   //RPGDialog Code Begin
   //----------------------------------------------------------------    
   exec("./ui/RPGDialog.gui");
   //----------------------------------------------------------------
   //RPGDialog Code End
   //----------------------------------------------------------------     
 

Around line 92 right after "exec("./scripts/centerPrint.cs");" add:

   //----------------------------------------------------------------
   //RPGDialog Code Begin
   //----------------------------------------------------------------     
   exec("./scripts/RPGDialog.cs");
   exec("./scripts/RPGDialogAudioProfiles.cs");   
   //----------------------------------------------------------------
   //RPGDialog Code End
   //----------------------------------------------------------------      
  
Around line 127 right after "Canvas.setCursor("DefaultCursor");" add:
      //----------------------------------------------------------------
      //RPGDialog Code Begin
      //----------------------------------------------------------------        
      initRPGDialogEditor();      
      //----------------------------------------------------------------
      //RPGDialog Code End
      //----------------------------------------------------------------        

>>In example\starter.fps\client\prefs.cs

Add to the end of the file:

$Pref::RPGDialog::ChatHudAnswerColor = "\c5";
$Pref::RPGDialog::ChatHudQuestionColor = "\c1";
$Pref::RPGDialog::Client::QuestionPath = "starter.fps/data/dialogs/dlq/";
$Pref::RPGDialog::MaxOptions = 100;
$Pref::Server::RPGDialog::ActionPath = "starter.fps/data/dialogs/dla/";

>>In example\starter.fps\server\scripts\game.cs

Around line 53 right after "exec("./aiPlayer.cs");" add:

   //----------------------------------------------------------------
   //RPGDialog Code Begin
   //----------------------------------------------------------------     
   exec("./RPGDialog.cs");
   //----------------------------------------------------------------
   //RPGDialog Code End
   //----------------------------------------------------------------     

>>In example\starter.fps\server\defaults.cs

Add to the end of the file:

//----------------------------------------------------------------
//RPGDialog Code Begin
//----------------------------------------------------------------   
$Pref::Server::RPGDialog::ActionPath="starter.fps/data/dialogs/dla/";//RPGDialog Action Path.
//----------------------------------------------------------------
//RPGDialog Code End
//----------------------------------------------------------------   

>>In example\starter.fps\server\prefs.cs

Add to the end of the file:

$Pref::Server::RPGDialog::ActionPath = "starter.fps/data/dialogs/dla/";

--->>Now go into the game, pressing F5 should toggle the Dialog Editor On and Off

--->>Execute SpawnTestNPC(); on the console and that will create a npc using the test dialog at the center of the orc village, the default key for starting up the dialog is "q"(you can change it on the options menu), so if you face the npc and are close enough, the dialog will start when you press "q".

--->>There is also a SpawnNPC(%Name,%Script,%Portrait,%startQuestion,%location) for custom NPC spawning.



----------------------------->>Script Files Instructions

The scripts are created using the included editor, press F5 ingame after the MOD was installed or execute the game with "-mod common/RPGDialogEditor" command line.

The scripts are stored in 2 files, one file contains the question and avaible options(.dlq), and the other stores the actions performed by each option(.dla), the question file is acessed by the client and the second one by the server, the client doesnt even need the .dla file, as the server doesnt need the .dlq file, this prevents the clients from peeking into the scripts to see what each option does, considering that the scripts are plain text files for now that would be pretty easy if the client had the .dla file.

The scripts must be located on the paths specified by $Pref::RPGDialog::Client::QuestionPath on the client and $Pref::RPGDialog::Server::ActionPath on the server or if that fails RPGDialogEditorPref::QuestionPath and $RPGDialogEditorPref::ActionPath respectively, note that on the editor you can load scripts from any MOD folder if both .dlq and .dla are on the same folder, also the editor will try using $RPGDialogEditorPref::ActionPath if it doesnt find the .dla on the same folder as the .dlq.

The following keywords can be used both in questions and answers:
<<PlayerName>> is replaced with the player character's name.
<<Name>> is replaced with the AiPlayer character's name.

The Action commands list(located on the edit answer GUI on the editor) is compiled from the RPGDialog.cs file located on the server/scripts folder everytime you run the editor, check server/scripts/RPGDialog.cs for more details on how this is done, but more importantly is knowing that all commands avaible for the actions are listed on the action command list.

----------------------------->>AiPlayer Instructions

The following fields are used by RPGDialog:

RPGDialogScript --> This determines which script the NPC will use, note that no file extensions are included. If this field isnt determined or is invalid there will be no RPGDialog associated to the NPC(Kinda obvious). EX: AiPlayerHandle.RPGDialogScript="Test"; will cause the NPC use the files Test.dlq and Test.dla.

RPGDialogPortrait --> This determines the NPCs portrait. EX: AiPlayerHandle. EX: AIPlayerHandle.RPGDialogPortrait = "Test.png"; will cause the NPC to use the file Test.png as his portrait.

RPGDialogStartQuestion --> Determines the first question shown when the dialog starts. EX:AiPlayerHandle.RPGDialogStartQuestion = 1; will cause the NPC to show the question number 1 when the conversation begins.

RPGDialogBusyText --> This is the message that will be sent to the player when the NPC is busy, note that %1 will be replaced with the player currently talking to the NPC. EX: AiPlayerHandle.RPGDialogBusyText = 'Sorry but I\'m busy talking to %1 right now.';

RPGDialogBusy --> Bool value used internaly... 

RPGDialogTalkingTo --> Handle to the player currently engaged in conversation, used internaly...

----------------------------->>Sound Instructions

There is a Sound drop-down menu on the New/Edit Question Gui in the editor, its values are taken straight from the audio profiles at client/scripts/RPGDialogAudioProfiles.cs, so any audio profiles at RPGDialogAudioProfiles.cs are avaible from the editor, also the current value from the .dlq file is set as the topmost value on the list, even if its invalid.
