Resource icon

David's Conversational Townsperson 1.1a update corrected

No permission to download
This was written for RunUO 2.0 by David, some of you may remember him from RunUO forums, he was a moderator there and genuinely helpful guy. He wrote a lot of the early tutorials also. I know this has been uploaded to some of the RunUO archive sites, but someone asked about it in another thread here at ServUO so I thought I would post it here as well so that when people search here they can find it.

I have tested the script with ServUO 55.1 on Mono 5.18.0.268 and it works without any changes to either its own scripts or any distro scripts. The Speech Rules editor was tested on Windows 10 64 bit and also works.

David's Original Wall-Of-Text Description:
Summary:

This is a Townsperson NPC which is able to converse with players. The NPC uses a database of speech triggers and replies and is able to select replies based on a number of criteria. An application is also provided to edit the speech database.

Version:

1.1, Feature Update Release for RunUO 2.0

This version adds the ability to respond based on the presence or absence of an object in the players pack, and to optionally delete the object. An object may also be added to the players pack or a creature spawned at the npc’s location. Additionally a property “Tag” was added to the Townsperson and responses may be filtered on that tag. The Townsperson’s Title and Name may be specified when the npc is created, and the attitude and wealth may be changed by updating the corresponding property. Various bug fixes, error trapping, and general tweaking were also added.

Description:

The Townsperson is a very well developed NPC (speech routines notwithstanding.) Considerable effort went into providing variations in appearance and attire. The Townspersons are each either poor, normal, or rich and dress accordingly with color coordinated outfits. They also have a rude, indifferent, or good attitude which is reflected in both their karma and potentially in their speech. The normal and rich Townspersons may be able to train a random skill—the rich might even know two skills. Both wealth and attitude are properties that may be set by a GM or by one of the advanced spawner systems.

The Townsperson uses a multi-threaded in-memory database consisting of several speech rules. Each rule has one or more triggers which are words or phrases that may be spoken by a player. When a trigger is detected by a Townsperson; it will stop, face the player, and give one of a number of replies. The replies can optionally include the Townsperson’s name, the player’s name, or the name of the region. Replies may be filtered on the Townsperson or player gender, the region, the Townsperson’s attitude, the Townsperson’s title, name, or the general time of day; i.e. morning, afternoon, evening, night, or overall daytime or nighttime.

