Game Development Community

dev|Pro Game Development Curriculum

RPGDialog - NPC interaction system

by Nelson A. K. Gonsalves · 11/29/2002 (12:27 pm) · 186 comments

RPGDialog is a Torque Game Engine modification that adds standard RPG Dialogs support, including multiple choice questions and question linking(underlined words on a question that perform actions when clicked on). Also included is an editor for creating and editing dialogs easily.

Instructions on installing are included on the zip file.

New download location since geocities is dead

Have fun using it! :)
And let me know of any problems you might find.

Contact me at dk_uo@yahoo.com or leave a comment here.

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.

- Question Links, Ex: "Hello, I'm Mary, how are you?" clicking on the word Mary would 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.

- 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.

June 8th 2005.
I finnaly got around to giving this a much deserved update!

Firstly I updated the instructions and made a few changes to make it fully compatible with TGE 1.3.

Also I've added buttons to move the answers up and down in the editor, so its now easier to organize the available options.

And finnaly, multiple actions can now be triggered by one response, thanks goes to BrokeAss Games for the idea. To execute multiple actions just add them one after the other without anything separating them, there is one example of this in the test scripts. Ohh, and now clicking on the actions list will add them to the actions edit and not replace them.

I have one warning though, version 1.0 .dla files are incompatible with version 1.3, there is an easy workaround I've used on my files, just open them directly in a text editor and do a quick replace all from "<" to "<END><", add <END> to the end of each line and remove the <END> from the beginning of the line, that should make them 100% compatible.

Let me know if you find any problems.

-Nelson

About the author

Recent Blogs

Page «Previous 1 2 3 4 5 6 7 Last »
#1
11/29/2002 (7:38 pm)
Thanks for this Nelson. I haven't tried it yet, but I can pretty well guarantee you I will use it !
#2
11/29/2002 (8:22 pm)
CRAZY COOL! rpg's are great and i think every game should have rpg elements. Thankyou for contributing this resource.
#3
11/29/2002 (9:45 pm)
Thank you guys, I tried to make it as complete as possible, so let me know of any problems you might find :)
#4
12/04/2002 (9:20 am)
Thank you so much for this. I'm sure many will have great use for it!
I know I will.

:)
Bendik
#5
05/20/2003 (8:06 pm)
how can I get this to work in my game ? i am using head release not realm wars
#6
01/21/2004 (8:03 pm)
WhooHOo. Just got it working 100% on starter.fps!

Thanks for the resource.


Matt (I know its almost a year to late but...)- I did:
1 - changing "rw" directory references to "starter.fps" including the directories within the .zip.
2 - moved the datablock PlayerData(LightMaleHumanArmor) from the "demo" to your project if it doesn't exist, otherwise the "spawnTestNPC();" function will not work.
3 - in the directions it reference "rw\client\default.cs" This location wasn't quite right for me.

Hope that helps.
#7
05/17/2004 (7:38 am)
i can not download the file
#8
07/14/2004 (9:41 pm)
Thanks Nelson,
With some wrenching I got this in.
Works in the latest HEAD.
KILLER KILLER KILLER KILLER!
This was easy and OMG!
I was able to add this feature to the NPCs (from another tutorial).
The editor is AWSOME!
NPCs have inventory and now dialog.
It seems that my NPCs are able to execute almost ANY command in response to a question.
This helped make an RPG possible.
Working on making bot's talk to NPCs randomly.
I created 'Bin' the tourguide as an example for my team.
This resource really adds personality to bots and NPCs.
We are using TrueSpace 6.6 with all the frills and I noticed a speech animation tool for heads. It works awsome, if you can afford TS6.6 it worth it. Hopefully I can get characters to mouth the speech.
Anyways, this resource is a must for RPGs!

This resource has been assimilated!

Ari
#9
07/19/2004 (2:16 pm)
This is wonderful... It's perfect for my game when in the single-player mode while doing the campaign!!!
#10
08/01/2004 (4:34 am)
to say it short : "nice"
#11
08/02/2004 (11:27 am)
You have to be really close actually, it took me a while to realize that ^^;
Anyway, this resource is really nice!
#12
08/02/2004 (12:00 pm)
Can anybody give me a valid example of how to use the function SpawnNPC(%Name,%Script,%Portrait,%startQuestion,%location)? I don't know how to format the arguments.
#13
08/04/2004 (3:44 pm)
I do it \SMMOG 5.aug\engine\starter.fps\server\scripts\game.cs

function onMissionLoaded()
{
// Called by loadMission() once the mission is finished loading.
// Nothing special for now, just start up the game play.
startGame();
SpawnNPC("Priest", "Priest_Akil", "Priest.png", 1, "-796 4069 500");
}
// But I guess I know by now - since you wrote it .... but I will answer it anyway because someone else will see it and say ohhhh great/nice work ..... by the way thanks for the help on this one
#14
09/30/2004 (3:41 am)
I'm kind of a newb with Torque and I was having this error with this resource:
(I am building from the current HEAD of Realm Wars from the CVS.)

