Full Version : How do I - Make talking npcs
xmlspawner >>XMLSpawner - How do I? >>How do I - Make talking npcs
<< Prev | Next >>
HellRazor- 02-15-2007
Thanks Arte!
One other question - is it possible to specify the color of text? For instance, if I wanted to highlight the key words in a conversation by coloring them red.
ArteGordon- 02-15-2007
I dont believe that you can hue individual words in the unicode text that is used for speech, so text that is displayed overhead (the Text field) would all be the hue specified by the speech Hue setting for the entry.
On the otherhand, gumps use html for their text so you can modify the hue and style of text displayed in gumps by using html tags. For example adding this to the Gump field
GUMP,test,0/this is <u><basefont color=#00ff00>underlined colored text</basefont></u> in the middle of a sentence
would display a gump with the specified text colored in green and underlined.
Erica- 04-11-2007

QUOTE (ArteGordon @ December 31, 2005 03:47 am)
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.
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.

Question since i got world spawned already using neruns file with your xml spawners how would i go about fixing all those npc spawners only to be set for them to talk words like osi..
ArteGordon- 04-12-2007
if you want to spawn vendors that have specific dialog attachment, you can change their spawner entries from something like
jeweler
to
jeweler/ATTACH/xmldialog,jewelerdialog
where you have your .npc file named jewelerdialog.npc placed into the default .npc folder (XmlQuestNPC)
You would have to edit the individual spawner entries to do this. To do it on a large scale you could also save your vendor spawners out to an xml file (for example using [xmlfind), and then do global string search/replace, and reload the xml file.
You could also edit the vendor scripts to automatically add the dialog attachments by adding something like this into their constructors
XmlAttach.AttachTo(this, new XmlDialog("jewelerdialog"));
You can take a look at the jeweler.npc file in xmlextras for some ideas.
Rocko- 04-24-2007
Is there anyway to make it so only the triggering player hear the talk?
ArteGordon- 04-25-2007

QUOTE (Rocko @ April 24, 2007 05:27 pm)
Is there anyway to make it so only the triggering player hear the talk?

you could have the npc whisper by setting the speechstyle property. It isnt strictly private but close

QUOTE
- added the SpeechStyle property to talking NPCs that allows you assign a MessageType to a speech entry like Regular (the default), Yell, Whisper, Emote.

Rocko- 04-25-2007

QUOTE (ArteGordon @ April 25, 2007 10:43 am)
you could have the npc whisper by setting the speechstyle property. It isnt strictly private but close.

Thanks Arte, that sounds a great addition.
I have another question, I know it is not in the current release, but just want some suggestions how I should go about do it, or find an alternative to solve the problem I am facing?
Is there anyway to allow a player to use a keyword to turn off the speech of a particular NPC to himself only? We have a starting area and as we add more talking NPCs with tutorials information, the screen soon gets very crowded when someone runs by. It would be nice if say player A decided to selectively hear only from certain NPCs by disable the speech from the rest, of course, just to player A. It wouldn't affect other players. If technically too much hassle, I can consider spead them out, though the starting area has always been the most visited place and easiest to broadcast any information.
Thanks again!
ArteGordon- 04-27-2007
good idea. There is not currently support for private overhead messages, but it would be an easy option to add to xmldialog entries.
That would restrict the display of overhead text to the triggering player. I'll get it into the next release.
Erica- 10-27-2007
i only can target the npc character and it works but was trying to see of targeting the spawner from those towns so it can speak if got 4 npc on spawners but that didnt work.
ArteGordon- 10-28-2007
you would either modify the spawner entry for each of them like this
tailor/ATTACH/xmldialog,npcfile
where you would have set up the npcfile earlier. You can do that by just editing an xmldialog on an npc using xmledit and then Saving it to File.
Or, if you wanted to script this into your npcs, just add something like this into their constructor
XmlAttach.AttachTo(this, new XmlDialog(npcfile));
where, again, you have already set up the npc file that you want to have used.
So making the following mod to Jeweler.cs will cause all jewelers to generate dialog according to the file jewelerdialog.npc. No change to their spawner entries is required for this. The next time the npc spawns, they will have dialog.

QUOTE
[Constructable] public Jeweler() : base("the jeweler") { SetSkill(SkillName.ItemID, 64.0, 100.0);
XmlAttach.AttachTo(this, new XmlDialog("jewelerdialog"));
}

and you would need to add this to the top of the script

CODE
using Server.Engines.XmlSpawner2;

Also note that even if you add it to their scripts, you can still spawn them with individual dialogs as I showed and the spawned dialog will replace the scripted one by default.
I would say that which method you choose depends on how widespread you want the change to be. If you want all npcs to have it, then it is easier to modify their scripts. If you just want a few, then it is easier to modify their spawn entries.
Erica- 10-28-2007
Ok i tryed it by short way with few npc on one spawner and put the cloak on to be regular player but nothing happen they didnt talk heres and image.
ArteGordon- 10-28-2007
did you create a .npc file named "npcfile"?
Use [xmledit on the npc and edit the entries as you like. Then when you are finished, enter the name of the .npc file into the "Save to File" dialog, and save it.
Erica- 10-28-2007

QUOTE (ArteGordon @ October 28, 2007 08:35 am)
did you create a .npc file named "npcfile"? Use [xmledit on the npc and edit the entries as you like. Then when you are finished, enter the name of the .npc file into the "Save to File" dialog, and save it.

Yes i saved when i open runuo folder theres a file there called npc file. Unless i have to put that file thats in runuo folder and make a folder in there called dialog so not sure whats wrong.
ArteGordon- 10-28-2007
what is the exact name of the file in the RunUO folder? Is it "npcfile.npc" or "npc file.npc"?
Having it in the main RunUO folder is fine. It will find it there. You can also put it into the XMLQuestNPC folder. It will find it in there too.
Erica- 10-28-2007

QUOTE (ArteGordon @ October 28, 2007 11:31 am)
what is the exact name of the file in the RunUO folder? Is it "npcfile.npc" or "npc file.npc"? Having it in the main RunUO folder is fine. It will find it there. You can also put it into the XMLQuestNPC folder. It will find it in there too.

Its npc file.npc so im not sure why isnt it working.