Skip to main content

Create A Quest

Creating the Quest

Let's create a quest. In the res://quests/ folder, go ahead and create a new .gd script. You can do this by right-clicking the folder in Godot and clicking New Script. The script file name should be the quest ID, for this tutorial you can name it tutorialStart.gd. You can ignore the other options in the 'Create Script' pop-up as we will be erasing everything in the script.

Open the tutorialStart.gd script file. Erase everything and replace it with:

extends Quest


func _init():
pass

This is how we initialize a Quest. Note, you should see an error saying Unkonwn class: "Quest", this is because you do not have access to the Queen's Brothel source files.

We are going to assign the Quest variables in the _init() function. I recommend opening the Quest in another tab so that you can better understand what we are doing.

I like to assign the id and dialogueID first. These will be the same, and should match your script file name.

extends Quest

func _init():
id = "tutorialStart"
dialogueID = "tutorialStart"

Now, we are going to set the quest's name. The name of your quest is important because if you want to create one long quest, you should use the same name across all your quest files. Logically, quests are just single use scripts, but we create the illusion of sub-quests by assign the same name to multiple files.

    name = "Tutorial Quest"

Set a description for your quest.

    description = "The start of the tutorial quest."

Now, we are going to set the mapKey for the quest. The mapKey is the location of our quest. You can find a list of Map Keys to use here. Let's use a key from Easthollow, just to keep things simple.

    mapKey = "MayorsOffice"

There is a variable called location. This variable is dynamic and does not need to be anything in particular, but for best practice make sure to name it something that will help the player. For the town of Easthollow, I like to use "Easthollow Town".

    location = "Easthollow Town"

And finally, we have a variable called parent which lets you define what quest ID needs to be completed before you can start this one.

I want this quest to be available at the start, so I'm going to use "newGame". You can find a list of quest IDs here.

    parent = "newGame"

This should be your final tutorialStart.gd script file.

extends Quest


func _init():
id = "tutorialStart"
dialogueID = "tutorialStart"
name = "Tutorial Quest"
description = "The start of the tutorial quest."
mapKey = "MayorsOffice"
location = "Easthollow Town"
parent = "newGame"

Now, we need to let the game know that we have created a new quest. Open the res://mods/{Mod ID}/init.gd file, where {Mod ID} will be the name of your mod, if you have changed it.

In the _ready() function, at the bottom let's add a line of code:

    QB.quest.addQuest(load("res://quests/tutorialStart.gd").new())

This line of code calls the addQuest function from the QuestManager. This will put the quest into the game because the game only looks for quests that are in the manager. The load() function is a Godot function. We are loading the script file and then creating a new object from that file. You don't have to learn what this means, just know that this is how you load objects in Godot.

Creating the Dialogue

We have created a quest that starts at the Mayor's office, but now we need to create the dialogue for that quest. Create a new script file called tutorialStart.gd in the res://dialogue/ folder. Make sure there are no typos, your file name should match the dialogueID you set above.

Go ahead and erase everything in the script file and replace it with:

extends Dialogue


func _init().("tutorialStart"):
setBackground("res://assets/Maps/Town/MayorsOfficeBackground.png")
talk("", "This is the start of my quest!")
completeQuest("tutorialStart")

This tutorial is not about creating dialogue, so we're going to keep it simple. A more in-depth tutorial can be found here.

Our dialogue will display a quick message and then our quest is over.

Create the Ending

Using the information above, you should be able to create your own ending to this quest.

  1. Create a new quest with the ID: tutorialEnd
  2. Keep the same name variable as tutorialStart
  3. Set the mapKey to "TownSquare"
  4. Set the parent to "tutorialStart"
  5. Create the dialogue file for this quest
    1. Change the dialogue ID parameter to "tutorialEnd"
    2. Try using the "res://assets/Maps/Town/TownBackground.png" background for this dialogue
    3. Make sure to change the completeQuest parameter to "tutorialEnd"

Because we set the parent to "tutorialStart", your tutorialEnd quest will only appear after you have completed the tutorialStart quest.

If you have successfully created the files, they should look like this:

# res://quests/tutorialEnd.gd
extends Quest


func _init():
id = "tutorialEnd"
dialogueID = "tutorialEnd"
name = "Tutorial Quest"
description = "The end of the tutorial quest."
mapKey = "TownSquare"
location = "Easthollow Town"
parent = "tutorialStart"
# res://dialogue/tutorialEnd.gd
extends Dialogue


func _init().("tutorialEnd"):
setBackground("res://assets/Maps/Town/TownBackground.png")
talk("", "This is the end of my quest!")
completeQuest("tutorialEnd")

Congrats! You're done! Go and export your mod and try it out!

Rewards

Let's add a reward for the player when they complete our tutorialEnd quest. At the bottom of the res://quests/tutorialEnd.gd file let's add a line of code that will give the player some gold when they finish the quest.

   addGoldReward(100)

and to top it off, let's give Queen some experience points, because she is the best girl after all!

   addExpReward("Queen", 200)

If you have done this correctly, your file should now look like this:

# res://quests/tutorialEnd.gd
extends Quest


func _init():
id = "tutorialEnd"
dialogueID = "tutorialEnd"
name = "Tutorial Quest"
description = "The end of the tutorial quest."
mapKey = "TownSquare"
location = "Easthollow Town"
parent = "tutorialStart"
addGoldReward(100)
addExpReward("Queen", 200)

When the player completes the quest, they will be rewarded with 100 gold and 200 experience points for Queen.