After console call spawnTestNPC();

----->

rw/scripts/server/RPGDialog.cs (194): Unable to instantiate non-conobject class AIPlayer.

<------

The fuction calls also produce errors:

rw/scripts/server/RPGDialog.cs (198): Unable to find object: '0' attempting to call function 'setMoveSpeed();'.

The rest of the functions produce the same error. I also wasn't getting good spawn data for the TestNPC, the only alteration I made was :

pickSpawnPoint();

to

pickSpawnPoint(2);

Now the console shows that I have (at least) one good spawn point. But the other errors keep it from ever spawing the NPC. Any ideas?

Thanks in advance! And this is a great resource! Thanks so much!
#15
11/24/2004 (4:21 pm)
@Kyle: It sounds like you aren't passing the right bot or DataBlock to the function. I don't use RealmWars so I can't really help you.

@Nelson and anyone reading this thread...

Hey, I have a very interesting snippit to add to this.
This adds vendors and mission quest/reward item functionality to the Bots.
I needed to have npcs give and take items depending on missions and vendors to buy and sell wares.
I use an inventory object called Dollar and a few others.
This is up to you.
The vendors however can use any kind of item that you specify as currency.
So you can trade bombs for food. ~~/

Ari
"Measure twice, cut once."

*New! Mutiple actions in response to an answer!
Just type actions back to back with no spaces in the answer editor and end the string with -

Example:

RewardItem(FlameThrower_01,1)RewardItem(FlameThrowerAmmo_01,500)RewardItem(Pistol_01,1)RewardItem(PistolAmmo_01,34)SayChat("Thank you for completing that for me.")-

On line 287 in common/RPGDialogEditor/editorMain.cs

Change:
           %ActionEnd=strpos(%line,")")+1;
To This:
           %ActionEnd=strpos(%line,"-")+1;

On line 308 in common/RPGDialogEditor/editorMain.cs

Change:
            %ActionEnd=strpos(%line2,")")+1;
To This:
            %ActionEnd=strpos(%line2,"-")+1;

In starter.fps/server/scripts/rpgdialog.cs on line 50 replace the serverCmdRPGDialogAnswer function with the one below.

function serverCmdRPGDialogAnswer(%client,%sender,%questionNumber,%answerNumber)
{
   if(%client==%sender.RPGDialogTalkingTo)
   {
      %npcFile=%sender.RPGDialogScript;

      %Actions=GetAction(%npcFile,%questionNumber);

      if(%Actions!$="<InvalidQuestion>")
      {
         if(strPos(%answerNumber,"QL")>=0)
         {
            %ActionHeaderSize=strlen("<"@%answerNumber@">");
            %NextActionHeaderSize=strlen("<"@getSubStr(%answerNumber,2,strLen(%answerNumber))+1@">");
            %ActionStart=strPos(%Actions,"<"@%answerNumber@">")+%ActionHeaderSize;
            %ActionEnd=strPos(%Actions,"<"@getSubStr(%answerNumber,2,strLen(%answerNumber))+1@">");
         }
         else
         {
            %ActionHeaderSize=strlen("<"@%answerNumber@">");
            %NextActionHeaderSize=strlen("<"@%answerNumber+1@">");
            %ActionStart=strPos(%Actions,"<"@%answerNumber@">")+%ActionHeaderSize;
            %ActionEnd=strPos(%Actions,"<"@%answerNumber+1@">");
         }


         if(%ActionEnd>=0)
         {
            %ActionEnd=%ActionEnd-%ActionStart;
         }
         else
         {
            %ActionEnd=strlen(%Actions);
         }

         // BrokeAss Games Multi-Response Add-On
         %SubActions=getSubStr(%Actions,%ActionStart,%ActionEnd);

      for(%i=1;%i<%ActionEnd;%i++){

         %ParamStart=strPos(%SubActions,"(")+1;
         %ParamEnd=strPos(%SubActions,")")-%ParamStart;
         %Param=getSubStr(%SubActions,%ParamStart,%ParamEnd);

         %Action=getSubStr(%SubActions,0,%ParamStart-1);
         //echo("SubActions: " @ %SubActions); //Parser Debugging
         //echo("Action: " @ %Action @ " Param: " @ %Param); //Parser Debugging

         if(%Param!$="")
         {
            eval(%Action@"("@%Param@","@%client@","@%sender@",\""@%npcFile@"\");");
            %SubActions=getSubStr(%SubActions,%ParamEnd+%ParamStart+1,%ActionEnd);
         }
         else
         {
            eval(%Action@"("@%client@","@%sender@",\""@%npcFile@"\");");
            %SubActions=getSubStr(%SubActions,%ParamEnd+%ParamStart+1,%ActionEnd);
         }

         if(%SubActions$="-")
         {
            break;
         }

        } // End Multi-Response Add-On
      }
      else
      {
      echo("ERROR::Invalid Question/Answer!!\nnpcFile = "@%npcFile@"\nquestionNumber = "@%questionNumber);
      }
   }
}

