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

#61
07/20/2005 (3:06 pm)
Chris, this is unbelievable.. its alot to go thru for little ole me.. but firSt thing tommorrow Im going to have a bash at it.. and you know what... I think I get it.. Thanks alot mate...

MArk
#62
07/20/2005 (3:54 pm)
No problem... Just remember. If you see someone who needs help or a piece of code that you have, don't hesitate to hand it over. Indies should do everything to help fellow indies.

:)
#63
07/21/2005 (5:46 am)
Well Chris.. I got stuck...

I managed to use the code in RPGDialog.. have added it to my running Kork style NPC..
(it works.. Kork runs off and the Dialog closes, but it works)

I made a NPCCharacters.cs as suggested.. and did exactly as you said regarding health pack info...

BUT...
Quote: I created a spawnNPC() funciton that would create an NPC with the right script at the right location.

Easier said than done... I dont know how to do this...

Quote: I made a spawnNPC call for each of the locations...


...or this

Quote: I also had to create new PlayerData datablocks for each NPC that needed a different shapefile used. Which means I had to change the spawnNPC() function. I added %datablock to the end of its decleration, and changed the spawnTestNPC() function to tack DemoPlayer onto its call to spawnNPC().


Damn... or this...


Quote:
Now to get my NPC's to have the right shape, I went into server/scripts/player.cs, searched for PlayerData... That is the datablock that tells TGE what DemoPlayer (PlayerBody) what it does and how to act and look.

Now.. this I THINK i understand.. just cant get to there from here... and When you put
PlayerData (NEWBody : PlayerBody){ 
 //new shapefile 
 ShapeFile = "I am a shape directory";
}

...where do I put this?
I find...
ShapeFile = "~/data/shapes/jill/jill.dts";

in my code ok (yes Ive changed the shape from the orc)
...and I get that you are somehow making it dynamic so it can be changed er.... somewhere else... in the new NPCcharacter.cs perhaps??

(This is too much for you to answer-- maybe just this will help)
Currently I have the original Kork Orc (now looking like the Bravetree girl tho) running about like mad.. as far as I see, it is created in game.cs by

function AIManager::spawn(%this)
{
   %player = AIPlayer::spawnOnPath("Bob","MissionGroup/Paths/Path2");
   %player.followPath("MissionGroup/Paths/Path2",-1);

   %player.mountImage(CrossbowImage,0);
   %player.setInventory(CrossbowAmmo,1000);

//added by mark
   %player.RPGDialogScript = "Test2";
   %player.RPGDialogPortrait = "hilde.png";
   %player.RPGDialogStartQuestion = 1;
   %player.RPGDialogBusy = false;
   %player.RPGDialogBusyText = 'Sorry but I\'m busy talking to %1 right now.';
   %player.RPGDialogTalkingTo = 0;
//end of mark

   return %player;
}

...as I said, I have added the RPGDialog stuff...

NOW... Are you saying I should MOVE all this to my NEW NPCcharacters.cs...
If so... HOW???????

Once done.. I may be able to patch up the rest...

thanks again... sorry for being a real pain in the ass...

mark
#64
07/21/2005 (6:14 am)
ok... First off, get rid of Kork... Place any AI apawning in the NPCcharacters.cs file. You will need calls that look something like this: I could be wrong about the order or number of arguments... so check the RPGDialog.cs file

AIPlayer::spawnNPC("Bob", "BobsScript", ... Cant remember what else goes here... , NEWBody);

now... that wont really work. Besides the fact that I cant remember what the other arguments are... but because my spawnNPC funciton takes 1 more thing then yours. It takes a player datablock as well. Thats because I added it in. You have to do the same.

In RPGDialog.cs, there is the function:

function SpawnNPC(%name, ... , %location, ... cant remember what else)
{
   // Random things including a call to AIPlayer::spawn(..., DemoPlayer)...
}

I changed mine to be this:

function SpawnNPC(%name, ... , %location, ... cant remember what else..., %dBlock)
{
   // Now mine says AIPlayer::spawn(..., %dBlock)
}

So there you see how I gave it hte ability to dynamically change playerBody datablocks...

But to use it you have todeclare some datablocks to use.

If you open player.cs and search for PlayerBody or PlayerData... you will see a datablock that declares your current player.

