Saturday, February 21, 2009

Howto: RPG dialog system

Well, Im going to explain now how the dialog system in my project is implemented.
But first, let me talk a bit about the project. The Ark is a very traditional RPG, although I use 3d features, the main view mode is isometric like. A 3rd person view is also provided for those used to more modern times. It is inspired in old classics like Fallout 2, Baldur's Gate and Diablo, looking to reach an adequate balance between action and quest solving. The secondary goal is to produce a game using only free software. Windows version is developed and compiled using Code Blocks+gcc, 3D models will be produced exclusively with Blender and all libs used must be free software. Once cleared this, lets go to the point.
One of the most important things in a CRPG is the dialog and the quest system. For example, the Oblivion is a great RPG, only degraded by its poor and stupid dialog system. Take the same game mechanics, but with a decent dialog system and you get Fallout 3, an even greater RPG.
So, how to implement such system? Without further ado, my solution.
The base of everything is the scripting system. Im going to suppose that you already have one, with access to game entities attributes. For the dialogs, I use a a container-like class, which holds the data of the current dialog phase. The dialog script receives a parameter Q, signaling where in the conversation are you and returns an NPC line, and several player reply/Id pairs. Initially I pass "root" as value. When the player chooses an answer, Q takes de value of the reply id code and the script is executed again. You can also make the script return a list of values instead of using a container.
This is how an script looks in a sort of pseudocode:

if q=root then
set npc_line *Starting line*
set player_reply_pair *Reply 1*,*question1*
set player_reply_pair *Reply 2*,*question2*
else if q=question1 ....

and so on. This is the simple version. Things get complicated when we mix attribute/skill dependent replies. Use your imagination...
Then comes the quest part. My solution is to have a list of flags, a sort of variables that hold values. A dialog script can consult this list to see if a flag exist, if not, it is added. another pseudocode example:

else if q=accept_quest then
set npc_line *Good, go to do what I said*
create flag Quest1,active
set player_reply_pair *Ok*,*ok*
else if q=questionX....


Seems easy, isnt it? The method works, but I would like to hear your opinions to improve it or a better way to do this.
And here you can see the system in action, four youtube videos:







0 comments:

Post a Comment