Customizable Dialogue System

I made this and used it in one of my games and I thought I should share it.

That place is uncopylocked so if you want the Dialogue system simply download a place and copy the required scripts and UI

Functionality

Allows you to make custom dialogue and use it on a custom UI, it is important that you have the required UI elements as the code needs them.

If a new event from the server is received while the client is already in a Dialogue then the old dialogue is halted and the new one plays.

It is easy to make new dialogue’s you just have to put them in a module as such

local module = {}

module.HomelessGuy = {
	{
		command = "Prompt",
		DialogueText = "...",
		speaker = "Homeless Guy",
		option1 = {
			text = "You nearly gave me a heart attack!",
			followup = {
				{
					command = "Dialogue",
					DialogueText = "I'm sorry, I was just looking for some food.",
					speaker = "Homeless Guy",
				},
				{
					command = "Dialogue",
					DialogueText = "I didn't mean to scare you.",
					speaker = "Homeless Guy",
				},
				{
					command = "Prompt",
					DialogueText = "Could I please have some food?",
					speaker = "Homeless Guy",
					option1 = {
						text = "The manager doesn't let me hand out free food.",
						followup = {
							{
								command = "Dialogue",
								DialogueText = "Not even what you're about to throw away?",
								speaker = "Homeless Guy",
							},
							{
								command = "Dialogue",
								DialogueText = "You must have some food that is going to expire soon or something.",
								speaker = "Homeless Guy",
							},
							{
								command = "Prompt",
								DialogueText = "Things that you can't sell to the customers anyways.",
								speaker = "Homeless Guy",
								option1 = {
									text = "I'm sorry, we threw away soon to be expired food 2 days ago (lie)",
									followup = {
										{
											command = "Dialogue",
											DialogueText = "Im' really sorry, but we recently threw away all our close to expiry food.",
											speaker = "You",
										},
										{
											command = "Dialogue",
											DialogueText = "You came at a very unfortunate time.",
											speaker = "You",
										},
										{
											command = "Dialogue",
											DialogueText = "I'm really sorry.",
											speaker = "You",
										},
									},
								},
								option2 = {
									text = "I think we do have something, let me check (true).",
									followup = {
										{
											command = "Dialogue",
											DialogueText = "We might have something still left in the freezer from a few months ago.",
											speaker = "You",
										},
										{
											command = "Dialogue",
											DialogueText = "I'm not 100% certain but I'll go check. You wait here.",
											speaker = "You",
										},
										{
											command = "Dialogue",
											DialogueText = "Yes, yes, thank you. I'll be waiting out here. Anything you can give me, I'll appreciate.",
											speaker = "Homeless Guy",
										},
									},
								},
							},
						},
					},
					option2 = {
						text = "We have some food that is going to expire soon anyway.",
						followup = {
							{
								command = "Dialogue",
								DialogueText = "We have some food that is going to expire in a few days.",
								speaker = "You",
							},
							{
								command = "Dialogue",
								DialogueText = "Are you okay with taking that?",
								speaker = "You",
							},
							{
								command = "Dialogue",
								DialogueText = "Yes, yes, thank you. I'll be waiting out here. Anything you can give me, I'll appreciate.",
								speaker = "Homeless Guy",
							},
						},
					},
				},
			},
		},
		option2 = {
			text = "What are you doing here?!",
			followup = {
				{
					command = "Dialogue",
					DialogueText = "I'm sorry, I was just looking for some food.",
					speaker = "Homeless Guy",
				},
				{
					command = "Dialogue",
					DialogueText = "I didn't mean to scare you.",
					speaker = "Homeless Guy",
				},
				{
					command = "Prompt",
					DialogueText = "Could I please have some food?",
					speaker = "Homeless Guy",
					option1 = {
						text = "The manager doesn't let me hand out free food.",
						followup = {
							{
								command = "Dialogue",
								DialogueText = "Not even what you're about to throw away?",
								speaker = "Homeless Guy",
							},
							{
								command = "Dialogue",
								DialogueText = "You must have some food that is going to expire soon or something.",
								speaker = "Homeless Guy",
							},

							{
								command = "Prompt",
								DialogueText = "Things that you can't sell to the customers anyways.",
								speaker = "Homeless Guy",
								option1 = {
									text = "I'm sorry, we threw away soon to be expired food 2 days ago (lie)",
									followup = {
										{
											command = "Dialogue",
											DialogueText = "Im' really sorry, but we recently threw away all our close to expiry food.",
											speaker = "You",
										},
										{
											command = "Dialogue",
											DialogueText = "You came at a very unfortunate time.",
											speaker = "You",
										},
										{
											command = "Dialogue",
											DialogueText = "I'm really sorry.",
											speaker = "You",
										},
									},
								},
								option2 = {
									text = "I think we do have something, let me check (true).",
									followup = {
										{
											command = "Dialogue",
											DialogueText = "We might have something still left in the freezer from a few months ago.",
											speaker = "You",
										},
										{
											command = "Dialogue",
											DialogueText = "I'm not 100% certain but I'll go check. You wait here.",
											speaker = "You",
										},
										{
											command = "Dialogue",
											DialogueText = "Yes, yes, thank you. I'll be waiting out here. Anything you can give me, I'll appreciate.",
											speaker = "Homeless Guy",
										},
									},
								},
							},
						},
					},
					option2 = {
						text = "We have some food that is going to expire soon anyway.",
						followup = {
							{
								command = "Dialogue",
								DialogueText = "We have some food that is going to expire in a few days.",
								speaker = "You",
							},
							{
								command = "Dialogue",
								DialogueText = "Are you okay with taking that?",
								speaker = "You",
							},
							{
								command = "Dialogue",
								DialogueText = "Yes, yes, thank you. I'll be waiting out here. Anything you can give me, I'll appreciate.",
								speaker = "Homeless Guy",
							},
						},
					},
				},
			},
		},
	},
}
module.Cofee = {
	{
		command = "Prompt",
		DialogueText = "Hey, how’s it going?",
		speaker = "Customer",
		option1 = {
			text = "Not bad, just working.",
			followup = {
				{
					command = "Dialogue",
					DialogueText = "I hear you. Gotta keep hustling, right?",
					speaker = "Customer",
				},
				{
					command = "Dialogue",
					DialogueText = "I get it. It’s been a busy day for me too.",
					speaker = "Customer",
				},
				{
					command = "Prompt",
					DialogueText = "Can I get a coffee to go?",
					speaker = "Customer",
					option1 = {
						text = "Sure, coming right up!",
						followup = {
							{
								command = "Dialogue",
								DialogueText = "Thanks! I’ll be on my way in no time.",
								speaker = "Customer",
							},
							{
								command = "Dialogue",
								DialogueText = "I need something to keep me awake, you know?",
								speaker = "Customer",
							},
						},
					},
					option2 = {
						text = "Sorry, we don’t do takeout coffee.",
						followup = {
							{
								command = "Dialogue",
								DialogueText = "Oh, that’s unfortunate. I was in a rush.",
								speaker = "Customer",
							},
							{
								command = "Dialogue",
								DialogueText = "Well, I guess I’ll stay for a bit then.",
								speaker = "Customer",
							},
						},
					},
				},
			},
		},
		option2 = {
			text = "I’m just here for the food.",
			followup = {
				{
					command = "Dialogue",
					DialogueText = "Ah, we’ve got some fresh pastries in stock.",
					speaker = "Employee",
				},
				{
					command = "Dialogue",
					DialogueText = "What kind of food are you in the mood for today?",
					speaker = "Employee",
				},
				{
					command = "Prompt",
					DialogueText = "Could I suggest the chocolate croissant?",
					speaker = "Employee",
					option1 = {
						text = "That sounds great! I’ll have one.",
						followup = {
							{
								command = "Dialogue",
								DialogueText = "Coming right up! You’ll love it.",
								speaker = "Employee",
							},
							{
								command = "Dialogue",
								DialogueText = "Excellent choice. It’s fresh out of the oven.",
								speaker = "Employee",
							},
						},
					},
					option2 = {
						text = "I’m not really into sweets.",
						followup = {
							{
								command = "Dialogue",
								DialogueText = "No worries, we’ve got savory options too.",
								speaker = "Employee",
							},
							{
								command = "Dialogue",
								DialogueText = "How about a sandwich instead?",
								speaker = "Employee",
							},
						},
					},
				},
			},
		},
	},
	
}

return module

There are two examples here, both being functional, it is important that you maintain that structure when making/editing dialogue, otherwise it will not work.

what I found was useful was to feed the example into chatGPT and tell it to, following that dialogue structure to make custom dialogue, it is certainly easier then doing it manually

(The Coffee one was made by chatGPT after I gave it the Homeless Guy one as an example and told it to make another random dialogue)

if you need help or clarification please ask

3 Likes