Create a new one by extending that one. That means the new one will have exactly the same things as the last one. Unless you change something, which we are going to do. We are going to changed the shape file. That's where this comes in:

PlayerData (NEWBody : PlayerBody)
{
   //new shapefile   ShapeFile = "I am a shape directory";
}

I think that is the right way to do it. Might need some tweaking though.


Quote:

--------------------------------------------------------------------------------
I created a spawnNPC() funciton that would create an NPC with the right script at the right location.
--------------------------------------------------------------------------------


Easier said than done... I dont know how to do this...

To do that you look at hte decleration of SpawnNPC in the RPGDialog.cs script. And fill one out. It will look like this:
spawnNPC("Bob, .. random things, "BobsScript", ... , "12 34 56", ..., NEWBody);

As you can see. I filled everything out, including the name of the script that I created in the game after hitting f5 to go to the dialog editor; and the location which I know because I had placed a healthpack named BobsScript there. (I named mine 1a, 1b, ... 9c... to make it easier)

Hope that helkos clarify
#65
07/22/2005 (3:02 am)
Nearly there... can you confirm (yes or no will do..) the Q's below???

1)
OK you said...
Quote:
Place any AI apawning in the NPCcharacters.cs file. You will need calls that look something like this: I could be wrong about the order or number of arguments... so check the RPGDialog.cs file

AIPlayer::spawnNPC("Bob", "BobsScript", ... Cant remember what else goes here... , NEWBody);

AND YOU SAID...
Quote:
In RPGDialog.cs, there is the function:
function SpawnNPC(%name, ... , %location, ... cant remember what else)
{  
 // Random things including a call to AIPlayer::spawn(..., DemoPlayer)...
}

Now the first bit is for CALLING the function SpawnNPC right?and...

2)
that is what you put in the new NPCcharacters.cs file?



3)
The second bit is is sitting in RPGDialog (why, do you leave it there exactly?) and this is the function that gets called by the above?

4)
IS IT?

5)
The PlayerData (NEWBody : PlayerBody) bit in Player.cs is for switching meshes.. I understand that, and it creates an extra data block (NEWbody) that you can change when you CALL each NPC???

SO.. finally..
6)

you said:
Quote:
To do that you look at hte decleration of SpawnNPC in the RPGDialog.cs script. And fill one out. It will look like this:
spawnNPC("Bob, .. random things, "BobsScript", ... , "12 34 56", ..., NEWBody);

Now.. are you editting number 1) (above) now? shouldnt it be

function spawnNPC etc etc?? is that the bit? or is this something NEW???
... and again.. would you leave it in RPGDialog?
Why not move ALL code to do with NPC's together in one file?

start of the file could set up all the stuff, end of the file could call all the NPC's zombies out of their graves and start flesh eating as they are supposed to.. ha ha ha...


...are you fed up with me yet?

I PROMISE, that when I get this done, Im gonna write a dummiew resource for creating NPC. The last word, for complete newbie idiots...

:)

Mark
#66
07/22/2005 (4:05 am)
1. Yes, the first quote is calling the function... and the second one is the function itself.

2. Example NPCCharacter.cs file:
// BEGIN FILE

function spawnEveryone()
{
spawnNPC(...); // Put all the stuff we talked about in there.
spawnNPC(...);
}

// END FILE

3. Yes, and it gets left there because it makes up the NPC system. That way every part of the core RPGDialog system is in those files. Then we make our own little functoin to make accessing the system easier, hence our spawnEveryone function.

4. Yes, that is what hte first statement is calling, is that code in RPGDIalog.cs

5. Yes, we added the extra argument to the spawnNPC functoin (%dBlock) so we could specify what shapefile we wanted to use, which requires each shapefile to have its own datablock. PlayerData (NEWBody : PlayerBody) simply creates a new datablock with everything the same as the old accept we change the shapefile.

6. No, my line is right. Anyhting with the word function at hte beginning declares that line as a funciton you can now call. You can only have ONE function spawnNPC() because if you declare it more hten once the engine wont know which to use (There is an exception to this. If you declare them with different numbers of arguments, but for hte sake of this discussion assume you cant)

The line is the same as the first line. Actually the first line is wrong. It has AIPlayer::spawnNPC.. it should just be spawnNPC().

