Using XmlDialogs to create talking npcsXmlDialog is an attachment that is used to add interactive dialog capabilities to any object including npcs. All of the talking npcs, quest npcs, etc. use this system.
To spawn an object with an XmlDialog attachment, you can use the ATTACH keyword like this:
orc/ATTACH/xmldialog,npcfileThis creates an XmlDialog attachment using a constructor that takes the name of a .npc file as an argument, and attaches it to the spawned orc.
Note, you can attach XmlDialogs to any object, not just creatures.
What are TalkingBaseCreatures, TalkingBaseVendors, and TalkingBaseEscortables?The Talking classes are like the regular classes with the following extra features:
1) They have support for the 'Talk' option in their context menus that allows initiation of interactions by clicking the npc and selecting the "Talk" option.
By Setting the
TalkText property on the npc, that text will be processed by the quest npc as though the player had spoken it. Even if this is enabled, speech can still be used to initiate interactions, so that a player saying the same text instead of selecting the context menu option will start the interaction in the same way, this just provides another alternative to speech.
2) They also support the display of overhead effects that can be used to identify them as interactive npcs.
The
EItemID,
EHue,
EOffset, and
EDuration properties define the effect item, hue, xyz offset, and effect duration. Setting
EItemID to zero will disable this feature.
Look at the questhighlight.xml example in xmlextras to see various npc highlighting schemes.
3) They allow you to load up XmlDialog configurations by setting the
ConfigFile and
LoadConfig properties. This is often used as an alternative to using the ATTACH keyword when spawning (it doesnt make any actual difference).
4) They allow you to configure XmlDialog attachment properties by setting the same properties directly on the creature.
It is unlikely that you would ever need to do this, since the preferred method of configuring XmlDialogs is with the [xmledit command.
What is an XmlQuestNpc?XmlQuestNpcs are just TalkingBaseCreatures that are given human form and can be directly spawned.
They can be constructed with a gender argument (1=female, 0=male) which would look like this in a spawn entry
xmlquestnpc,0to spawn a male npc.
Talking npc example:Put the travelagent.npc file in a folder named XmlQuestNPC in your main RunUO folder. You can find it included in the xmlextras package of xmlspawner2.
Then create a spawner and add this as a spawn entry
xmlquestnpc/ATTACH/xmldialog,travelagentor you can do it this way (you will often see examples that set up talking npcs like this)
xmlquestnpc/configfile/travelagent/loadconfig/trueThis will do exactly the same thing. It is just another way of getting the npc to load up an XmlDialog configuration from a .npc file.
Then start talking... (make sure you are a player when doing this otherwise you will not get any response. You can use the StaffCloak to quickly switch to player accesslevel for testing).
Creating your own dialogTo create your own dialog in an XmlDialog attachment, you would use the
[xmleditcommand, and target any object that has an XmlDialog attachment already on it.
If the object does not have an XmlDialog attachment, you will be prompted to add a new one.
Once you have added the XmlDialog, you can add and edit the dialog entries.
To add a new entry, press the Add button in the [xmledit gump.
To enter in the text that you want the npc to speak edit the Text field.

To configure the entry to be activated by nearby player movement alone, set the DependsOn field to -1. This means that the entry doesnt "depend on" any other entry having been just activated.

To set the amount of time that has to pass before the npc dialog can be activated again, set the ResetTime field. In this example it is configured for 30 seconds.

To save the configuration to a file that can be loaded back onto that npc or any other npc, enter in the name of the .npc file and press the Save button.

To test the dialog configuration, change your AccessLevel to player (I use the staff cloak for this purpose), and move close to the npc.

To add a second dialog entry that can also be movement activated, open up the [xmledit gump again using the [xmledit command and targeting the orc, and press the Add button.

Then enter in another phrase into the Text field and set the DependsOn field to -1. Now when a player comes in range, the entry activated will be randomly selected from these two possible entries and the orc will say one of these phrases every 30 seconds while there are players within the specified proximity range (3 tiles).

To link together multiple dialog entries so that they follow one after another, set the DependsOn field to the entry ID that you want to precede it.
For example, adding another entry that "depends on" entry 20, will cause that entry to be activated after entry 20. The delay between activating the entries can be specified in the PrePause field in seconds. The default PrePause value of -1 will automatically calculate the delay based upon the length of the text.

So now when the orc says "Who dares enter my domain?", it will be followed by "Ah, it is but a puny human. Die human!"

To add an entry that will only be activated if the player says a keyword, add another entry with the Add button, set the Text that you want to be said, and enter in a list of keywords into the Keyword field. If any of the keywords in the list is spoken, the entry will be activated. In this case the DependsOn field is also set to 30 which means that the entry will only be activated if one of the keywords is spoken after entry 30 is activated.


To save all of these edits back to an .npc file, enter in the npc filename such as OrcThreat, and press the Save button again. The configuration can then be loaded onto any npc at a later time using the approaches described at the beginning of this document.