Paste the code below into the end of starter.fps/server/scripts/rpgdialg.cs.

//<ActionList>SellItem(Item,Price,Currency,Amount)
function SellItem(%item,%price,%currency,%amount,%client,%sender,%npcFile)
{
   if(%client.player.getInventory(%currency) >= %price){
   %client.player.incInventory(%item, %amount);
   %client.player.decInventory(%currency, %price);
   %sender.player.incInventory(%currency, %price);
   messageClient(%client, 'SellItem', '\c1You have purchased %1 %2(s) for %3 %4 from %5.',%amount,%item,(%price*%amount),%currency,%sender.name);
   } else {
   messageClient(%client, 'SellItem', '\c1You do not have %3 %4 to buy %1 %2(s) from %5.',%amount,%item,(%price*%amount),%currency,%sender.name);
   }
   //CloseDialog(%client,%sender,%npcFile);
}
//<ActionList>BuyItem(Item,Price,Currency,Amount)
function BuyItem(%item,%price,%currency,%amount,%client,%sender,%npcFile)
{
   if(%client.player.getInventory(%item) >= %amount){
   %client.player.decInventory(%item, %amount);
   %client.player.incInventory(%currency, %price);
   %sender.player.decInventory(%currency, %price);
   messageClient(%client, 'BuyItem', '\c1You have sold %1 %2(s) for %3 %4 to %5.',%amount,%item,(%price*%amount),%currency,%sender.name);
   } else {
   messageClient(%client, 'BuyItem', '\c1You do not have %1 %2(s) to sell for %3 %4 to %5.',%amount,%item,(%price*%amount),%currency,%sender.name);
   }
   //CloseDialog(%client,%sender,%npcFile);
}
//<ActionList>GiveItem(Item,Amount)
function GiveItem(%item,%amount,%client,%sender,%npcFile)
{
   if(%sender.player.getInventory(%item) >= %amount){
   %client.player.incInventory(%item, %amount);
   %sender.decInventory(%item, %amount);
   messageClient(%client, 'GiveItem', '\c1%3 has given you %1 %2(s).',%amount,%item,%sender.name);
   } else {
   messageClient(%client, 'TakeItem', '\c1%3 does not have %1 %2(s) to give you.',%amount,%item,%sender.name);
   }
   //CloseDialog(%client,%sender,%npcFile);
}
//<ActionList>TakeItem(Item,Amount)
function TakeItem(%item,%amount,%client,%sender,%npcFile)
{
   if(%client.player.getInventory(%item) >= %amount){
   %sender.player.incInventory(%item, %amount);
   %client.decInventory(%item, %amount);
   messageClient(%client, 'TakeItem', '\c1You have given %1 %2(s) to %3.',%amount,%item,%sender.name);
   } else {
   messageClient(%client, 'TakeItem', '\c1You do not have %1 %2(s) to give to %3.',%amount,%item,%sender.name);
   }
   //CloseDialog(%client,%sender,%npcFile);
}
//<ActionList>RewardItem(Item,Amount)
function RewardItem(%item,%amount,%client,%sender,%npcFile)
{
   %client.player.incInventory(%item, %amount);
   messageClient(%client, 'RewardItem', '\c1You have been rewarded %1 %2(s) by %3.',%amount,%item,%sender.name);
   //CloseDialog(%client,%sender,%npcFile);
}
//<ActionList>SayChat(ChatMessage)
function SayChat(%chatmessage,%client,%sender,%npcFile)
{
   messageClient(%client, 'SayChat', '\c1%1 Says: %2',%sender.name,%chatmessage);
   //CloseDialog(%client,%sender,%npcFile);
}
#16
11/24/2004 (4:25 pm)
Deleted.

Ari
"I'll sleep when I'm dead."

*Edit: Thanks Nick!
#17
11/24/2004 (11:08 pm)
Great addon Ari!

For the formatting put: code within brackets in the beginning and /code within brackets after the last line of code.

Nick
#18
11/28/2004 (5:06 pm)
Hey, this is quite useful.
But I cannot open the website link to download the addon. Anyone knows where to get this?
Thx
#19
11/29/2004 (2:26 am)
@Lynn
The link above is to a webpage not a file.
The actual link to the file is http://www.geocities.com/dk_uo/rpgdialog.zip

*Snippit updated.
I updated my snippits above to handle multiple actions per answer.
Another chat action was also added.

Ari
"Measure twice, cut once."
#20
12/14/2004 (9:02 pm)
I am using the RPG dialog.

spawntestnpc(); could be called and npc appears, but the TalkTo() function never get called when I press q key.

it is inside xxx\client\scripts\default.bind.cs:

function TalkTo(%val)
{
echo("Calling TalkTo()");
if(%val)
echo("Calling commandToServer()");
commandToServer('RPGDialogRay');
}

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


I am using the demo mod but not the starter.fps within the SDK, I will try putting them together inside starter.fps. But, anyone could help me figure out what's happening? Thx

I open new topic for this problem @ qt=24054, thanks
Page «Previous 1 2 3 4 5 6 7 Last »