As I said. You want to seperate the system from your access to it. So everything RPG system related, like the function declerations ( function spawnNPC(...){...} ) and code to make RPGDialog work , goes in RPGDialog.cs... and everything you use to access the system, like spawnEveryone, which makes NPC's, goes inside characterNPC.cs

You could do it your way, but my way is good programming practice, and much cleaner and easier to sort out and work on.

No I am no fed up with you. But you really need to pick up a programming book (Sam's teach yourself C++ in 24 hours is a good one for beginners) and read up in the docs about Torque script. If you don't know how to code at least a little bit, you won't be able to do much at all with Torque.

As for creating a dummy resource for creating NPC's.... This thread (or the last 10 posts of it) are pretty much a dummys guide. You shouldn't write one if you don't fully understand everything in it, or even how to code for that matter.
:)
#67
07/22/2005 (5:48 pm)
Thanks for your help Chris, will leave it till tomorrow to dive in and try it.. Im basically there now I think, all thanks to you.. good to get the clarifications...

I agree that everything that we need to make a dialog work should be inRPGDialog.cs, but arn't we putting everything we need to get a NPC to work ALSO into RPGDialog? An NPC needs many different things, not just dialog... an inventory, a big gun (not in my games tho) a job, a shape (handled that one) , a sex (I have the solution to this one...UN implemented) etc etc etc...
I feel like it should be AIPlayer (or a new NPC.cs) that gets extended... with possibilities for future expansions..? Like if you need your NPC,s to... oh I dunno.. forget it...Im being extremely picky...

Thanks for ALL your help...

MArk...

...but I do think there could be better newbie help docs... but sure.. I'm probably NOT the one to write 'em...


...yet


; )
#68
07/22/2005 (5:59 pm)
@Mark - I hope you get it working properly. Look me up on msn (email from profile) this weekend if you need help.
#69
08/01/2005 (7:32 am)
What functions are getting called when you walk away from the NPC (to make the dialog close)? I can't seem to figure it out.

Grrr... I figured it out right after I posted this...
#70
08/06/2005 (10:54 am)
I am assuming, that if you are installing this with the demo, that "starter.fps" is the same as the "demo" folder. Correct? And that I should replace all instances of "starter.fps" with "demo". Am I right?

I tried installing and after installing, hitting f5 didn't work....nothing happened.


Also, certain files that you are supposed to modify...they don't exist. For example:
example\starter.fps\client\scripts\client\config.cs

There is a
example\starter.fps\client\config.cs
but no
example\starter.fps\client\scripts\client\config.cs

is this a typo? I assumed it was and modified the client/config.cs file.
#71
08/06/2005 (12:40 pm)
Nevermind. Me got that part working now. This thing is very cool.
#72
08/06/2005 (8:21 pm)
This thing is awesome. A HUGE time saver. It's very useful and has many features, and is easy to use. Much props to the bro. Gonsalves. By the way, you should start accepting donations on your website, I'm sure there are some who would contribute to this type of thing.
#73
08/10/2005 (7:35 am)
Link down...
#74
08/10/2005 (8:04 am)
No it's not
#75
08/17/2005 (2:12 am)
Where can I download it?
#76
08/17/2005 (3:54 am)
The 5th line from the top says
Quote:
This file can be downloaded from this website

click on website....

Then click download at the top of the page that opens ........

Just tested. It works perfectly ;)
#77
10/02/2005 (4:10 pm)
Incredible resource! Got this working in < 20 min!
#78
11/08/2005 (5:43 pm)
Hi,

I've integrated the RPGDialog in the given FPS Starter Kit level. However, when I click on one of the underlined words, the dialog doesn't link to another question. In fact, the dialog closes, in the chat HUD I see the fact I "said" the underlined text, but no other dialog appears.

Also, when I click on an answer that would launch another question, the current dialog closes and no other one appears.

Has anyone else seen this behavior, or have any ideas how to fix this?

Thanks ahead
#79
11/17/2005 (5:01 pm)
Great resource! I'm a noob with a question. Has anyone had luck with or tried triggering an RPGDialog outside of key strokes or mouse? Like I said I'm a noob
#80
11/18/2005 (7:17 am)
Isaac - Find the key binding that triggers the conversation..... Create a scheduled radius container check around the npc and if theres a human in it then call the talk code.

Look at the ASIGuard resource for some methods that will let you do a radius check and find ahuman and get there id.