Hello Good morning Developers
I have a great doubt how I can make a dialogue system something similar like robot 64 or egghunt 2018
Something similar like that video is an example:
Hello Good morning Developers
I have a great doubt how I can make a dialogue system something similar like robot 64 or egghunt 2018
Something similar like that video is an example:
I suppose whoever made that video used Magnitude and RunService to run constant checks comparing the distance between the player and the NPC’s and altered the bubbles based on that, nowadays you can just use the custom property of ProximityPrompts to detect the range and interactions for you and just alter the bubble accordingly. I suggest taking a look at ProximityPromptService.
As for the dialogue itself, you could use StringValues and Recursion (Loops are actually better due to task overflow, I just happened to have it done with recursion, you might want to change it to use loops instead.) to look for a value inside the NPCs, after one is found you look for another, and so on until there is no more dialogues left.
Made something similar the other day, here’s a fragment of it:
-- Typewritter Effect
local function TypeWritter(StringValue, Time, TextBox) --Reacives the text, time and textlabel and writes it
local index = 0
for first, last in utf8.graphemes(TextBox.Text) do
index += 1
TextBox.MaxVisibleGraphemes = index
Sound:Play() --Plays a sound while writing
task.wait(Time) --Time it takes to write
end
end
-- Dialogue Handling
local function Dialogue(StringValue, Time) --StringValue == text inside the value, Time == how long it takes to write
--Clone a preset GUI (Screen one, not bubble)
local FrameClone = Frame:Clone() --Gray frame shown on screen
FrameClone.Parent = GUI --We parent it to the GUI
FrameClone.Visible = true --and make it visible
--Update Text
local TextBox = FrameClone.TextLabel --TextLabel inside frame
TextBox.Text = StringValue.Value --We change it's text to the one in the value inside the NPC
--TypeWritter effect
TypeWritter(StringValue, Time, TextBox) --We call a function to write the dialogue and give it the value, time and textlabel
--We look inside the StringValue for more StringValues
if StringValue:FindFirstChildWhichIsA("StringValue") then --If there is more
Mouse.Button1Down:Wait() --We wait for the player to click the current one
StringValue = StringValue:FindFirstChildWhichIsA("StringValue") --Save the next one
Time = StringValue:GetAttribute("Time") --Get it's time
FrameClone:Destroy() --And destroy the current one
Dialogue(StringValue, Time) --Then we call the whole function again
else --If there is no more dialogues we just stop
Mouse.Button1Down:Wait() --Once the player clicks the current frame
FrameClone:Destroy()
end
end
-- You'll have to make the PromptTriggered function that calls
-- the dialogue and starts the loop and the whole bubble thing
-- yourself, hope you got the idea.
local function ExampleTriggeredFunction(Object)
local StringValue = --StringValue on npc
local Time = StringValue:GetAttribute("Time") --Attribute with how much the dialogue lasts
Dialogue(StringValue, Time) --We send the values containing the Dialogue/Time that will display
end)
As for the multiple responses part, you’ll have to edit the whole part that looks for more stringvalues to account for both player and npc responses, then you’ll either do some difficult size/position division to position the answers based on the size of a frame or something, or just do a bunch of if statements with a max amount of responses in mind and positioned and clone the found amount, shouldn’t be too difficult that way.
Thank you very much friend, you helped me a lot in that little problem