Full Version : How do I - Make talking npcs
xmlspawner >>XMLSpawner - How do I? >>How do I - Make talking npcs


<< Prev | Next >>

ArteGordon- 12-31-2005
Using XmlDialogs to create talking npcs

XmlDialog 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,npcfile

This 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,0

to 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,travelagent

or you can do it this way (you will often see examples that set up talking npcs like this)

xmlquestnpc/configfile/travelagent/loadconfig/true

This 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 dialog

To create your own dialog in an XmlDialog attachment, you would use the

[xmledit

command, 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.
user posted image

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.
user posted image

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.
user posted image

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.
user posted image

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

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.
user posted image

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).
user posted image

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.
user posted image

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!"
user posted image

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.
user posted image

user posted image

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.

Mage-Solitaire- 01-01-2006
Utiliser XmlDialogs pour créer des npcs parlant

XmlDialog est un attachement qui est utilisé pour ajouter des possibilités de dialogue interactifs à n'importe quel objet de type npc: talkingnpc, questnpc, etc utilisent ce systeme.

Pour spawner un objet avec un attachement de XmlDialog, vous pouvez employer le mot-clé ATTACH, comme ceci:
orc/ATTACH/xmldialog,npcfile

ceci créera un XmlDialog attachement en utilisant un constructeur qui prend le nom d'un dossier .npc comme argument, et l'attache à l'orc spawné.
Note, vous pouvez attacher XmlDialog à n'importe quel objet, pas seulement une créatures.


Qu'est-ce que les TalkingBaseCreatures, TalkingBaseVendors, et TalkingBaseEscortables?

Les mobiles "talking" sont comme les mobiles classiques, avec les avantages suivant:
1) elles ont l'option "talk" 'dans leurs menus contextuels qui permet le déclenchement des interactions en cliquant sur le npc et en choisissant l'option "talk".

En remplissant la valeur de "TalkText" sur le npc, ce texte sera traité par le npc de recherche comme si le joueur l'avait dit. Même si ceci est permis, la parole peut encore être employée pour lancer des interactions, de sorte qu'un joueur disant le même texte au lieu de choisir l'option de menu de contexte commence l'interaction de la même manière, ceci fournit juste une autre alternative à la parole.

2) elles soutiennent également l'affichage des effets visuels pouvant etre employés pour les identifier en tant que npcs interactifs. Les propriétés d'EItemID, d'EHue, d'EOffset, et d'EDuration définissent l'efet de l'objet, la couleur, l'emplacement de xyz, et la durée d'effet. Le réglage d'EItemID à zéro neutralisera ce dispositif.

Regardez l'exemple de questhighlight.xml dans les xmlextras pour voir divers variations aux npc.

3) ils vous permettent de charger des configurations de XmlDialog en configurant les propriétés de ConfigFile et de LoadConfig. Ceci est souvent employé comme alternative au mot-clé ATTACH lors du spawn (Cela ne fait en réalité aucune différence l'utilisation de l'un ou de l'autre).

4) ils vous permettent de configurer les valeurs d'attachement de XmlDialog en plaçant les mêmes valeurs directement sur la créature.
Il est peu probable que vous l'utilisiez, la méthode la plus simple etant de configurer XmlDialogs avec [xmledit command.


Qu'est-ce qu'un XmlQuestNpc?

Les XmlQuestNpcs sont des TalkingBaseCreatures a qui l'ont a donné forme humaine et peuvent donc etre directement spawné. Ils peuvent être construits avec une valeur de genre (1=female, 0=male) qui ressemblerait à ceci dans un spawn de xmlquestnpc
xmlquestnpc,0


Exemple de npc de parler:

Mettez le dossier de travelagent.npc dans un dossier appelée XmlQuestNPC dans votre dossier principale de RunUO. Vous pouvez la trouver incluse dans le paquet de xmlextras de xmlspawner2.

Créez ensuite un spawner et ajoutez ceci comme entrée

xmlquestnpc/ATTACH/xmldialog,travelagent

ou vous pouvez la faire de cette façon (vous verrez souvent les exemples qui installer des talkingnpc comme ceci)

xmlquestnpc/configfile/travelagent/loadconfig/true

cela fera exactement la même chose. C'est juste une autre manière d'obtenir le npc pour charger une configuration de XmlDialog à partir d'un fichier .npc.

Commencez alors à parler... (assurez-vous que vous êtes un joueur pour le faire sinon vous n'obtiendrez aucune réponse. Vous pouvez employer le StaffCloak pour commuter rapidement à l'accesslevel de joueur pour vos test).


