RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Dialog NPC

Arya

Wanderer
Dialog NPC

Summary:
This NPC can be used to create dialogs such as those in classical single player RPGs. The creation of the dialogs is done through an external program which produces a datafile that if positioned correctly within the RunUO folder allows the NPC to reconfigure itself on the fly, without rebooting the server.

The dialog script supports also invokation of custom code whenever a player chooses an option on the dialog gump.

Description:
This NPC is an evolution of the Conversational NPC I posted some time ago. It's more complex in its functionality though and much more powerful.

The NPC simulates dialogs with players with multiple choice answers (such as those seen in classical Ultima games). The dialog itself is created through an external program called DialogEditor, provided in the download package. The whole conversation is carried through a gump displaying the NPC speech, and a number of choices the player can make in response (limited to 8).

The NPC can be configured on the fly, so it doesn't need a server reboot to apply a new dialog. The XML files containing the dialog configuration must be placed in a well known folder within the RunUO main directory (by default RunUO\TheBox\Dialog), and once they're in a staff member only needs to double click the NPC to access the dialog selection gump (which will display only the name of the XML file, not the full path).

The dialog structure can be as complex as it gets, and I tried to do my best to make creation and editing user friendly. I have written a comprehensive readme file for the DialogEditor program (in the download package) which explains everything you need to know to produce dialogs.

Probably the most powerful feature of this NPC is the ability to interact with your code without actually recoding the NPC itself. Whenever a player chooses a response to whatever the NPC said, the dialog can be configured to dynamically call a function in an external script (provided the function has a specified signature, refer to the DialogEditor readme file for details).

I have provided two very simple samples of what this script can do:

- Thief: whenever a player with over 5000 gold in their backpack approaches this NPC, a dialog will start, leading inevitably to either the player donating the thief some money, or the thief stealing if the player refuses.

