Previous Blog Next Blog
Prev/Next Blog
by date

Racist Elven Orcs?

Racist Elven Orcs?
Name:Gareth Fouche
Date Posted:Aug 04, 2006
Rating:3.4 out of 5
Public:YES
Comments:YES
RSS Feed:GarageGames Blog feedor Subscribe with .
Profile Page:View profile page for Gareth Fouche

Blog post
I have been working on my dialogue system, and its coming along quite nicely.

I'd previously implemented the RPGDialogue resource, but wanted to move to a more database orientated approach, away from plain text files. So I set out to make my DB-based dialogue tree system. For anyone who is curious, I'll explain the system.


At the core of it is the DialogueManager, which sits on the server and manages things. When a player tries to interact with an NPC (using my interaction resource), a request is sent to the DM to begin a dialogue. The DM asks the AI if it will accept the request. The AI can reject it, if its busy with something else, like attacking or chasing an enemy.

Each AI has a DialogueSet. This is pretty much just a list of the possible dialogues it can say to a player. Any piece of text a AI can say is represented by a DialogueNode (these are the nodes in the dialogue tree graph). Now, each node has a condition under which it gets displayed. The DM runs through each node in the set, checks the condition, and stops at the first one that evaluates to true. The conditions are just script functions that return true or false. For instance, I have an "isRace(X)" function. The entry in the database, for a node, looks like "isRace(<<PC>>, Elf)"

Since the DM keeps track of the dialogue, it can replace the special tag <<PC>> with the server side id of the clients player object. Likewise, it inserts the players name etc into text strings.

Right, so the DM finds the first node that passes. This allows you to easily set up quest dialogue. For example, if you have a quest to rescue timmy down the well, you could have 4 nodes, with conditions as so :

1 = "Oh help, my son timmy has fallen down the well!" - condition => questNotActive(TimmyInWell)
2 = "Have you found timmy yet? Please, hurry!" - condition => questState(TimmyInWell, 0)
3 = "You found timmy! Thank you so much. Here, have some gold..." - condition => questState(TimmyInWell, 1)
4 = "Thanks again for finding timmy. You're the greatest, Hero Guy!" - condition => questState(TimmyInWell, 2)

As long as you set the appropriate variable, the right node will be displayed. Which brings me to the runScript. Each node, and any response, can have a script which runs when it is displayed/selected. You can give him gold, set vars, change the weather, spawn enemies, etc. Anything you can script.

For each Node that gets displayed, there are a number of Responses, which also use the conditional showing idea, but the DM shows ALL responses that eval to true, not just the first. Each Response has a list of possible nextNodes, which the DM evaluates in the same manner as it does the initial DialogueSet, ie finding the first and returning it, etc etc, you get the idea, basic dialogue tree stuff.

The only other interesting structure is the DialogueInfo table. This contains optional text, which also gets displayed based on conditions. For instance, if you are questioning a shady character, you could have a piece of text saying "You notice spots of blood on his cuff", with the condition being "passSkillCheck(Spot)". Basically, extra details.

Anyway, explenation aside, what does this mean? It means I can implement racist and snooty NPCs! (The orc in the picture below is only nice if you are an elf)







Yay....um, wait, maybe thats not a good thing. Hehe. ;) .I'm quite happy with how its come out. Not only is it really flexible and powerful, it was relatively quick and easy to implement. Took about 2 days, after working hours.





So whats left?

Well, I want to change it to evaluate a list of conditions, not just one, and only allow through nodes that pass all of them. Likewise, have it execute an arbitrary number of scripts in a list. Should take about 10 minutes to put in, I would have done it last night but it was midnight and sleep was calling.

Obviously, I need to code up more condition and result scripts. Also a snap.

I want to add entries for animations and sounds to play, this could be done in script, but since I will probably use it a lot I'll make seperate DB entries for them.

The main thing now though is a dialogue editor GUI. Right now I simply edit the DB by hand, its not too bad at the moment, but it will quickly become a pain when I add more dialogues. This should also be pretty easy, if slightly more time consuming. I am going to try making use of the treeview gui, so I can get a nice overview of the dialogue structure. Since there can be cycles in the tree, I will just need to watch for that, to prevent infinte loops, hehe.

(Just a small note, my RPG won't actually contain the usual blah fantasy races like elves and orcs, I just called them that for test purposes.)

Recent Blog Posts
List:06/24/08 - Celebratory
05/13/08 - The Gingerbread Villa
04/14/08 - SoW - Some concept art
04/02/08 - Blog of War
02/28/08 - Scars of Bloom
01/16/08 - SoW - Character Customization
12/04/07 - SoW - Environments.
10/22/07 - SoW - The War in the West

Submit ResourceSubmit your own resources!

Adam deGrandis   (Aug 04, 2006 at 11:42 GMT)
pretty neat. :)

Mincetro   (Aug 04, 2006 at 12:21 GMT)
Reminds me of the system in Morrowind/Oblivion, sounds pretty cool.

Don Hogan   (Aug 04, 2006 at 14:06 GMT)   Resource Rating: 4
That's very cool!

Edit: Ok, I hit the submit for rating instead of the post, so I'll add this: Just the 4 lines of logic for the quest state is very useful for me (an artist) because it clearly shows a way of thinking about structure I'd have wrestled with otherwise.

Now, I need more coffee. =)
Edited on Aug 04, 2006 14:09 GMT

Jonathon Stevens   (Aug 04, 2006 at 16:53 GMT)
Good stuff, are you planning on releasing the code in a resource?

Jermaine Morgan   (Aug 06, 2006 at 15:57 GMT)
it looks cool

You must be a member and be logged in to either append comments or rate this resource.