SimpleDialogue - A Dialogue Module

SimpleDialogue - A Dialogue Module by CrabDevs

SimpleDialogue, is a module made to simplifying making NPC dialogues for your game. With an easy to implement system, using a tree structure to configure the dialogues.

You can easily create branching conversations, both simple and complex dialogues.

[Github Repo]

Read the documentation here:
SimpleDialogue wiki (Click me)

Get the module here:
Roblox library (Click me)

Examples

Simple Quest Dialogue

local npc = path.to.npc

local dialogue = SimpleDialogue.new(npc)

local dialogueTree = SimpleDialogue.CreateTree({
	SimpleDialogue.CreateNode("Hello, traveller!", {
		SimpleDialogue.CreateOption("Hey! Can you tell me about the quest?", function()
			dialogue:ShowNPCText("Yes of course!", function()
				task.wait(2)
				dialogue:DisplayNode(2)
			end)
		end, 0),
		SimpleDialogue.CreateOption("Bye!", function()
			dialogue:ShowNPCText("Goodbye!")
		end)
	}),
	SimpleDialogue.CreateNode("Please find me 2 cows..", {
		SimpleDialogue.CreateOption("I'll do it!", function()
			print("Quest started..")
		end),
		SimpleDialogue.CreateOption("No, thanks!", function()
			dialogue:ShowNPCText("Okay, goodbye!")
		end)
	}),
})

dialogue:SetDialogueTree(dialogueTree)

Conditional Dialogue

local npc = path.to.npc

local dialogue = SimpleDialogue.new(npc)

local questStarted = false
local hasQuestNotStarted = function()
	return not questStarted
end

local hasQuestStarted = function()
	return questStarted
end

local itemFound = false

local dialogueTree = SimpleDialogue.CreateTree({
	SimpleDialogue.CreateNode("Hello, traveller!", {
		SimpleDialogue.CreateCondition(
			hasQuestNotStarted,
			SimpleDialogue.CreateOption("Do you have a quest for me?", function()
				questStarted = true
				PlayerGui.ScreenGui.QuestLabel.Text = "Quest Started: true"
				PlayerGui.ScreenGui.ItemLabel.Visible = true
				dialogue:ShowNPCText("Yes I do!", function()
					task.wait(2)
					dialogue:ShowNPCText("Find the brick item!", function()
						task.wait(2)
						dialogue:EndDialogue()
					end)
				end)
			end, 0)
		),
		SimpleDialogue.CreateCondition(
			hasQuestStarted,
			SimpleDialogue.CreateOption("Finish Quest!", function()
				if itemFound then
					itemFound = false
					questStarted = false
					PlayerGui.ScreenGui.QuestLabel.Text = "Quest Started: false"
					PlayerGui.ScreenGui.ItemLabel.Visible = false
					PlayerGui.ScreenGui.ItemLabel.Text = "Item Found: false"
					dialogue:ShowNPCText("Thanks! Goodbye!")
				else
					dialogue:ShowNPCText("You didn't give me an item!")
				end
			end)
		),
		SimpleDialogue.CreateOption("Bye!", function()
			dialogue:ShowNPCText("Goodbye!")
		end)
	})
})

dialogue:SetDialogueTree(dialogueTree)

workspace.BrickItem.ProximityPrompt.Triggered:Connect(function()
	if questStarted then
		itemFound = true
		PlayerGui.ScreenGui.ItemLabel.Text = "Item Found: true"
	end
end)

To get started with using SimpleDialogue visit: Getting Started - Installation

Feel free to come with feedback, and/or support me with a coffee → Buy me a coffee (Click me)

27 Likes

Version 0.1.6
After a little time, fixed the different configurations such as Rojo and Wally, so now you should easily be able to add this project to your own.

Or you can download the rbxm file from → Release 0.1.6 · Crabzzai/SimpleDialogue · GitHub

Feel free to come with feedback or wishes for features.

hey, this is awesome, tysm. One bug that i ran into is that it affects all prox prompts in game. If you have a nearby prompt which is shown, then you activate a different nearby prompt, it will disable the first prompt.

1 Like

I will look into that! It should of course only affect prompts which are related to the NPCs of the dialogue system.

awesome! One other thing i ran into is the :SetOnInteract doesn’t work, the self.currentNPC is nil at the time that the callback is set, so it doesn’t set it.

1 Like

Hey is there a way to make it so the response dialogue is a 2d screen effect.

1 Like

clicked on this and thought it was an @athar_adv resource, the brainrot is real

1 Like

Ah, thank you! That will be fixed as well, pushing the fixes now.

Version 0.1.7

  • Fixed so it only disable/enable proximity prompts which are a part of the system.
  • Fixed so :SetOnInteract will actually be set and run.

Download the rbxm file from → Release 0.1.7 · Crabzzai/SimpleDialogue · GitHub

So the UI is in the PlayerGui instead of a ScreenGui?

1 Like

Thanks a ton. Everything works perfectly. I really appreciate it, i was just about to build something like this for a game, but you saved me a ton of time!

