[Tutorial] [Basic Scripting] How to create a quest

Hello everyone,

This tutorial will walk you through creating a quest. We will be using the Modding Tutorial mod, but this will work for any mod.

If you haven’t already, I recommend you read first the tutorial “Architecture in Grim Dawn” here : https://forums.crateentertainment.com/t/tutorial-basic-scripting-architecture-in-grim-dawn/103229

I also recommend you read the “Grim Dawn Modding Guide.pdf” that is in your Grim Dawn folder, which will introduce you to the tools we will be using in this tutorial.

In order to create a quest, we will need to :

  • Create a npc and a conversation that triggers the beginning (and the end) of the quest

  • Create a .qst file using the Quest Editor tool

  • Create a .lua script file (your quest script)

  • Link all those files together properly

1. Creating the .qst file

The .qst file is your quest file, it is not the script of the quest but another type of file required by the mod, in which you will find all the details of the quest. Most of these informations will be also shown in the player’s UI and quest journal.

Open the QuestEditor, File -> New.

Group name : optional, all quests that have the same Group Name will be figured in the same section in the Quest Journal of the player. Usually Group name is the location/map where the quest is, but it can be anything you wish.

Quest name : the name of your quest as it will be figured in the Quest Journal of the player. Clic on that line and put the name of the quest in the text editor box below. Note that when you mouse over the Quest Name, a tooltip also give you the Quest ID. This number will be important when it comes to scripting, as it will be the mean we can point to that quest.

New Task : the task to be completed. You can add a new Task by double clicking on the Quest name line, but one task is enough for now. Again, each task is assigned a task ID that you can find by mousing over the Quest Task line. What you write here will be shown in the quest log in the right of the player UI.

Task Description : A more detailed description of the task, it will be shown in the Quest Journal of the player when the player clicks on the quest.

Now we need to give objectives to the quest. when those objectives will be done, the quest will automatically trigger the “on complete” actions (usually the quest’s rewards)

Double Clic “Objectives”, Add a condition “HasMoney” then >= 200. this objective will be marked as done once the player has 200+ bits in it’s inventory.

In the text Editor box, we add “Get 200 bits”.

Once the player has the money, they need to give it to Barnabas, so we add a second objective : double clic on “objectives” and then in the Text Editor, write “Give the money to Barnabas”. We put the condition “WaitForCompletion” : it will be completed via the conversation file, when we choose to give the money to Barnabas.

OnComplete : the actions that will be performed once the player has completed the quest. There can be several types of actions and rewards. For now, we’ll just give the player its money back : double clic on OnComplete to create a line, then on that line clic Action -> “GiveMoney” ->200

Now “Save As” -> Modding Tutorial -> source -> Quests -> MyFirstQuest
This will generate the source .qst file and now we need to add it to our mod’s assets : go to Asset Manager, Sources tab, then clic Quests, and on the right panel, right clic MyFirstQuest.qst and select “Auto-Create Asset”.

Now if we go into the Asset Tab of our Asset Manager, we will find MyfirstQuest.qst has been added to the Quests folder. The Mod never uses the Sources files, it uses the Assets files, so that’s why we need to always create the asset, based on the source files we have.

Then we clic “Build” so that the new .qst is added/recognized as an option in the ConversationEditor later on.

2. Creating the conversation that will begin and complete the quest

Now that we have .qst file with the details of the quest, we need to create a conversation that will point to that file, in order to tell when to begin the quest and when to end it.

Open the ConversationEditor, choose the Modding Tutorial. The mod you choose here will determine what functions/actions you can perform during the conversation. You can use “Grim Dawn” or “Modding tutorial” (as they include most actions needed by default).

Create New Conversation, then I recommend to name it after the name of the NPC. In our case, it’s Barnabas.

Double clic the Name line to add a new conversation line, this is what your npc will say when you clic on it. In the text editor, we add : “Hi, I got a quest for you! Are you interested?”

We then add two answers possible : Accept type with text “Yes!” and “decline” type with “Sorry no.”
(We don’t need to use Accept/Decline type, it’s just for visual clarity)

Now our Accept answer must start the quest. To do so, we select the Accept Line, and clic on Action, then select BeginQuestTask. In the quest line, we select our new Quest but be careful, we have two Quests folder : the base game one, and the mod one. The mod one, with our mod specific quests, is the second one. Select MyFirstQuest.qst

In the task line, select the task of the quest that will be started. In our case, it’s “[1] Give 200 bits to Barnabas”

Now, we also need the script part the quest. Scripts can perform specific actions, but they’re also required for every quest, in order to bestow the quest to all players in the game (the .qst file and the conversation don’t do it by themselves).

In your source\Scripts\game folder, open quests.lua
In order for the mod to load our new quest, we need to add this line :
Script.Load(“scripts/game/quests/myFirstQuest.lua”)

