[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:
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.
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.