Roblox Guide Help

Quests Module


This module aims to handle the creation and advancement of quests for players in your game.

This module does not directly handle your quests, meaning that you will have to use the methods created to add a quest to a player, update the player's advancement in the quest, and more.

Installation

In your wally.toml file, add this to your dependencies:

[dependencies] quests-module = "release/quests-module@0.0.7"

Import

You have two solutions to import this module, depending if you wish to import the Controller or the Service on your own, or if you let the module give you the right code.

local QuestsModule = require(ReplicatedStorage.Packages["quests-module"])
local QuestsController = Knit.GetController("QuestsController") local QuestsService = Knit.GetService("QuestsService")

Configuration

A file called QuestsModule.config.lua is to be created in the folder ReplicatedStorage/Shared/Configs.

return table.freeze({ ["MaxQuestsPerUser"] = 4, ["Quests"] = { ["10 Clicks"] = { ["Type"] = "Clicks", ["Goal"] = 10, ["Reward"] = { ["Type"] = "Economy", ["Economy"] = "Money1", ["Amount"] = 1000, }, }, }, })

Explanation:

  • MaxQuestsPerUser: The maximum amount of quests a player can have at a time.

  • Quests: The list of all quests available.

    • 10 Clicks: The internal name used to refer to your quest. Can be anything as long as it is unique.

      • Type: The type of quests that your quest fit in. This is used later in the IncreaseCount method.

      • Goal: The goal of your quest. Here, the goal is to reach 10 clicks, so put 10.

      • Reward: You can put whatever you want here, this is sent to all services when a player reaches the goal of a quest so you can handle this the way you like.

Usage

Client Side

This method allows you to listen to an event sent by the QuestsService and run a callback function whenever an event is received.

List of events:

  • OnQuestAdded: Called when a quest is added to a player. Sends the quest progress as a parameter.

  • OnQuestRemoved: Called when a quest is removed from a player. Sends the quest name as a parameter.

  • OnQuestFinished: Called when a player finishes a quest. Sends the name of the quest to the client, and the quest config to the server.

Usage

QuestsModule:RegisterEvents(name, callback)

Explanation

  • name: The name of the event you wish to listen to.

  • callback: The callback function that will be run whenever this event is received.


QuestsModule:RegisterEvents("OnQuestRemoved", function(name) print("The quest named " .. name .. " was removed from the player.") end)

    Server Side

    This method allows you to add a quest to a player. This quest will then be counted as "Started" and will be updated with the IncreaseCount method.

    Usage

    QuestsModule:AddQuest(player, name)

    Explanation

    • player: The player to whom to add the quest.

    • name: The internal name of the quest to add to the player.


    QuestsModule:AddQuest(player, "10 Clicks")

      This method allows updating the progress of a type of quest for a player.

      Usage

      QuestsModule:IncreaseCount(player, type, count)

      Explanation

      • player: The player who needs his quests to be updated.

      • type: The type of quests that needs an update.

      • count: The value to add to the progress.


      QuestsModule:IncreaseCount(player, "Clicks", 1) -- Adds 1 to the progress of all quests with type "Clicks"

        This method allows you to remove a quest from a player.

        Usage

        QuestsModule:RemoveQuest(player, name)

        Explanation

        • player: The player to whom the quest is removed.

        • name: The name of the quest to remove from the player.


        QuestsModule:RemoveQuest(player, "10 Clicks")

          This method allows you to retrieve the lists of all quests of a player

          Usage

          QuestsModule:GetQuests(player)

            This method allows you to retrieve the lists of all quests of a player

            Usage

            QuestsModule:GetQuest(player, name)

            Explanation

            • player: The player who has the quest.

            • name: The name of the quest to get.


            QuestsModule:GetQuest(player, "10 Clicks")
              Last modified: 25 November 2024