Quest
Quest - module is a comprehensive system for managing quests in a game. It allows for the registration, tracking, and completion of quests, with various events and callbacks to handle quest-related activities.
Quest here is a set of tasks that player needs to complete the quest. Just trigger in a required place a function call like quest.event("collect", "coin") and all logic will be handled automatically.
Features
- Quest Management - Create, start, and complete quests with ease.
- Quest Progress - Track the progress of quests and their tasks.
- Quest Events - Listen for quest-related events and adjust it for your needs.
- Quest Configs - Flexible quest config system which allows to use quests in various ways.
Setup
See the Defold Quest repository on Github
Basic Usage
In Quest library, you have to create a config for quests and start quest system. After that you can trigger events for quests and subscribe to events to handle them for your needs.
local quest = require("quest.quest")
-- Fill the quests config and start quest system
quest.init({
["quest_01"] = {
autostart = true,
autofinish = true,
category = "quests",
tasks = { { action = "intro_completed" } },
},
["quest_02"] = {
autostart = true,
autofinish = true,
category = "quests",
required_quests = { "quest_01" },
tasks = { { action = "collect", object = "coin", required = 10 } },
},
["quest_03"] = {
autostart = true,
autofinish = true,
category = "quests",
required_quests = { "quest_02" },
tasks = {
{ action = "kill", object = "enemy", required = 5 },
{ action = "kill", object = "boss", required = 1 }
},
},
})
-- Throw events for active quests
quest.event("kill", "enemy")
quest.event("kill", "enemy", 2)
quest.event("collect", "coin", 3)
-- Subscribe to quest events to handle them for your needs
quest.on_quest_event:subscribe(function(event_data)
print("Type", event_data.type) -- "register"|"start"|"progress"|"task_completed"|"completed"
print("Quest ID", event_data.quest_id) -- Quest ID
print("Quest Config", event_data.quest_config) -- Quest Config table
print("Delta", event_data.delta) -- Progress delta (for "progress" type)
print("Total", event_data.total) -- Total progress (for "progress" type)
print("Task Index", event_data.task_index) -- Task index (for "progress" and "task_completed" types)
-- This is a queue and we have to handle event by returning true
-- If we don't return true, the event will be fired again
return true
end)
-- Check if any quest is active for specific action and object
local quests = quest.get_current_with_task("kill", "boss")
Read Use Cases for more examples.
Support project 
Your donation helps me stay engaged in creating valuable projects for Defold. If you appreciate what I’m doing, please consider supporting me!