This version (1.1) adds a property to the Townsperson called “Tag.” Tag may be set to any text string by a GM or by one of the advanced spawner systems and allows very focused response filtering. Perhaps the most exciting feature of this version however, is the ability to filter responses based on any object and whether the player does or does not have that object equipped or in his pack. If the object is found, it may optionally be deleted. Finally an object may be placed in the players pack (or a creature may be spawned at the Townspersons location.) The object names are the RunUO Item names, not the displayed name…enter the same text you would use for a spawner or the [Add command.

In addition to speaking a reply, the response may be accompanied by one of ten different NPC animations and a separate “reaction.” The reactions you may choose from are: do nothing, attack the player, flee from the player, the npc becomes criminal (and attackable,) or the npc hides, dies, or deletes itself. These reactions follow the text response and animation by just short of two seconds.

The speech database is loaded from an xml file in the RunUO\Data directory, and maintained in-memory as an ADO dataset. Each database lookup is handled in its own separate processor thread. This arrangement provides a fast smooth speech response and helps to minimize impact on the overall performance of the server. Should you choose to edit your speech database while the server is live; there is no need to bounce the server to get the updates. As a GM or better, ingame, simply type [dbReLoad to refresh the data from the current xml file. Using this command will pause the Townspersons speech for 2 or 3 seconds to flush the queues and load the updated database.


Notes:

With version 1.1 the starter speech database is intentionally mis-named to avoid overwriting any current databases. To use the starter database look in the RunUO\Data folder and rename the file “Rename.SpeechRules.XML” to “SpeechRules.XML.”

The speech database included is intended to provide a good but basic functionality. Most shards will want to expand on the database to fit their needs, a tool is provided for that purpose.

Since the database is kept in memory, it is not recommended for a server which is already short on RAM. (You know who you are.) Also since threaded calls are made to the database, it will benefit from multiple processor cores.

There is a switch available via [Props which determines if attacking the npc is a criminal action. The switch defaults to false but the default can be changed in a commented line near the top of the Townsperson.cs file. Using a reply with a reaction of Attack or Criminal will set this switch to false.

The Time of Day criteria has six options; all are based on ingame time. Morning is between 6AM and noon, Afternoon is noon to 6PM, Evening is 6PM to midnight, and Night is midnight to 6AM. Daytime and Nighttime are based on the default LightCycle.cs file to match the actual daylight cycle. Daytime is considered 5AM to 11PM and Nighttime is 11PM to 5AM. That is determined in Townsperson.cs in the CheckTOD() method at line 484 should it need to be adjusted to suit your shard.

This package is written for all RunUO 2.0 releases. However, I believe it may be modified easily for RunUO version 1.0. In ReplyList.cs at line 50 a commented change would need to be made, in Townsperson.cs starting at line 239 the hair and beards will need to be handled differently, and at the top of SpeechDataHandlers.cs registering the command dbReload will need to be done the old way. Otherwise, I expect it will run in 1.0 just fine.


Installation:

The Townsperson script itself consists of four files; Townsperson.cs, Logging.cs, SpeechDataHandlers.cs, and ReplyList.cs. However there is also a SpeechRules.xml file which must be in the RunUO\Data folder, and SpeechRulesEditor.exe which should be in your root RunUO folder. All the filepaths are maintained in the archive, just extract it into your RunUO folder, restart the server, and you should be good to go.


The Speech Rules Editor:

SpeechRulesEditor.exe is a standalone application to edit your speech database. To edit the working database, it must be in the root RunUO folder (where RunUO.exe or Server.exe is.)

22ltee.jpg


You may copy the Speech Rules Editor to a separate folder or computer to work on your database, but a copy of the database must be in a Data folder which exists in the same folder as the editor and the database must be named SpeechRules.xml. A starter database is included with the package as well as an empty database which you can use should you choose to start from scratch. To use the empty database rename EmptySpeechRules.xml to SpeechRules.xml.

When you start SpeechRulesEditor, you will see three sections; Rules, Triggers, and Responses as well as several buttons along the bottom; Read XML, Import XML, Write XML, Exit, and an option to disable various informational messages/warnings.

First click Read XML to populate the form with your current speech data and enable the remaining buttons.

The Rules section is where you organize your speech rules. You may add a new rule or edit or delete existing rules (with the exception of the special {Default Rule} which cannot be altered.) If you type in the single text box above the displayed list and click Add, a new rule with that name is added. If you click Update, you change the name of the currently selected rule to what you just typed.

The Triggers section buttons function identically to the Rules section. The triggers themselves however, are the words or phrases that the Townsperson will listen for within a player’s speech. A trigger must match exactly (except for case) to what the play says, but the trigger can be imbedded within what is spoken—it does not need to be the only thing, or even the first thing said.

The Response section is the meat of the package. Along the left side you will see the edit box at the top and a list of existing responses below it. The regular Add New, Update, and Delete buttons are at the upper right and below them you will see a reminder of the variables you may use within a response. If a response contains {0} that will be replaced with the name of the NPC, {1} will be replaced with the players name (or Name Mod if one exists,) and {2} with the name of the current region. Below that are the Response Conditions. If any conditions are set, that criteria must match for the specific response to be used. This will allow males or females to respond or be treated differently and it will enable a real difference in the NPC’s attitude. You can even vary the responses by time of day. Below the conditions, in the Response Result section you may select an animation for the NPC to perform when that specific response is used, for example the NPC can shake his head, salute, bow, or take a swing at the player. Following the animation choices, you may choose one of several physical reactions such as Attack, Flee, Criminal, Hide, Die, or Delete. Note that Attack or Criminal will make the npc attackable.

New with version 1.1 you can use the Townsperson’s Title as a response filter, or you may use a special Townsperson text property called “Tag.” You may also specify any ingame item and filter responses based on whether the player does or does not currently have that item. As a response result, and if an item was specified, the item may be deleted. Finally (and independent of the previously mentioned item,) an object may be created as a response result. If the created object is an item, it will be added to the players pack—or placed at the players feet if there is not room in the pack. If the object is a Mobile it will be spawned at the Townspersons location.

Clicking Merge XML will allow you to browse for a Speech Rules database in another location or with a different name. If found, and if it is a valid database, any Rules in the new database which do not exist in production database will be merged with their triggers and responses. At this time Merge XML will not merge triggers and responses for rules which already exist in the production database.

Write XML will write the current data in your editor to your production database. Be sure you take adequate precautions to maintain backups of important versions.


Notes:

In this version, in order to not overwrite any current databases, the starter database was renamed. To use the starter database you must open the RunUO\Data folder and rename the file “Rename.SpeechRules.XML” to “SpeechRules.XML.”

The database schema has changed for version 1.1; opening an existing version 1.0 database in the Speech Rules Editor will automaticly backup, convert, and save the database as version 1.1.

The source code for the Speech Rules Editor is available below as a Visual Studio 2005 project. These files are not required to use this system.


Some Caveats to note:

There is already a "time" keyword built into RunUO/ServUO (there used to be more, you used to be able to ask them for directions and such). If you are near a townsperson and another NPC, you may get different (but both technically accurate) descriptions of the time of day

The answer given for occupation is not persistent, they may say they are a blacksmith, and then a minute later a mage.
Author
Zavreyon
Downloads
122
Views
1,971
First release
Last update
Rating
0.00 star(s) 0 ratings

Latest Updates

  1. Speech Editor Source, Italian and German Language Packs added

    So my last update didn't include the prior release files. Theyw ere still accessible via history...
  2. Additional language packs

    Speechrule databases for additional lanaguages added, German by Gossman and Italian by Thilgon.
Back