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!

[2.0] Conversational Townsperson - updated

David

Moderate
[2.0] Conversational Townsperson - updated

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 called “Tag” was added to the Townsperson and responses may be filtered on that tag. The Townsperson’s Name, Title, and Tag 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.

1.1a Improved Hide response.

I am sure more can be done, but I am happy with this version and do not antcipate further updates in the near future. If you add a feature, I look forward to your submission.

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 RunUOData 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 RunUOData 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.
  • Thilgon has put together an Italian version of the speech database which you can find later in this thread. <here>
  • Gosmann has posted a German version of the speech database in this thread. <here>

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.
 

Attachments

  • Townsperson 1.1a.rar
    55.4 KB · Views: 366

David

Moderate
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.)


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.
 

Attachments

  • SpeechRulesEditor.rar
    44.6 KB · Views: 117

Mideon

Page
Once again, premium quality release as per your standard usual :D

Thanks again David. I may tinker around with this as I'm also looking to get into some AI to make things a bit more immersive IG for players....will be checking out Ravenal's AI patch and see what I can come up with.

Cheers and keep up the good work.
 

Kamron

Knight
I am not sure if Ravenal is working on Town based AI Personality, but combining this with various AI Personalities could make the shard almost TOO realistic ;)

Thank you for this wonderful release David.

EDIT: I do not put my tools in the main directory of the server. Is it possible to create a way to open the XML file, or provide the source code so I can.
 

David

Moderate
Kamron;818520 said:
I do not put my tools in the main directory of the server. Is it possible to create a way to open the XML file, or provide the source code so I can.

Sure, the source for the editor is attached to the second post.

/edit: Or you should be able to put the editor anywhere and create a shortcut which has the RunUO base directory as the "Working Directory."
 

Mideon

Page
Kamron;818520 said:
I am not sure if Ravenal is working on Town based AI Personality, but combining this with various AI Personalities could make the shard almost TOO realistic ;)

Thank you for this wonderful release David.

EDIT: I do not put my tools in the main directory of the server. Is it possible to create a way to open the XML file, or provide the source code so I can.

Immersion is a good thing :D

I mean Rav's upcoming Finite State Machine patch. It can make very interesting monsters...but can also likely be adapted for very colourful townsfolk. I haven't had a chance to check out his patch yet to see if it can be easily done or if I should consider creating a framework for it :D
 

David

Moderate
This is a minor tweak that improves the Hide response result. Hide now lasts a full 5 minutes as intended and the npc is allowed to wander around while hidden. The first post is updated as well, but the file attached here is the only one that changed.
 

Attachments

  • Townsperson.cs
    42.8 KB · Views: 34

koluch

Sorceror
..ok Im old and slow....

I wanted to test this out, as all your scripts I have found wonderful.
But alas, I am doing something wrong.
This is what I did just to test:
1)Used the XML speech you provided.
2)spawned a Townsperson on a XML spawner.(Same result spawning with distro spawner)
3)Put on my staff cloak to set myself to player status and said hail, he turned was polite and then attacked me!! ACK!!! :eek:
(I have good karma)

So tried it without the staff cloak on my Owner, and he was polite, good response and didnt attack, but as soon as Im a player, I get attacked.
Used props and set him to "Good", same result.

I did see in the Townsperson script he is set to Closest for combat level.

Im an idiot here, what AM I doing wrong?

Thanks for any assistance in setting this up, it will be a super freature to have active!

Koluch
 

David

Moderate
Does the attack follow a specific spoken response or all of them? If you would, open up the Speech Rules Editor and make sure the NPC Reaction (bottom right corner) is not set to Attack. Also, are you by any chance criminal as a player (shouldn't matter I don't think, but asking just in case.) Finally, try asking the npc for his name or something--trigger a different rule and see what happens.
 

Lichbane

Wanderer
WOW! Does this apply to all townspeople or do you need to spawn specific ones? (Sorry ... I'm a bit of noob when it comes to this stuff).
 

Christos81

Wanderer
OK, this is just awsome. Thanks kindly for giving yet another way to make our worlds more lively. Every single script I check by you is amazing, keep it up and I will remain a fan of your work.
 

David

Moderate
Thanks for the encouragement guys, it means a lot!

Lichbane, all of the townspersons (of this type--it does not apply to generic npcs or escorts) will share the same speech database. You can use the region to alter the responses or if you want a response specific to just one or a few townspersons, you can use the townspersons name and/or the Tag property.
 

Lichbane

Wanderer
David;824663 said:
Lichbane, all of the townspersons (of this type--it does not apply to generic npcs or escorts) will share the same speech database. You can use the region to alter the responses or if you want a response specific to just one or a few townspersons, you can use the townspersons name and/or the Tag property.
So you can tailor the responses from a mage guildmaster, mage, alchemist, tailor, sailor, guard, etc? Hmmm ... all the possibilities. :)
 

David

Moderate
I was trying to merge Thilgon's post with his Italian version of the speech database from the previous thread, but experienced a fail of epic proportions. I did manage to salvage a copy of the file but this thread now seems to be disconnected somehow, at the very least it is not showing up in a search of my scripts. :eek:

Anyhow, here is Thilgon's Italian SpeechRules.xml.
 

Attachments

  • Italian SpeechRules.rar
    3.5 KB · Views: 21

LordHogFred

Knight
This is an awesome release.
I love the QuestObject integration, to further this would it be possible to add support for looking for XML Attachments? Would be able to rewrite all the ML quests using proper interactive NPCs that way :D.
 
Top