Originally found at: Morrowind
*Scripting/Dialogue Tutorial v1.0 Readme*
This file along with others can be found at - http://www.angelfire.com/rpg2/mwmods
*** WARNING ***
I do NOT claim this to be the best/only/ultimate way of doing ANY of this. If you know of a better or different way of doing any of this then by all means use it. In fact, if it's better or faster or more efficent than what I show here, let me know about it!
*** WARNING DONE ***
To view the end result of this tutorial:
Extract the files into your x:\Morrowind\Data Files directory and launch Morrowind. Select Data Files from the launcher window and double click the tutorial.esp file. Click OK and then select Play. Talk to the NPC just outside Seyda Neen named Bob the Bully. Follow the bridges out of town and you'll find him.
Files are here.
First I would like to give credit to Kaenash from the official Morrowind forums. I read his/her (sorry, don't know which is correct, no offense intended.) post on his ideas on how to teach everyone to mod. This tutorial encounter we'll create was his idea, I'm just implementing it for everyones benefit.
Now that that is out of the way, time for my shameless plug for my own mod...
If you haven't already seen it or downloaded it you can get it here - http://www.angelfire.com/rpg2/mwmods/companion.zip
The mod allows you to take an NPC warrior with you on your travels.
Ok, enough of all this. Stop reading this readme and get to reading the tutorial! That is unless you're curious what all is included in this zip.
Zip file includes:
Tutorial.esp file. - This is the finished product. All the script, dialogue and other changes are completed here so you can see how it works in the game.
Readme file. - That's this file obviously.
Tutorial.txt - The tutorial itself.
Not realy a bugs, just some things I didn't do. For instance if you tell Jim you don't want to escort him over to Bob then the next time you talk to Jim you'll get another 50 gold just like you did when you brought him the note the first time. This also happens after Jim has killed Bob. You can still talk to Jim and get the 50 gold. It's easily fixable with a few more lines of dialogue. I just didn't do it since this is only a demonstration.
The note you get from Bob to give to Jim also makes no sound when you recieve it from Bob or when you give it to Jim. To remedy that just add -
PlaySound, "book open"
To the script jimScript between set state to 850 and Player->RemoveItem. This gives it sound when you get the note from Bob. I'll leave it to you to discover how to give it sound when you give it to Jim.
Creating the First NPC
Creating the Second NPC + More Dialogue
Let's start with a little explanation of exactly what we're going for in this tutorial. What we're going to try to do is create 2 NPC's and a small quest to go along with them. The first NPC is Bob the Bully, who isn't very fond of our second NPC Jim. Here's what should happen when we're done and we run the quest. The player talks to Bob who gives the player a task. The task is to take a note Bob gives you to Jim. When the player finds Jim and gives him the note, Jim decides he'd like to share a few words of his own with Bob and wants the player to take him to Bob. Once Jim sees Bob they attack one another ending with poor Bob's death. Don't worry, Bob wasn't such a great guy anyway. After Jim does Bob in the player gets a reward from Jim for leading him to Bob. I'll try to be as detailed as possible through out this tutorial, but if anything should be unlcear, just send me an email. So, let's get started shall we?
Load up the editor and when it's all set click on File/Data Files. Since we don't yet have a mod to work with, just double click the Morrowind.esm file and click OK. Wait until the editor is finished loading the file and then go to your Cell View window which is on the lower right. This window has 2 selection boxes in it. We need the one on the left which lists all the areas in the game. We'll make our mod in Seyda Neen since it's the beginning area and it'll be easy to test.
In the left hand selection box of the Cell View window, scroll down until you find the Seyda Neen listings. There's a lot listed, and you could load them up individually until you find the one you want, but we'll just use the Seyda Neen that is at Grid -2, -9. Double click that listing and wait a few moments while the editor loads the area.
Now you should have a top down view of Seyda Neen in your render window. Click the render window to make it the active window. It might be a good idea to resize it a little larger than it is now. Once it's sized to your satisfaction, click one of the buildings or NPCs near the center of town and press C.
The C key centers you on the object as you've probably noticed. And if it was a building you picked you've probably got a nice close view of a thatch roof. Since that's not very helpful, press and hold V and move your mouse down. That will zoom you out. Moving the mouse up zooms you in. Once you have a better view, click on one of the NPCs closer to the center of town. I chose Vodunius Nuccius. Once you have one selected, press C again to center on him. Zoom out again to get a better view of town. Holding down the Shift key and moving the mouse left or right spins your view. Holding the space bar and moving your mouse up or down raises and lowers your view, while moving your mouse left or right slides your view.
Once you have a nice view of the center of town, pick out a spot where you'd like to put Bob. Once you know where you want to put him, go to the Object window on the left side of your screen and click on the NPC tab. Just so we cover as much as we can, we'll create a new NPC. Right click in the Object window and select new. This brings up the NPC interface where you can change skills, inventory, AI, dialogue and just about anything else you can imagine.
First things first. Up at the top you'll see a space that says ID next to it. This is the name that the engine uses to filter dialouge options along with other uses. Name your new NPC something unique. It can be anything you want, it's not the actual name of the NPC it's just used by the engine to reference this NPC type.
Alright, I named my new NPC npc_bob just in case you want to follow along exactly. Next comes the field with Name next to it. This is the actual name you'll see in the game when you target this NPC. I named him Bob the Bully.
Next field is the script field. We'll come back to that later on. The field after that is the race field. You can choose any race you'd like. I picked Breton. The class can also be anything you'd like. I used commoner although you could use a "real" class such as mage or warrior. Faction and rank can also be set here although we have no real need for them.
Click the OK button and you'll have a new NPC all set to be put into the world. To get him into the world though, you have to find him on the list of NPCs. Click on the list of NPCs in the Object window and type the first few letters of the name you put in the ID field. Presto! The editor goes to your new NPC, or at least close to it. So now that you've found him in the list we need to get him into the actual world. To do that, click and drag his name and move it over the render window and release.
Ok, so he doesn't look too impressive with no clothes and no hair. We'll get to that in a minute. The more pressing problem is that he may be floating in the air unless you happened to be zoomed in close to the ground when you dragged him into the render window. To fix that simply press the F key. The F key causes the selected object to fall to the top level of the object below it, in this case the ground. Once he's there you can click on him and hold the mouse button while moving your mouse to position him where you want him to be. If he's facing the wrong way, hold the right mouse button and move the mouse left or right to spin him.
Now that he's positioned let's get the poor guy some clothes. In the Object window, select the tab at the top that says Clothing. Double click on your NPC to bring up the NPC interface again. Now in order to give him any item, but in our case clothes, you find what you want in the Object window list and just drag it's name over to his inventory box. The inventory box is on the right side of the NPC interface just above the save and cancel buttons. Ok, back to the clothes. Since my Bob NPC is a commoner I scroll down to the
common section of the list and find him a common belt, shirt, pants and shoes which I drag into his inventory box. You'll notice that as you add wearable items such as clothes the NPC will equip them when you press the save button. If you equip something and later decide to remove it, just select it and press the delete key. You can play dress up with your NPC until you're satisfied with his look and then we'll get on to changing his face and hair.
While you're in the NPC interface you might want to click the AI button and delete the listing in the box. This keeps the NPC in one place instead of wandering around. You can always replace it later, but for testing it's much easier if you don't have to look all over for you NPC.
To change your NPCs physical looks just take a look at the top right hand corner of the NPC interface and you'll notice 2 boxes, one on top of the other with a listing of files. At the end of each file you'll note it says head in the top box and hair in the bottom. To change your NPCs face and hair, just select any combination of the 2 and click save to see how he looks. Once you're happy with that you can go ahead and create your second NPC you'll need for this tutorial. Remember what the second NPCs name is you use in the ID field, but don't place him in the world yet.
If you don't already have the NPC interface open for your first NPC, find him and double click on him to bring it up. In the lower left corner you'll see a button with Dialogue on it. Click that and give the editor a couple seconds to load it all up.
When it loads what you'll be seeing is the games dialogue filtered for your NPC. That means that out of all the possible dialogue options in the game, your NPC can only talk about what is listed. To make our own dialogue we'll need to do a few things.
First, in the lower left corner there's a selection box labeled "Filter for" that should have your NPCs ID name in it. Click that box, scroll to the top, and select the blank entry. Now what you're seeing on the left hand side is the dialogue keywords the game uses. The keywords are the blue words you see in the text when you talk to an NPC in the game. So in order for us to give Bob something to talk about that will be helpful to us we have to give him a couple keywords and a greeting.
If you already know what you want your NPC to talk about and you already know the keywords you'll be using you can create those first. But to make things easier we'll do the greeting first. At the very top left corner of the Dialogue window you'll see some tabs. Select the Greetings tab. When you select that, and if you don't have a filter selected, you should get a list with Greetings 0 - Greetings 9. We'll put our greeting dialogue in the Greetings 1 section. You can actually put it in any of them, but the developers have things neatly sorted and I see no reason to change it.
Select the Greetings 1 option and then in the Info/Response window select the top listing and right click, then select new. You can either enter your text directly on the new line, or click on the box below the Info/Response box and type your greeting in there. Here's what I wrote -
Greetings friend. Would you care to help me with a task?
Standard stuff I know, but it'll do as an example. Once you're finished writing your greeting dialogue find the field labled ID. Click the ID selection box and type the first few letters of your NPCs ID name, or just scroll down to it. What this does is filter this greetings so that only NPCs with the ID you chose (npc_bob in my case) can give this greeting. If you were to go back to your NPC list and drag npc_bob off the list again and place him in the world with a name other than Bob the Bully, you'd have 2 NPCs with the same ID so each could use this greeting but no other NPC could because the computer only looks for the ID when filtering, not the name you gave the NPC.
That's it for setting up the greeting. There are other filters you can use but we only really need the ID field for now. We'll get to the result box at the bottom and the Function/Variable boxes later. Now pick out a word in your greeting that you'll use as a keyword to get more information about what Bob wants. I chose the word task. Once you have a word selected, go back up to the upper left corner and click the Topic tab again. Right click anywhere on the list and type in the keyword you want to use and press enter. This part is similar to the greetings part. You now have to enter the text you want the player to see when he clicks on the keyword in your greetings dialogue. For example, my keyword was task. I right click in the topic list, enter task and then right click and select new in the Info/Respone box at the top and enter -
Yes, a task. Are you up to it or not?
Again, filter this response to your NPC by selecting his ID in the ID selection box. For this part of the tutorial I ask that you make your keyword dialogue a question like mine. We're now going to see how you give the player options in the dialogues.
In the Result box you will type in the responses you want the player to have to the NPCs question. My responses are "Sure, I'm up for it." and "No way buddy.". In order to make these responses into a choice for the player you type into the result box at the bottom -
choice "Sure, I'm up for it." 1 "No way buddy." 2
Don't forget the " " or the numbers. The numbers are for the engine to know which choice was made, they wont show in the dialogue. Before we go any further you can save your plugin and test it out to make sure that the dialogue works properly and that your NPC is in the right spot. To save, just click the OK button on the dialogue, click the save button on the NPC interface if it's still open, then click File and Save. Name your plugin and run Morrowind. At the Morrowind Launcher screen, select Data Files and double click on the name of your mod to enable it. Click play and test out your mod. Now, because we haven't finished the dialogue yet you wont actually be able to finish the conversation with him. In fact you'll be in a loop and wont be able to say goodbye to the NPC. This isn't exactly a bug so don't worry about it. Just hit escape and exit out of Morrowind.
Once you're sure the NPC is where you wanted him to be and the dialogue works up to the part where you get a choice to help or not load the editor back up. This time when you select File and then Data Files you can just double click your plugin and click the set as active file button. This loads the main Morrowind.esm and your plugin all at once and sets your plugin as the file to work with.
Either select your NPCs name from the NPC tab list or select the Seyda Neen cell from the Cell View window and find your NPCs name in the Cell View object list. Either way, double click on the NPCs name. Once the NPC interface opens, click on the dialogue button again. When the dialogue window opens it should be filtered to your NPC. Find your dialogue keyword in the list on the left and select it. Now we're back to where we were before we tested our plugin. Now we need to give the NPC some answers to use. One answer for each choice you gave him. I gave him 2 choices, therefore I'll need 2 answers.
To give him the response to the "Sure, I'm up for it." choice, select the dialogue you have in the Info/Response box and right click. Select new. Give your NPC a response to the player accepting the quest. Mine goes like this -
"Good. Very good. Take this letter to Jim. He can be found by the cave behind the siltstrider platform."
That gives all the information the player needs to begin this quest, although if it were a complex and involved quest you could also have further keywords here. They would be added the same way we added the greeting keyword. We'll get to adding the letter to the players inventory in a moment, right now add a response also for what the NPC says if the player refuses the quest. Again right clicking in the Info/Response box and typing in a reply. Here's mine -
"Can't handle a simple task huh? I should've known."
It's important that these responses be ABOVE the reply with the choices. Because of the way the game looks for dialogue options if they're below the first response you had you'll never see them. Now that you have both responses make sure you filter them for your NPC in the ID selection box. Now, how does the game know which response to use for which selection? Well, that's where the Function/Variable box comes in.
Find your NPCs reply to the player accepting the quest and in the Function/Variable box select Function, in the second box select choice and in the third box type in 1. Do the same for the player refusing the quest, but in the third box put a 2. Now, when you talk to this NPC and accept his quest he will reply with the response you set to 1 and will respond with the alternate if you refuse the quest.
Now that you have both the accept and refuse dialogues complete we have to add Bobs letter to the players inventory when the player accepts the quest. Now, we could use a scroll that is already premade, and for the most part we will, but just to show you how to edit text on a scroll we'll make one that Bob can give the player.
In the Object window, click on the Books tab and scroll down the list until you get to the sc_ items. We could use just about any item in the game for this, but I figured a scroll would be good so you'll get to see how to edit the text on it. Double click on any of the sc_ items, it doesn't really matter which one. First thing we need to do is give it a new name. I'll call mine "Bob's Note to Jim". Change the ID field to something similar to what you named your NPC. My scroll ID is sc_npcbob. Down at the bottom where it says Enchanting, click on the box and scroll to the top and select the blank entry. You could have this note magical and it would be treated like a spell scroll, but that's not needed for our quest. The weight and value can be left as they are. Now, to change the text on the scroll, just edit it the Book Text window to suit your needs. One thing to notice though, if you picked a spell scroll, is that inside the <> style brackets is the font color, font size and font face that will be on the scroll if you read it in the game. The face on most, if not all spell scrolls is Daedric. I myself don't read Daedric so to change that to a nicer looking font and one that's readable you can change Daedric to Magic Cards.
After you get your scroll text edited click the save button. The editor will ask you if you want to create a new item. Click yes.
Now that our custom scroll is made we need to find a way to give it to the player when they accept the quest. This is easily done. Go back to the dialoge window either through the NPC interface as before, or by clicking the word baloon icon at the top of the editor. Make sure the dialogue window is filtered for your NPCs ID and click on your keyword. Once you're back at your keyword find the reply that you used when the player takes the quest. At the very bottom of your reply there's a box labled Result. This is a handy little box that allows you to do a number of things. One of them is using script. As long as the script is no longer than 1 line long, in other words no "if" statements, you can put it here. In order to give the player the scroll you just made, enter this in the result box -
Player->AddItem, "sc_npcbob" 1
Make sure you get the capitol letters correct and the " " and the comma. What this little bit of script does is:
Player-> - Tells the computer who gets what's coming.
AddItem - Just what it says, adds an item.
"sc_npcbob" - This is the item that the previous command is to create. Your scroll may be named something else, if so use that.
1 - The number of items to create with the AddItem command.
Now, when you save your plugin and run it if you talk to your NPC you'll get the 2 options you entered in your keyword dialogue. Accept, or refuse. If you refuse the quest he'll reply with his dialogue for that choice, but if you accept you'll be notified that a scroll has been added to your inventory. At this point we should also make accepting the quest give you a journal entry. Having a journal entry isn't required, but I'm trying to cover as much as I can. To make a journal entry, go to the dialogue window and click the right arrow up by the Topics tab until you come to the journal tab. Once you get to it, right click on the list that's on the left hand side and select new. I named my entry Tutorial_001, but again name it what you wish. Enter some text describing the quest. Who gave it, and what you're supposed to do is always a good idea, but put what you want. If you look where the filter boxes are you'll notice a box called Index. Put any number you want in there, we'll need it later so remember it.
For the most part this is the same as creating the first NPC. Create one, place him outside of town and get him clothed. Once he's in place, open up the dialogue window and create a new greeting. This greeting is a standard one he'll give you if you haven't started the quest yet. I used a standard "Hello. How may I help you?" greeting for this one. When you're done entering your standard greeting set the filter to him. Now we'll create the greeting he'll use if you have the letter. For this one I have the NPC say "Hello %PCName, I see you have something for me.". If you're curious the %PCName is used to put the players name into the dialogue. There's a list of % defines in the help files if you want more. Anyway, after you have the greeting that you'll use after the player has the quest you'll want to give the player a choice to either give him the letter, or not give him the letter. This isn't totally needed, you could just force the player to give him the letter when they talk to the NPC but I like to give the player options. In the result box I typed -
choice "Give him the letter." 1 "Hide the letter." 2
Same as before. You'll need to make a few more dialogues if you use this, but I think it's better to give the player a choice in how they want to continue. Before we get to making those other dialogues for the choices, head up to the Function/Variables box again. This time set the first box to Function, the box to it's right to state and the last box enter a number. Any number will do, but it should be a unique one. I used 850. This is another sort of filter option. The player will only see this greeting if the NPC is in "state" 850. I'll show you how we put the NPC in that state in a minute. First let's finish up the dialogue options we just created.
Click to the Topics tab and make sure the Filter for box in the lower left is empty. Now, create a new keyword. Make sure the keyword is in the greeting you just created, the one you changed the Function/Variable on. My greeting was "Hello %PCName, I see you have something for me.", so I used the word "something" for my keyword. Once you have your new keyword made, you'll want to make a response for the keyword.
All together you'll need 3 new responses, the keyword response, the one where you give the player the choice to give the letter up or not, a "Yes" response and a "No" response.
Be sure to set both responses Function/Variable boxes to the same number as your greeting otherwise they wont be seen. You'll also have to set one of the Function/Variable boxes to Function and the box next to it to Choice. The last box should be set to 1 for one reply and 2 for the other, just like before.
Hope that wasn't too confusing, if it was just let me know. On with the tutorial...
Now that you have all 3 responses, find the response you'll use when the player gives you the letter. Select that response and at the bottom in the Result box enter this -
Player->RemoveItem, "sc_npcbob" 1
Player->AddItem, "Gold_001" 50
The first part works just the opposite of the AddItem command, instead of adding an item, it removes it. Simple enough. If you named your scroll something other than sc_npcbob use that instead, but keep the quotes there.
The second part gives the player 50 gold for his troubles. Doesn't help our mod any, but I thought I'd add it anyway.
If everything went well, and my tutorial wasn't too confusing you should have your dialogue all set up for the quest up to the point where you give the scroll to the second NPC. To actually get him to take it you'll need some scripting which is where we'll go next.
Alright, now the fun part. Now we actually get to change the way the game behaves. The first script we'll be doing will be for the second NPC which will allow him to take the scroll from the player.
Click on the pencil icon at the top of the editor, this will open the script editor. Once you're in the editor, select Script then new. You'll now be looking at a blank script. I'll give you the script here first and then explain what it does.
if ( MenuMode == 1 )
if ( GetJournalIndex Tutorial_001 >= 10 )
if ( Player->GetItemCount, "sc_npcbob" == 1 )
set state to 850
Player->RemoveItem, "sc_npcbob" 1
Ok, first line -
Begin - Starts the script
jimScript - The name of the script. Can be anything you want.
Second line -
short state - Keeps track of the local state variable.
Third line -
if (MenuMode == 1 ) - Best to put that in every script. If the menus are up, do return nothing.
endif - Ends the statement.
Fourth line -
if (GetJournalIndex Tutorial_001 >= 10 ) - Checks to see if the player has this entry in
endif their journal. Does nothing really in this
script but it can be used to activate a quest NPC.
Fifth line -
if ( Player->GetItemCount, "sc_npcbob == 1) - Checks to make sure the player has the note.
set state to 850 If yes, then it puts Jim NPC at state 850 so
Player->RemoveItem, "sc_npcbob" 1 you can get to the dialogue about the letter.
return Player->RemoveItem removes the letter when
endif the NPC is talked to.
Sixth line -
End - Ends the script.
Now that you've got the script written, save it and find your newest NPC you created and open up his NPC interface. Up at the top on the left you'll see a field called Script. Pull down the menu and find the script you just wrote. Click the save button and go try out your plugin to make sure everything works right. If all goes well this is what you should get so far...
If you talk to the second NPC first you should get some sort of standard greeting.
If you talk to the first NPC first you should get the option to deliver a note for him. If you click no, that's the end of the topic. If you click yes you should get the letter and a journal update if you added that part.
Once you have the note and you talk to the second NPC you should get a new greeting with a keyword in it. If you click the keyword you should get the option to give him the note, or keep it yourself. If you give him the note it should be removed from your inventory and you should be compensated 50 gold by the NPC.
In order to get the second NPC (Jim) to follow you to the first NPC (Bob) we'll have to do a bit more dialogue editing and some more scripting. We'll do the dialogue editing first sice it's the most involved.
Open the dialogue editor and filter it for your second NPC, Jim in my case. Find your keyword that brings up the option to give him the letter. Select your dialogue that you use to give the letter to him. Now, if you don't already have it, put the name Bob (or whatever you named your first NPC) somewhere in that dialogue text. Now, unfilter your Topics list so you can make a new keyword. Make the new keyword Bob, or again whatever you named your first NPC.
Select the keyword and type something to the effect of "Bob!? That no good lousy trouble maker? Where is he? Will you take me to him?". Now in the result box at the bottom we're going to add 2 choices again. One we lead him to poor Bob, and the other we leave him standing where he is. Type in the result box -
choice "Lead Jim to Bob." 1 "Don't lead Jim to Bob." 2
Or something similar.
Now, just like before, make 2 more dialogues in the Bob keyword. 1 for each choice. Say whatever you like in them, but when you're done set your Functions/Variables box in your dialogues to Local, next one over to state and the last to 850. This is so we'll be able to see them as dialogues when the NPC is switched over to state 850 when the quest is activated.
In your "Lead Jim to Bob" dialogue, set the Functions/Variable boxes to Function, then choice and finally 1, this is in addition to having one of the other Function/Variable sets read Local, state, 850. At the bottom in the Result box add -
We don't have that script yet, but we'll create it as soon as we're finished with the other
Do the same for the "Don't Lead Jim to Bob." dialogue, except that instead of 1 in the last box you'll use 2 and don't add the StartScript in the Result box.
Alright, now onto the follow script. We need this so that when you tell Jim you'll take him to Bob he'll follow you over there. Here's the script -
if ( GetCurrentAIPackage != 3 )
set followNow to 1
AiFollow Player 0 0 0 0 0
if ( GetDistance npc_bob <= 200 )
set followNow to 0
if ( GetTarget npc_bob == 1 )
if ( GetHealth <= 0 )
set followNow to 0
AiWander 280 6 0 40 30 20 0 0 0
The first if statement just says that if the NPC is using any AI type other than follow, to put him in follow mode and track the player. The second if statment is pretty obvious. If npc_bob gets withing 200 units of Jim, Jim stops follwing me and attacks Bob. The last statement just says that if Jims target is Bob, he should check Bobs health. If Bobs health drops to 0 or below then Jim should stop following me, stop combat and start his wander AI.
Now, since I want Jim to win I'll edit Bobs health and give Jim a weapon. Just open the NPC interface for Bob and adjust his stats. Just uncheck the auto-calc skill stats box and they're all editable. As for Jims weapon, just find one in the editor and drag it into his inventory box, just like you did with clothing.
Now, to give ourselves a reward for killing poor Bob, we'll make a script to give us a ring when Bob dies. You could either have it just pop into your inventory or you can have it on Bobs body when he dies. The script for the instant ring in your inventory when Bob dies is -
if ( OnDeath == 1 )
Player->AddItem, "ring_keley" 1
PlaySound, "mysticism cast"
MessageBox, "You've recieved a magic ring!
To have the ring spawn on Bobs corpse just remove the Player-> part of the script along with the messagebox text.. Open Bobs NPC interface and attach the script to him in the script box and you'll get a ring one of two ways when you get Jim to kill Bob.
By going back and adding more dialogue to Jim you could also have him thank the player for their help and give them the reward.
That's about it for this tutorial. There's still a few tweaks/fixes you could apply to it if you're ambitious, but this should get your started. If anyone has any problems, questions etc just send me an email. The address is in the readme file.
Good luck all!