- Travel: this is a NPC that will teleport the player to either Britain or Trinsic for a price of 500 gc. If you drop 500 gc on the NPC it will ask you where you wish to go, if you double click it, it will first explain its function and then ask you if you agree to pay (if you say yes, but don't have the money in your bank the NPC will kill you when you try to travel).

Refer to the installation section for information on how to install or remove the samples.

As usual any feedback is appreciated, not working on a shard makes it quite hard to decently test things so please report any issues you might find and I'll try to address them asap.

Installation:
The package you download will contain 3 folders:

- DialogEditor : this is the program used to create the dialogs. As all my programs, this requires the .NET framework 1.1 to run. This folder also contains DialogEditor.html, the readme file with instructions for the program.
- Samples : these are the XML files for the two situation described above. By default put them into ..\RunUO\TheBox\Dialog and they will be accessible by the NPC when the server starts.
- Script : this folder holds all the files needed for the NPC to operate on the server and should be placed within your Scripts folder. If you don't wish to use the samples provided, delete the DialogNPC\Samples folder as they only contain support classes for the Thief and Travel dialogs.

If you wish to change the target folder for the XML files, you can do so by editing DialogNPC.cs. The option is right at the beginning of the file (remember, all folders are realtive to the core RunUO folder).

When you start the server use:

[add DialogNPC

to create the NPC. Double click it to access the list of available dialogs. Refresh the gump, if you add or remove XML files from the dialog folder to see the changes.

Updates

June 19 (1.1):
- Fixed bug where the player wasn't removed from the current user list and therefore couldn't initiate a new dialog.
- Changed the way the item-in-backpack trigger is handled by the NPC. Now the check is done just once, when the player enters the NPC's range, so the player will no longer receive the gump multiple times when moving around the NPC.

Download
http://arya.runuo.com/download/scripts/DialogNPC.1.2.zip
 

HadesUO

Wanderer
Thanks Arya this will definitly come in handy with the quest im working on that includes your other npc that responds to keywords.
 

GrimGreap

Wanderer
Nice scipt, will come very useful! :D. Just finished testin it out and i noticed one problem. When testing it with the thief sample script, once the conversation is finished, if the player is still in range of the NPC, the conversation will start again when u move.

Any ideas?
 

Arya

Wanderer
Yes GrimGreap, that's an issue with the way the NPC verifies whether a player is carrying a given item. If you read the Dialog Editor readme, it's explained in detail. I plan on changing the way this is done though, possibly doing the check only when the player trepasses the range limit. For now you should use this kind of trigger only if you plan on removing the item from the player...
 
Z

Zigler

Guest
sounds like a great addition .. could make nice quest with this I imagine
 
wow

:eek: Simply amazing... This has so many potential uses, from interactive FAQs through to shard-wide quests and scenarios

Yet another invaluble addition to the shard I'm working on :D

Found one problem though:
If you allow players to end the conversation and they right click or click the end button, it doesn't remove them from m_Users, so stops them from re-initiating the conversation again without resetting the npc. I just added a quick remove function to dialognpc.cs and called it from ButtonID =0 response on the gump and it seems to fix it..
 

Arya

Wanderer
Thank you very much Hunter for that one! I think I once incurred in that problem while testing but then forgot to investigate. I will add it to the update I'll be posting later on with the fixed range for the item in backpack trigger.
 

Arya

Wanderer
I have posted a small update in the first thread. I fixed the bug with the player not being removed from the users list and changed the way the range check is made when looking for items in the player backpack.

Now the check will occur when the player crosses the boundary of the Range value for the dialog (in other words when the player enters the NPC's range). You can test this fix by running the Thief example... you will no longer receive the gump multiple times when moving close to the NPC, but only once when you approach it for the first time.
 

Arya

Wanderer
SingularityZero said:
Simply amazing. I was wondering though if we might make a thread where we posted our function scripts?
I personally don't mind, not sure how the moderators would feel about it. If it's something small, or just an XML script without any server code you might post it in this thread. On the other hand if you write a quest that makes use of this NPC, you should definitely create a separated thread and just point to this one as requirement.
 

David

Moderate
Arya said:
I personally don't mind, not sure how the moderators would feel about it. If it's something small, or just an XML script without any server code you might post it in this thread. On the other hand if you write a quest that makes use of this NPC, you should definitely create a separated thread and just point to this one as requirement.
Agreed. If you make something with this script you want to share, by all means post it. A link back to this thread would be a really good idea as well.
 

lover1973

Wanderer
Thanks for your great scripts and program. but I am having a problem right now.
I tried to make a xml file with your Dialog Editor and the program showed a error message when I typed text(chinese text) in the Editor. The following is the information reported:

************** Exception Text **************
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at UOFont.UnicodeFonts.GetCharImage(Int32 Font, Char c)
at UOFont.UnicodeFonts.GetStringImage(Int32 Font, String Text)
at Arya.DialogEditor.DialogOptionsEditor.UpdatePreview()
at Arya.DialogEditor.DialogOptionsEditor.txTitle_TextChanged(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnTextChanged(EventArgs e)
at System.Windows.Forms.TextBoxBase.WmReflectCommand(Message& m)
at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
at System.Windows.Forms.TextBox.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

I dont know why. if I type English text in any Editor, then everything is good. It seems Your program does not support chinese text.
I really like you GREAT program, Can you solve this problem for me?? :confused:
 

Arya

Wanderer
It looks like an error in the UOFont libraray which I didn't develop myself (therefore I have no code to fix). The error occurs because apparently the library can't display a preview of the text displayed on the gump using the UO fonts. In the next version I'll make sure that if this error occurs the program won't crash, but you'll simply get no preview. More than that I'm afraid I cannot do. Hopefully within the week :)
 
S

Seven

Guest
Can't wait to use this on my server. Keep up the great work! Thanks.
 

lover1973

Wanderer
Arya said:
It looks like an error in the UOFont libraray which I didn't develop myself (therefore I have no code to fix). The error occurs because apparently the library can't display a preview of the text displayed on the gump using the UO fonts. In the next version I'll make sure that if this error occurs the program won't crash, but you'll simply get no preview. More than that I'm afraid I cannot do. Hopefully within the week :)

Thanks, but i wanna say one more thing, this error cccurs when I type some chinese text in editors, even just copy chinese text in them, not preview.
 

Arya

Wanderer
lover1973 said:
Thanks, but i wanna say one more thing, this error cccurs when I type some chinese text in editors, even just copy chinese text in them, not preview.
That's correct. The preview is updated real time with whatever text you input into the text box.
 
Arya said:
I personally don't mind, not sure how the moderators would feel about it. If it's something small, or just an XML script without any server code you might post it in this thread. On the other hand if you write a quest that makes use of this NPC, you should definitely create a separated thread and just point to this one as requirement.

Made a post in submissions with a quest NPC I made. Hope someone finds it useful. I know I learned a little more code when trying to make it. Thanks for the inspiration Arya.
 
Top