Créer vos propres dialogues

Pour créer votre propre dialogue dans un attachement XmlDialog, vous pouvez employer

[xmledit

puis cibler n'importe quel objet qui a un attachement XmlDialog déjà dessus. Si l'objet n'a pas d'attachement XmlDialog, vous serez incités à en ajouter un neuf.

Rocko- 09-10-2006
I got a question, how do I use xmledit to make it so that keyword trigger dialog does not depends on other lines? that is, in this example, how do I make it so line 40 does not depends on line 30? I entered in the "Depend on" field a value of -1, but it didnt get triggered by my saying the keyword... any suggestion? Thanks.

ArteGordon- 09-13-2006
what is it that you are trying to do?

The way the dialog system works is that all entries are a part of a dialog tree. You can set the root of the tree with spontaneous banter entries that dont depend on anything except nearby movement (DependsOn = -1), but once you start the conversation, then you must follow the tree structure.

The tree structure is very flexible, so it does not have to branch in a specific pattern. I doubt that you have something that cannot be fit into such a tree.

If you want to have an entry that can be reached from more than one of the branches, just give it multiple DependsOn references

DependsOn = 20,30,40,etc.

Rocko- 09-13-2006
QUOTE (ArteGordon @ September 13, 2006 09:48 am)
what is it that you are trying to do?

The way the dialog system works is that all entries are a part of a dialog tree. You can set the root of the tree with spontaneous banter entries that dont depend on anything except nearby movement (DependsOn = -1), but once you start the conversation, then you must follow the tree structure.

The tree structure is very flexible, so it does not have to branch in a specific pattern. I doubt that you have something that cannot be fit into such a tree.

If you want to have an entry that can be reached from more than one of the branches, just give it multiple DependsOn references

DependsOn = 20,30,40,etc.

Sorry if I didn't explain clear enough. What I am trying to achieve is the target NPC will always respond to my keyword say "name" with "My name is GodFood, Sir, and how are you today?", regardless of other conditions. So it's a root, but instead of randomly triggered by a player in proximity, it is triggered only by a specific keyword.
Thank you!

ArteGordon- 09-13-2006
You should be able to accomplish this by adding another XmlDialog attachment that just responds to your keyword. It would behave like a separate independent dialog tree.
One problem with this is that [xmledit doesnt support multiple dialogs on a target, so you would have to create them separately, save them to .npc files, and then you could spawn an npc like

xmlquestnpc/ATTACH/<xmldialog,npcfile1/name/dialog1>/ATTACH/<xmldialog,npcfile2/name/dialog2>

where the names 'dialog1' and 'dialog2' give the two xmldialog attachments different names so that they can coexist on the same npc, and 'npcfile1' and 'npcfile2' are the names of the .npc files that were already prepared.

I havent actually tested this out, but it should work.

(edit)

I think that I may have read too much into your question.
If all you wanted to do was to have an npc respond to a keyword without any other entry having been activated before it, just set the DependsOn to zero and set the keyword to whatever you want.
When an XmlDialog is idle, then the default state is set to zero so that is what you can assign to DependsOn when you want it to depend on no prior state or player movement.

Rocko- 09-13-2006
The way you suggested works perfectly the way I wanted! Thanks Arte. xmlspawner/done2.gif

Rocko- 09-14-2006
QUOTE

I think that I may have read too much into your question.
If all you wanted to do was to have an npc respond to a keyword without any other entry having been activated before it, just set the DependsOn to zero and set the keyword to whatever you want.
When an XmlDialog is idle, then the default state is set to zero so that is what you can assign to DependsOn when you want it to depend on no prior state or player movement.

Yes that was what I wanted to do, sorry I must have stated the question pretty ambiguously. smile.gif
Now I got the DependsOn ZERO part, but another issue is it seems if I have all entries in one xmldialog, I will not be able to apply different reset timer do I? Say I want a dialog tree like the one you showed in this example to be triggered by player movement but will mute for 30sec before it can be triggered again, since i dont want the NPC to spam the screen when player keep moving around. Now if I add an entry that dependsOn Zero and triggered by a keyword, I wouldn't be able to have player trigger it at any time, because the 30sec is applied to all entries, am I understanding it correctly?
The way you suggested, attach two different xmldialogs, allow me to set different reset timer. Say a towncrier will yell "welcome to my town." every 30 secs given a player moves around; then he will reply "no news today" at any time if someone speaks "news". One inconvenience is I can not xmledit it if I have an NPC loaded with multiple xmldialogs. I have to load only one, edit it, save it, then repeat for the other. Then once I am happy, load all. Would be nice if I could apply different reset timer for different entries in the same xmldialog.

ArteGordon- 09-14-2006
The idea of having entry-specific reset times has come up before. It will probably be added at some point.

To set up what you describe, just set up your "welcome to my town" entry with DependsOn of -1, and then set up your "news" keyword entry to DependOn on the "welcome to my town" entry.

It will spam the welcome every 30 seconds, and if anyone says the keyword before it resets, then it will activate the news entry.

The only drawback to this is that it will take 30 seconds after getting news for the dialog to reset so that it will respond to the "news" keyword from someone else.

You could try something like this to get around that.

Entry 10: DependsOn = -1; Text="welcome to my town"
Entry 20: DependsOn = 10,30 ; Keyword = "news"; Text="whatever"; LockOn = false
Entry 30: DependsOn = 20 ; Keyword = "news"; Text = "whatever" ; LockOn = false


Having entries 20 and 30 depend on each other (circular branching) means that after getting news, the tree would always have a branch to another "news" entry, so you could activate it immediately without having to wait for it to reset. By unchecking the 'LockOn' box you allow the dialog to respond to anyone, not just the player that first activated it.

Rocko- 09-14-2006
QUOTE (ArteGordon @ September 14, 2006 06:12 pm)
Entry 10: DependsOn = -1; Text="welcome to my town"
Entry 20: DependsOn = 10,30 ; Keyword = "news"; Text="whatever"; LockOn = false
Entry 30: DependsOn = 20 ; Keyword = "news"; Text = "whatever" ; LockOn = false


The logic used here seems perfectly fine with me, though it takes some serious thinking to come up with something like this! smile.gif Kudos to the master.

Foruno- 02-08-2007
Spanish version of How do I - Make talking npcs here

riverman- 02-09-2007
Arte, i must admit im only up to page 38 in runuo forums, and i have searched here, with no success, can you help please.
this is the idee, a player walks up to a npc, and says hi, in responce the npc askes him if he want to enter the place, the player agrees and the npc says it will cost 1000 gold.
sequentiqal depending on the previous comment.

now up to that i got, but now i have to drag the gold onto the npc and it needs to respond by giving me a ticket (that will teleport me back here when i cant manage- like an escape) and activate the entrance teleporter.

could you advise pls, im a little stumped here.

ArteGordon- 02-09-2007
dragging and dropping onto an npc will only work if the player has a questholder and the item being dropped satisfies a GIVE quest objective.
In a dialog, you will need to TAKE the gold.

I suppose that during your dialog you could also just give them a questholder with a simple GIVE quest objective and your ticket as the reward.

HellRazor- 02-13-2007
I don't know if this is possible, but if not, perhaps a recommended feature.

Is it possible to have the NPC name all of the keywords that the player can use at that point in time?

This would be nice since a player can get lost in the tree, or forget the exact keywords.

Also, how long does it take an NPC to "reset" its dialouge back to its default state due to inactivity? And what if more than one player is conversing with the NPC at the same time?

ArteGordon- 02-13-2007
"Is it possible to have the NPC name all of the keywords that the player can use at that point in time?"

interesting idea. Many times you want the keywords to remain hidden, but perhaps adding an option for the designer to specify "hints" for an entry which could include a list of keywords.

"Also, how long does it take an NPC to "reset" its dialouge back to its default state due to inactivity? And what if more than one player is conversing with the NPC at the same time? "

The reset time is specified at the top of the [xmledit gump. By default it is 1 minute, but you can set it to whatever you like.
You can also manually force resetting
from xmlspawner2.txt
QUOTE

- a small change to the XmlDialog attachment that allows it to be reset by setting the DoReset property via an Action field in XmlDialog entries (thanks to Vladimir for the idea).  This allows the use of an action such as

SETONTHIS/doreset/true

to allow the xmldialog to become immediately available for reactivation without having to wait for it to timeout from the last player.


and by default, the first player to initiate dialog is the only one that the npc will respond to until it resets. This can be changed by toggling the LockConversation box for individual dialog entries. By clearing this setting for a dialog entry it allows anyone to trigger the entry.
QUOTE

- added the LockConversation property to to talking NPCs allowing you to specify whether a conversation with the NPC should be locked to the first player to interact with it (LockConversation=true) until the conversation resets, or whether you want it to be able to interact with anyone at any time (LockConversation=false). This also allows a new conversationalist to be established in mid-conversation when it is disabled in a single entry. This is true by default.