I’m working on an Interaction / Dialog system for my game - Below is one of the interaction modules for Players / NPCs. I was wondering how exactly would I insert multiple options for topics, questions and so forth?
I’m querying this due to the inital ‘Dialog’ GUI being a single gui in StarterGui that is manipulated accordingly. How could I do this to include options?
local System = {}
local Debounce = false
function System.Configure(Player, UI, Obj)
if Debounce == false then else return end
Debounce = true
local Humanoid = Player.Character:WaitForChild("Humanoid")
Humanoid.WalkSpeed, Humanoid.JumpPower = 0, 0
UI.Dialog.Visible = true
UI.Confirm.Label.Visible = false
NPC(Player, UI, Obj)
end
local Dialog
function Text(Player, UI, Obj)
for i = 1, #Dialog do
UI.Dialog.DialogText.Text = string.sub(Dialog, 1, i)
wait(0.05)
end
end
function NPC(Player, UI, Obj)
UI.Dialog.DialogName.Text = Obj.Parent.Name
Dialog = "Welcome, " .. Player.Name .. "!"
Text(Player, UI, Obj)
wait(1)
Dialog = "How can I be of assistance today?"
Text(Player, UI, Obj)
wait(1)
end
return System
A system I used involved where you could have 3 reply options and a dialogue for the speaker. It used a number system to keep track of dialogue. This would be handled in a module.
Eg.
local Speakstore = {}
-- a table would be used for keeping track of dialogue
local speakers = {
[key] = {
[0] = {Dialogue, reply1, reply2, reply3};
[1] = {Dialogue, reply1, reply2, reply3};
Name = "Npc";
}
}
local module = {}
function module.Chat(player, key)
--[[ if the player doesn't have any dialogue tracked for the current key in speakstore then create it.]]--
if not speakstore[key] then
speakstore[key] = 0
end
-- What I then did was remote function the player the dialogue for example:
local dialogue = speakers[key][speakstore[key]] - - in this case it would be 0.
local remote = thingy:InvokeClient(player, dialogue, speakers[key].Name)
-- on the client the player would create the gui and reply with a number 1-3 representing their reply of reply1-3.
You can then simply apply logic based on the number eg...
if remote == 2 then - - if they chose reply2
speakstore[key] = 1 - - next time dialogue would be from 1 instead of 0. If you want to make a dialogue box appear straight after their choice then you can just
module.Chat(player, key)
else
end
end
That’s the kind of system I used for my cancelled project. The advantage of using keys instead of speaker name’s means you can have completely separate dialogues based on conditions without having to have a different name. We’ll you’d have to tweak this kind of system so it works with multiple players.
Apologies if my explanation was a bit rough I’m writing this in a rush on my phone.