Note that for script and function names, we start with a lowercase letter (never a number in LUA).

Now we need to create myFirstQuest.lua

Go to source\Scripts\Game\Quests, copy/paste an existing quest. Rename it to myFirstQuest.

Open it, remove the previous quest lines and add :

gd.quests.myFirstQuest= {}

This script does not give the quest to the player, it is only in order to perform certain extra actions/events that the quest could trigger (which is not the case here). Save it and then in your Asset Manager, Auto-Create Asset for that script.

Now we need the game to give that quest to the player. For that, we edit two scripts that have already been done :

ModdingTutorial\source\Scripts\Game\questevents.lua
ModdingTutorial\source\Scripts\Game\Quests\ _MPQuestControl.lua

Open both files.

In questevents.lua, in the section “-- Global Quest Events for Bestowing Quests (no server check here or in the dispatch function)”, add the line :
myFirstQuestBeginQuest = gd.MPQuestControl.bestowMyFirstQuestGlobalMP,

Now in _MPQuestControl.lua, we must add the code that is going to add the quest to the player. This is where you will need the ID of both the Quest and the Task (you can find the ID in the QuestEditor) :

Now we have the scripts that will be used to give the quest. We can go back to our conversation and this time in the conversation line “Accept Yes!”, we add a new action -> Lua Script -> QuestGlobalEvent(event) then in the [event] line, we change the argument type to String and write “myFirstQuestBeginQuest” and clic Okay.

Now our conversation will give the quest thanks to GlobalQuestEvent() and use the ID of the .qst file for the details of the quest.

Now we need to add the conversation lines in order to give the money/complete the quest.

Go to ConversationEditor, double Clic the conversation name, and on the new conversation line, add a condition “OnQuest”, then select “myFirstQuest.qst” and “TRUE”. This means this conversation will pop up only if the player has the myFirstQuest.

In our new conversation line, we can now add two answers possible : Accept Give the 200 bits to Barnabas with a condtion “HasMoney” >= 200 and two Actions “CompleteQuest” with the myFirstQuest selected and “GiveToken” MyFirstQuest. The token is here to inform the game/npc that the player has already completed the quest, so the npc won’t start the dialog again.

Additionally we need to add two condtions on our previous conversation line (the one that gives the quest) : “OnQuest”, then select “myFirstQuest.qst” and “FALSE” and the condition “HasToken” MyFirst quest and “FALSE”. This means this conversation will only pop if the player does not have the quest, and has not already completed the quest (he does not have the token).

Save, then go to Asset Manager and in Sources\Conversations, auto-create asset for “npc_barnabas_01.dbr” and then Build

Congratulations! Our conversation is now set, with the proper scripts and .qst file !

Now we need to create the NPC Barnabas and link him to that conversation.

3. Creating a NPC

First we will add the npc to our world. Open the Editor -> Modding Tutorial -> Open an existing world and select TutorialWorld.wrl

OpenWorld

Go into Editor Mode, then in the right panel clic Records -> npc -> questnpcs -> npc_barnabas_01

Now clic on the map where you wish to add the npc. It should now look like this :

Now we must add our quest to the world. Go to Layout Mode -> Quest -> Add. In the Quests folder, find myfirstquest.qst and select, then Ok

Now Build -> Rebuild all Maps, then File -> Save All, and close the Editor.

Now in the Asset Manager, we are going to import the .dbr file for Baranabas, which contains all the variables to the NPC we just added. It is with that .dbr file that we will link the npc to the conversation we created earlier.

Go to Database (the one on the top of the window) then Import Record then select records\creatures\npcs\questnpcs\npc_barnabas_01.dbr and OK

Now the .dbt file has been added to the mod database, go to records\creatures\npcs\questnpcs and in the right panel, double clic on npc_barnabas_01.dbr

In the Conversation tab, Edit so that the variable points to the conversation file we just created. When choosing the file, be creful to use the second Conversations folder (the first conversation folder only contains conversations of the Grim Dawn base game, not your mods conversations).

Save and close, then build. And voilà! Congratulations!

Now launch the Modding tutorial mod map and check everything is working fine. If you got any issue/error, let me know below or by pm.

Have fun modding!

looks complicated but im sure i can follow it easily.

thanks for the info, imagine somebody making mod where every quest gives player bunch of EXP and Bits/Gold and scaling up

It seems complicated at first glance yeah, mostly because I have put everything/detailed every action, although it’s much better once you’ve done it a few times.

You can do a lot of things indeed.

yeah, basically with enough effort everyone can make Grim Dawn X Titan Quest, or even DLC-quality like mod (Nydiamar)

currently im learning about modding through tweaking Grimarillion and other mods i have.