Author Topic: Simple quest and dialogue in Hammerwatch 2  (Read 3899 times)

Hipshot

  • Developer
  • Posts: 455
  • Level Designer
    • View Profile
Simple quest and dialogue in Hammerwatch 2
« on: August 18, 2022, 04:16:42 PM »
The dialogue system can be very advanced and call on various features and systems in the game, it's almost impossible to give examples of everything one can do with it, it's one of those things where you just have to experiment and see if you can do "just that".
But at least a basic dialogue and quest is simple to set up and manage, this text will explain how you do that.

(The phrase called mymod, this should be replaced with the name of the mod or something else to make it easier to identify the mod later on.)

To start with you need to create an NPC to talk to, one that can give you the quest and where you will hand it in for a reward.
In the extracted resources, go into the folder, actors/npcs/quest and copy the file named npc_halvard.unit into your modfolder and change the filename to "npc_michael.unit'.
Open the new npc and find where it says:
Code: [Select]
%defblock Dialog
<f>0</f><s></s>
<f>6</f><s>tweak/quests/dialog_world.sval:npc_halvard</s>
<f>22</f><s></s>
%endblock

%defblock Schedule
<f>0</f><s>tavern_upstairs</s>
<f>6</f><s>halvard_idle</s>
<f>22</f><s>tavern_upstairs</s>
%endblock
Change it so it looks like this:
Code: [Select]
%defblock Dialog
<f>0</f><s>mymod_dialog.sval:npc_michael</s>
%endblock

%defblock Schedule
<f>0</f><s>michael_idle</s>
%endblock
This changes so the dialogue Michael uses are directed to a file in your modfolder and that he will be able to talk to you all hours of the day instead of just from 06 to 22 and he won't go to sleep either, he will just stand in one place whatever happens around him, you can also change where it says NPCNAME from Halvard to Michael to make it simpler to detect the npc in the game when debugging if needed.

Now you have an npc you can place in a mod level, you will have to restart the editor to see this new unit.
You will notice that when you walk up to Michael, you can't interact with him or anything like that. It's because he's missing his dialogue.

Let's add a dialogue and at the same time, add a quest to that.
We need another file to do this, a .mas file that will handle all dialogue and quests for NPCs in your mod. In the extracted resources, go into the folder tweak/quests and copy the file called world.mas into your mod folder.
Rename the file to mymod.mas. this file should contain all dialogue and quests for your mod, you can make more file if you feel it's easier or include like we have done in the base game, but in most cases you should be fine with only one file as in this example. Open the file.

To make it easier upon yourself, erase everything inside it and paste the following:
Code: [Select]
%include "scripts/Quests/GenerationHelper.inc"
%include "tweak/quests/experience_levels.inc"
void Execute()
{
//DONT CHANGE BELOW HERE
GenerateFiles("mymod_world.sval", "mymod_dialog.sval");
}

Now you have a clean basic structure where you can add dialogue trees and quests.

Let's give Michael a dialogue that will give you a quest that you can complete.
In the .mas file, copy what's below, either the entire thing or just what's missing from the clean one you just made.
Code: [Select]
%include "scripts/Quests/GenerationHelper.inc"
%include "tweak/quests/experience_levels.inc"
void Execute()
{

CreateDialog("npc_michael", "Michael Douglas");

AddQuestPrompt("quest-michaelsquest");
SetText("Hi, I'm looking for a few carrots, can you help me find these?");
SetActiveText("Did you ever find any carrots?");
SetFinishedText("Great, nom nom!");
SetAfterText("I just love carrots. I hope these lasts long!");

CreateQuest("quest-michaelsquest", "The Carrot Lover", "I love carrots, I can eat them all day if I had enough. You know, if you can bring me a hefty load, I will give you these rare boots? How about it?");
AddMissionCollectItem("carrot", 15, true);
AddRewardEquipment("feet", "epic", "expert");
AddRewardExperience(500);


//DONT CHANGE BELOW HERE
GenerateFiles("mymod_world.sval", "mymod_dialog.sval");
}

If we break down what we see here a bit. The first line, where it says CreateDialog is what defines a dialogue for an npc here we also have the name that will be displayed on the speech bubble, more or less the name of the NPC how it's shown to players in the game. After we have that defined, we can give the npc various different types of dialogue types like, TimedPrompt, DetailPrompt, QueryPrompt etc, but now we will use the QuestPrompt.

This is a break down of the quest prompt, the most basic usage of it:

AddQuestPrompt -> This must be the corrent ID of the quest you want attached to this dialogue.
SetText -> This is the speech bubble dialogue of the npc, the one that will lure the player to take the quest.
SetActiveText -> This is the speech bubble dialogue displayed while the quest is active (not finished).
SetFinishedText -> Short speech bubble text shown when you complete the quest, usually something like "thanks".
SetAfterText -> When the quest is complete, the npc will say this.

Then after that we will add the quest itself, the one that will show up in the quest log and give us a reward when we complete it, in this case, find 15 carrots and hand them to Michael. A quest can have a plethora of variables, too many to list now, this is just a simple quest so.

CreateQuest -> The first segment is the quest ID, this is the one you call from the QuestPrompt, then you have the quest name and last the quest description, these two are displayed when you push the button for more info and can also be seen in the quest log later on.
AddMissionCollectItem -> This one defines what item to find and how many of them, the true value is set if you also want to have these items removed from your inventory, in 99% of the cases you want this.
AddRewardEquipment -> These are the boots that you get as reward when you complete the quest.
AddRewardExperience -> And this is how much experience you gain.

If you want to make another npc with another quest, duplicate this entire text and rename the CreateDialog to something else, like npc_karen or so and then play around with different quest requirements, like change the carrot to apple or dirt, you can also give money as reward or take money from the player when he completes the quest.

MuffinH8er

  • Posts: 1
  • Maggot Crusher.
    • View Profile
Re: Simple quest and dialogue in Hammerwatch 2
« Reply #1 on: August 19, 2022, 02:45:40 AM »
You've put a lot of flexibility in the dialog system. I look forward to what you will do with it. Plenty of different states for the NPC's and I'm interested on how complex you can get the quest. I look forward to seeing the integration in-game and how they play with the editor worldscripts.

Hipshot

  • Developer
  • Posts: 455
  • Level Designer
    • View Profile
Re: Simple quest and dialogue in Hammerwatch 2
« Reply #2 on: August 19, 2022, 08:36:26 PM »
It's easy to connect dialogue with the world, both from just brining up the speech bubble and when you accept something, for example from these:


AddRewardGlobalEvent(string event); -> Calls out an event as a quest reward or from a querryPrompt button.
AddStartGlobalEvent(string event); -> When you start a quest.
AddEffectGlobalEvent(const strin &in event) -> When you just bring up a speech bubble, whatevertype.

Then in the world you just use a GlobalEventTrigger to check if the condition is true, you can also do other things like check flags etc.