1 Like

Thank you! Feel free to share the game with me when it’s released! Would love to see.

Pretty nice module, looking forward to the updates

1 Like

Version 0.1.8

  • Added support for 2D dialogues (Enable this by using the useScreenGui in the configuration, currently experimental, feel free to come with feedback)

Download the rbxm file from → Release 0.1.8 · Crabzzai/SimpleDialogue · GitHub

Feel free to try out version 0.1.8, and feel free to give feedback on the new added 2D dialogue.

1 Like

Good work, i will use this module with my future games!! thanks for the module, you should make donation for anyone who wants to support you!

1 Like

Thank you! I will take that into consideration.

Version 0.2.0

  • Added support for conditions.
local beenHereBefore = false

local dialogueTree = SimpleDialogue.CreateTree({
    -- First node (index 1)
    SimpleDialogue.CreateNode("Welcome to our village! First time visiting?", {
        SimpleDialogue.CreateOption("Yes, it's my first time", nil, 2),
        -- This is a dynamic condition, as soon as `beenHereBefore` changes value to true, this option will be shown.
        SimpleDialogue.CreateCondition(
            function()
                return beenHereBefore
            end,
            SimpleDialogue.CreateOption("No, I've been here before", nil, 3)
        ),
        SimpleDialogue.CreateOption("Goodbye", nil, -1)
    }),
    
    -- Second node (index 2)
    -- A static condition, this condition is determined when it's defined, and will not change.
    SimpleDialogue.CreateCondition(
        1 == 1,
        SimpleDialogue.CreateNode("Welcome to our village! First time visiting?", {
            SimpleDialogue.CreateOption("Yes, it's my first time", nil, 2),
            SimpleDialogue.CreateOption("No, I've been here before", nil, 3),
            SimpleDialogue.CreateOption("Goodbye", nil, -1)
        })
    ),

    -- Third node (index 3)
    SimpleDialogue.CreateCondition(
        function()
            return beenHereBefore
        end,
        SimpleDialogue.CreateAutoNode("Have a good day then!", function()
            task.wait(5)
            dialogue:EndDialogue()
        end, false),
        function()
            print("This will run, if the node failed to open.")
        end
    ),
})

Download the rbxm file from → Release 0.2.0 · Crabzzai/SimpleDialogue · GitHub
Feel free to come with feedback, and/or support me with a coffee → Buy me a coffee

Hey quick question. In my game i want to have multiple (50+ npcs) to have dialoguse but i dont want to put a script in each of them but rather have a module that takes the texts/options from a table and creates the dialogues automatically. i havent quite found what works for me yet

nevermind this, i tested around a abit and i found a solution for handling all npc dialoguse in 1 module.

--[Modules]--
local SimpleDialogue = require(yourPath.To.SimpleDialogue)

--[Variables]--

local DialogueHandler = {}

DialogueHandler.Nodes = {
	["WeaponNPC"] = { -- the Name of the NPC
		Options = {
			Node1 = { -- make sure each option is ordered the way you want it
				{Text = "Yes please!", NodeSwitch = 2},  
				{Text = "No thank you.", NodeSwitch = 3}, 
				{Text = "Goodbye", NodeSwitch = -1}, -- -1 ends the dialogue
			}
		},
		Nodes = { -- make sure each node matches to the nodeSwitches in the options
			{Text = "Do you wish to change your weapon?", AutoNode = false}, -- this is always the start text (NodeSwitch = 1)
			{Text = "Please, take a look!", AutoNode = true, 
				Function = function()
					print("Player has opened shop!")
				end
			}, -- NodeSwitch = 2
			{Text = "Have a good day then!", AutoNode = true} -- NodeSwitch = 3
		}
	},

}
function DialogueHandler:Init()
	for i, npc in pairs(Services.CollectionService:GetTagged("Talkable")) do -- just an example but gets every instance tagged with the "Talkable" Tag
		local dialogueController = SimpleDialogue.new(npc)
		
		local nodes = {}
		for i, node in ipairs(DialogueHandler.Nodes[npc.Name].Nodes) do
			if node.AutoNode then
				table.insert(nodes, SimpleDialogue.CreateAutoNode(tostring(node.Text), node.Function))
			else
				local number = i
				local options = {}
				if DialogueHandler.Nodes[npc.Name].Options["Node"..number] then
					local currentOptions = DialogueHandler.Nodes[npc.Name].Options["Node"..number]
					
					for i, option in ipairs(currentOptions) do
						table.insert(options, SimpleDialogue.CreateOption(option.Text, nil, option.NodeSwitch))
					end
					table.insert(nodes, SimpleDialogue.CreateNode(tostring(node.Text), options))
				end
			end
		end
		
		local dialogueTree = SimpleDialogue.CreateTree(nodes)
		dialogueController:SetDialogueTree(dialogueTree)
		
	end
end

I put this together in 30 minutes at 2 am so you can maybe do it better but its an example. conditions arent included in here but if someone requests it, i can try to do it

1 Like