...and something extraEdit
In this tutorial, we will create a talking NPC from scratch. And we will add some extra features: he will not only talk, but test the player's abilities.
Start the Art Manager. From the menu, select 'Mod - New'. Under 'New Mod Name', enter 'TalkingNPC'
Next, click the 'database' tab. The folder TalkingNPC/database will be displayed in the left-hand pane. Right-click it, and in the context menu choose 'Create Directory...'. Set the name of the new directory to 'TalkingNPCStuff'.
Now we have a mod and a custom folder in its database to put things in. Time to
Import from the DatabaseEdit
From the menu, select 'Mod - Import record'. In the window that comes up, navigate the file structure to records/dialog/greece. Select 'athens_guard_a.dbr' and click 'import'. (This is a dialog record. You could, in fact, use any of the dialog files.)
The database in our left-hand pane will have collapsed, so expand it again to records/dialog/greece. As you see, the dialog file has been imported to the same location it sat in the original game's database. We will now move it to our custom folder.
Right-click the dialog file, and choose 'copy' from the context menu. Then click on our 'TalkingNPCStuff' folder to select it. Right-click into the right-hand pane, and choose 'paste' from the context menu. We will need two dialog files, so repeat the pasting action. By right-clicking the two dialog files, you can rename them. Set their names to 'dialog_before.dbr' and 'dialog_after.dbr'
Now we need somebody to speak those dialogs.
Do 'Mod - Import record' again. This time, navigate to records/creature/NPC/greece/athens and import 'walking_male_001.dbr'. This is a creature record of the NPC type. As before, navigate the database to the imported file, copy it, and paste it twice into our 'TalkingNPCStuff' folder. Rename the two copies to 'teacher_before.dbr' and 'teacher_after.dbr', respectively.
Wiring up the dialogEdit
We will now add the dialogs to the NPCs. This will be easier if we build our database first. Therefore, right-click 'TalkingNPC/database' and choose 'build' from the context menu.
Select 'teacher_before.dbr' and double-click it. The properties of the file will open for editing. Click on 'NPC Static Dialog'. There is a single variable in this category, called 'dialogPak'. Here we must enter a reference to our dialog file. The value of the variable (shown in the right-hand field beside the name) is currently empty. Double-click the empty field. A button with an ellipsis (...) will appear. Click that button, and a window will pop up from which to choose the file we want. Thanks to our building the database, our 'TalkingNPCStuff' folder and its contents are available here. Select 'dialog_before.dbr' to be 'teacher_before.dbr's dialog.
While we are at it, we might as well give our NPC a name. Click on 'Actor Variables'. The topmost variable is called 'description'. This variable is a tag. Double-click the right-hand field and enter 'TeacherNameTag'. This is of course not the real name of the NPC. We will add that in a moment. Save and close the properties window.
Now do the same for 'teacher_after.dbr'. Of course, the dialog must be set to 'dialog_after.dbr'. Use the same name tag, though. In fact, both NPCs will be the same person, when we are done.
Changing the dialogEdit
Now we will edit the dialogs.
Open 'dialog_before.dbr' for editing. Click on 'Default Dialog'. Edit 'defaultDialogTextTag' to 'dialog_before_line1'. Click on 'Additional Dialog', edit 'dialogTextTag1' to 'dialog_before_line2'. There is an entry in the second variable, a sound file to be read. We don't need this, so delete it.
Open 'dialog_after.dbr' for editing. You will not be surprised that you should set 'defaultDialogTextTag' to 'dialog_after_line1' and 'dialogTextTag1' to 'dialog_after_line2'. In this case, we will be needing a third line of dialog. Click on 'Irritation Dialog' and set 'irritationDialogTextTag' to 'dialog_after_line3'. Delete the sound file here, also.
This might be a good time to build your database, again.
Filling those Tags with meaningEdit
Now we will give all those tags we entered into the database records their meaning.
That is done by editing the 'modstrings.txt' file.
Click on the 'sources' tab, expand 'TalkingNPC/Source', and click 'Text'.
You'll find the modstring.txt file in the right-hand pane. Double-click it. This will open the file in your text editor. It is currently empty.
Add the following 6 lines (each in one line, no newlines):
TeacherNameTag=Headmaster of the Academy
dialog_before_line1=So you think you are ready to leave our school, young Padawan? I'd like to test your prowess first.
dialog_after_line1=Indeed, you have done well. I gladly release you.
dialog_after_line2=You have graduated from the Academy with honor.
dialog_after_line3=What are you waiting for? Adventure awaits!
Then save the file.
We need to create an asset for the modstring.txt file. Right-click it, select 'Auto-create asset' from the context menu, and click OK in the window that pops up. This must be done once only. Later, the Art Manager will update the asset when it buids the mod.
A little bit of storylineEdit
At this point, teacher_after.dbr is a fully functional talking NPC. You could put him onto a map, he would display a lozenge above his head and say the lines of his dialog. But as you may have guessed from the dialog lines, we will now have the Headmaster test the player, his pupil.
He will do that (in his 'before' incarnation) by summoning a monster. The monster will be himself, armed and ready to fight, and he will summon it in his stead. After the monster is killed, he himself will reappear (in his 'after' incarnation) and graduate the player.
The next thing we need, therefore, is a monster.
Go to 'Database - Import record' and navigate to records/creatures/monster/skeleton. We will choose a skeleton because they are essentially human and we will not have to worry about the animations.
Import 'am_soldier_05.dbr' into the database. This file is a creature record of the monster type. Copy and paste it into our TalkingNPCStuff folder, as you did before with the dialogs and NPCs. Rename it to 'summoned.dbr'
To make the monster look like the Headmaster, we will now edit it. Double-click the file and click 'Actor Variables'.
Obviously, the 'description' should be 'TeacherNameTag'.
The physical form of the monster is set in the 'mesh' variable. Edit it to the headmaster's mesh, (creatures/npc/maletownnpc01.msh). A texture will not be needed, delete the entry in 'baseTexture'.
The skeleton we used is a little largish. We have to set 'scale' back to 1.0
Now, click on 'Character'. You'll find, under 'characterRacialProfile', that our monster is currently classified as undead. Delete that entry.
Finally, we have to concern ourselves with the 'Death Parameters'
We can't have the monster lying around when the NPC Headmaster reappears. Therefore, edit the monster's 'deleteBehavior'. From the drop down list in the right field, select 'delete' The monster will now disappear immediately after being killed.
Now find the variable 'actorToSpawnOnDeath'. Here is an easy way to make the NPC reappear without having to write a quest. Just enter 'TalkingNPCStuff/teacher_after.dbr' here and the thing is done.
A scripted sceneEdit
The summoning of the monster is not so easily done. We need to write a quest for that.
We will need a questlocation in our quest. Prior to writing the quest, import 'testquestlocation01.dbr' from records/quest/questlocations, paste it into our custom folder and rename to location.dbr. You know how to do that by now. Build the database.
Start the quest editor. When it is done loading, choose 'File - Select mod' from the menu and specify our mod. Wait again for the program to load the database. Thereafter, you can expand the database in the right-hand pane to show the contents of our TalkingNPCStuff folder.
Then, open a new quest file. Call it NPCMonsterChange.
Add two quest steps to your file, add a trigger to each.
To the first trigger, add as condition 'On interact with X'. Click on the new condition, its properties will be displayed in the pane below. You must specify 'teacher_before.dbr' as the NPC database record. The ellipsis button works a little different in the Quest Editor. You have to select the record first. Highlight the teacher_before file in the right-hand pane by clicking it. Then doubleclick below to bring up the ellipsis button. When you click the button, the highlighted file will be copied. Mark that the Condition now says 'On interact with teacher_before'
Add as Action to this trigger 'NPC X play animation X and don't allow interruptions'. Set the NPC to teacher_before, as above, and the animation to AttackIdle (from a drop down list).
The second trigger gets 'Animation completed' as its condition. Mark that there is no X in this condition. Nevertheless, you must select teacher_before as the NPC whose animation ends.
The actions of the second trigger are 'Hide X', where you set X to teacher_before (of course), and 'Spawn X at X'. The entity to be spawned is of course our summoned.dbr, and the location our location.dbr.
What does this quest file do? If you click on teacher_before, he starts displaying his dialog. To prevent him from being hidden at once, the hide and summon actions are delayed by playing the animation. Else the monster would be speaking the first line already. When the animation is done, or when you click the NPC a second time, the NPC will be hidden and replaced by the monster.
The quest is done. Save it. Be careful to save it into the correct directory, namely <your working directory>/CustomMaps/TalkingNPC/Source/Quests.
Close the Quest editor.
Finally, we must create an asset for our quest file. In the Art Manager, click the source tab. Expand TalkingNPC/source to find the quest file in the quests folder. Right-click and auto-create asset as you did with the modstring.txt file earlier.
Putting it all togetherEdit
We are nearly done. Just a few clicks in the World Editor are missing.
Open the editor. Select our mod. Expand the source directory and select 'Maps'. Enter 'TestMap' as file name and click OK. The editor opens in layout mode. Select 'Region - Add new terrain' from the menu and enter TestLevel as the file name. Click on the new level to highlight it and go to editing mode by clicking the button with the two red arrows.
Add just three things to your world: A spawnplayer, a 'teacher_before' from our custom folder, and a 'location' at exactly the same spot as the teacher.
Return to layout mode. Rebuild the pathing ( 'Build - Rebuild all pathing') of your level so that the character will be able to move.
Finally, we must add the quest to our map. Choose 'Quest - Select files...' from the menu. Click 'Add'. Expand resources/quests and pick 'NPCMonsterChange.qst' from the file list. Click 'OK' twice.
Now you can save all and quit the editor.
Open the Art Manager. You must create an asset for the new TestMap.wrl file. It is found in source/maps.
Finally, you can build the mod by pressing F7.
Test the mod in the game. If everything went right, the Headmaster should involve you in a sparring fight when you click him.