Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local rs = game:GetService("ReplicatedStorage")
- local ts = game:GetService("TweenService")
- local uis = game:GetService("UserInputService")
- local deb = game:GetService("Debris")
- local col = game:GetService("CollectionService")
- local plrtalking = false
- local closedialogue = false
- local talking = false
- local whoistalking = nil
- local responding = false
- local line = nil
- local layer = nil
- local dialogues = nil
- local emotions = {[1] = nil, [2] = nil}
- local showing1 = false
- local showing2 = false
- local list = require(rs.Dialogues)
- local expressions = rs.Emotions
- local gui = script.Parent.Parent
- local ui = gui.main
- local chars = ui.characters
- local chr1 = chars.char1
- local chr2 = chars.char2
- local grad = ui.gradient
- local skip = ui.skip
- local img = ui.img
- local narr = ui.narrate
- local msg = ui.msg
- local logger = ui.logs
- local logs = ui.log
- local box = msg.box
- local resp = msg.responses
- local txt = box.text
- local exponential = TweenInfo.new(1, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out)
- gui.Enabled = false
- skip.Visible = false
- chars.Position = UDim2.fromScale(0, 1)
- grad.Position = UDim2.fromScale(1, 1.333)
- msg.Position = UDim2.fromScale(0, 1.333)
- box.Position = UDim2.fromScale(0.5, 0.5)
- resp.Position = UDim2.fromScale(1.2, 0.5)
- narr.Visible = false
- narr.GroupTransparency = 1
- narr.txt.Text = ""
- logs.Position = UDim2.new(1.2, -10, 0, 10)
- logger.Visible = false
- logs.MouseButton1Click:Connect(function()
- logger.Visible = not logger.Visible
- if logger.Visible then
- logs.Text = "Hide Chatlog"
- else
- logs.Text = "Show Chatlog"
- end
- end)
- for _, chr in pairs(chars:GetChildren()) do
- if chr:IsA("ViewportFrame") then
- local cam = Instance.new("Camera")
- cam.Parent = chr
- cam.CFrame = CFrame.new(0, 1, -10) * CFrame.Angles(0, math.rad(-180), 0)
- cam.FieldOfView = 40
- chr.CurrentCamera = cam
- end
- end
- local function createlog(msg, narrating)
- local logged = script.logged:Clone()
- logged.Parent = logger.scroller
- logged.TextSize = math.round((32 / 1080) * gui.AbsoluteSize.Y)
- if narrating then
- logged.Text = msg
- else
- logged.Text = msg
- end
- task.defer(function()
- local lwidth = logged.AbsoluteSize.X
- local msize = game:GetService("TextService"):GetTextSize(logged.Text, logged.TextSize, logged.Font, Vector2.new(lwidth, math.huge))
- local count = math.ceil(msize.Y / logged.TextSize)
- logged.Size = UDim2.fromScale(1, 0.05 * count)
- if narrating then
- logged.FontFace = Font.new(logged.FontFace.Family, logged.FontFace.Weight, Enum.FontStyle.Italic)
- else
- logged.FontFace = Font.new(logged.FontFace.Family, logged.FontFace.Weight, Enum.FontStyle.Normal)
- end
- end)
- end
- local function close()
- skip.Visible = false
- ts:Create(chars, exponential, {Position = UDim2.fromScale(0, 1)}):Play()
- ts:Create(grad, exponential, {Position = UDim2.fromScale(1, 1.333)}):Play()
- ts:Create(msg, exponential, {Position = UDim2.fromScale(0, 1.333)}):Play()
- ts:Create(box, exponential, {Position = UDim2.fromScale(0.5, 0.5)}):Play()
- ts:Create(resp, exponential, {Position = UDim2.fromScale(1.2, 0.5)}):Play()
- ts:Create(logs, exponential, {Position = UDim2.new(1.2, -10, 0, 10)}):Play()
- task.wait(1)
- gui.Enabled = false
- logs.Visible = false
- dialogues = nil
- plrtalking = false
- closedialogue = false
- talking = false
- responding = false
- line = nil
- layer = nil
- dialogues = nil
- emotions = {[1] = nil, [2] = nil}
- chr1:SetAttribute("Character", nil)
- chr2:SetAttribute("Character", nil)
- for _, emotion in pairs(chars:GetDescendants()) do
- if emotion:IsA("Model") and not emotion:IsA("WorldModel") then
- emotion:Destroy()
- end
- end
- for _, response in pairs(resp:GetChildren()) do
- if response:IsA("Frame") then
- response:Destroy()
- end
- end
- for _, log in pairs(logger.scroller:GetChildren()) do
- if log:IsA("TextLabel") then
- log:Destroy()
- end
- end
- end
- local function chartoggle()
- if showing1 and showing2 then
- ts:Create(chr1, exponential, {Size = UDim2.fromScale(0.5, 1)}):Play()
- ts:Create(chr2, exponential, {Size = UDim2.fromScale(0.5, 1)}):Play()
- elseif showing1 then
- ts:Create(chr1, exponential, {Size = UDim2.fromScale(1, 1)}):Play()
- ts:Create(chr2, exponential, {Size = UDim2.fromScale(0, 1)}):Play()
- elseif showing2 then
- ts:Create(chr1, exponential, {Size = UDim2.fromScale(0, 1)}):Play()
- ts:Create(chr2, exponential, {Size = UDim2.fromScale(1, 1)}):Play()
- end
- end
- local function sfx(pitch)
- local clone = script.talk:Clone()
- clone.Parent = script
- clone.PitchShiftSoundEffect.Octave = (pitch + (math.random() * 0.1 - 0.05)) / 2
- clone.Volume += (math.random() * 0.1 - 0.05)
- clone:Play()
- deb:AddItem(clone, clone.TimeLength / 2)
- end
- local function playertalk(str)
- txt.FontFace.Weight = Enum.FontWeight.Regular
- txt.TextSize = 32
- txt.TextColor3 = Color3.fromRGB(255, 255, 255)
- plrtalking = true
- txt.Text = str
- txt.MaxVisibleGraphemes = 0
- createlog("You: "..str, false)
- for i = 0, string.len(str) do
- if not plrtalking then
- txt.MaxVisibleGraphemes = #str
- break
- end
- sfx(1.25)
- txt.MaxVisibleGraphemes += 1
- task.wait(0.02)
- end
- plrtalking = false
- end
- local function btnhandler(btn)
- if btn:IsA("TextButton") then
- btn.MouseEnter:Connect(function()
- ts:Create(btn.Parent.txt, exponential, {Position = UDim2.fromScale(0.55, 0.5)}):Play()
- end)
- btn.MouseLeave:Connect(function()
- btn.Parent.txt.TextColor3 = Color3.fromRGB(255, 255, 255)
- ts:Create(btn.Parent.txt, exponential, {
- Position = UDim2.fromScale(0.5, 0.5),
- }):Play()
- end)
- btn.MouseButton1Down:Connect(function()
- btn.Parent.txt.TextColor3 = Color3.fromRGB(160, 160, 160)
- end)
- btn.MouseButton1Up:Connect(function()
- btn.Parent.txt.TextColor3 = Color3.fromRGB(255, 255, 255)
- end)
- btn.MouseButton1Click:Connect(function()
- responding = false
- ts:Create(box, exponential, {Position = UDim2.fromScale(0.5, 0.5)}):Play()
- ts:Create(resp, exponential, {Position = UDim2.fromScale(1.2, 0.5)}):Play()
- local prevline = line
- line = 0
- local rlayer = dialogues.messages[layer][prevline].respond
- local rdata = dialogues.responses[rlayer][tonumber(btn.Parent.Name)]
- if rdata.msg == "" then
- close()
- return
- end
- skip.Visible = true
- box.character.Text = "You"
- playertalk(rdata.msg)
- layer = rdata.display
- for _, response in pairs(resp:GetChildren()) do
- if response:IsA("Frame") then
- response:Destroy()
- end
- end
- end)
- end
- end
- local function respond()
- responding = true
- skip.Visible = false
- ts:Create(box, exponential, {Position = UDim2.fromScale(0.355, 0.5)}):Play()
- ts:Create(resp, exponential, {Position = UDim2.fromScale(0.81, 0.5)}):Play()
- for k, v in ipairs(dialogues.responses[dialogues.messages[layer][line].respond]) do
- local clone = script.option:Clone()
- clone.Name = k
- clone.keybind.Text = k
- clone.txt.Text = v.btntxt
- clone:SetAttribute("Message", v.msg)
- clone.Parent = resp
- btnhandler(clone.btn)
- end
- end
- local function typewriter(str, spe, msg, char)
- if plrtalking then return end
- talking = true
- txt.Text = str
- txt.MaxVisibleGraphemes = 0
- txt.FontFace.Weight = msg == 3 and Enum.FontWeight.Light or msg == 2 and Enum.FontWeight.Bold or Enum.FontWeight.Regular
- txt.TextSize = msg == 3 and 24 or msg == 2 and 48 or 32
- txt.TextColor3 = msg == 3 and Color3.fromRGB(160, 160, 160) or Color3.fromRGB(255, 255, 255)
- local pitch = dialogues.configs.vocalranges[char]
- pitch = msg == 2 and pitch + 0.2 or msg == 3 and pitch - 0.2 or pitch
- createlog(box.character.Text..": "..str, false)
- for i = 0, string.len(str) do
- if not talking then
- txt.MaxVisibleGraphemes = #str
- break
- end
- sfx(pitch)
- txt.MaxVisibleGraphemes += 1
- task.wait(spe)
- end
- talking = false
- if dialogues.messages[layer][line].autoskip then
- line += 1
- showline()
- end
- if dialogues.messages[layer][line].respond then
- respond()
- end
- end
- local function emotionchange(num, char, new)
- if emotions[num] == new then return end
- if expressions[char:GetAttribute("Character")][new] then emotions[num] = new end
- for _, chr in pairs(char.WorldModel:GetChildren()) do
- chr:PivotTo(CFrame.new(0, -10, 0))
- end
- char.WorldModel:FindFirstChild(new):PivotTo(CFrame.identity)
- char.Position = UDim2.fromScale(char.Position.X.Scale, 0.05)
- ts:Create(char, exponential,
- {Position = UDim2.fromScale(char.Position.X.Scale, 0)}
- ):Play()
- end
- function showline()
- if plrtalking then return end
- local closing = false
- local current = dialogues.messages[layer][line]
- if current.exit then
- closing = true
- end
- if current.imgdisplay then
- ts:Create(ui, TweenInfo.new(0.25), {GroupColor3 = Color3.fromRGB(0, 0, 0)}):Play()
- task.delay(0.25, function()
- img.Image = current.imgdisplay
- img.Visible = true
- ts:Create(ui, TweenInfo.new(1), {GroupColor3 = Color3.fromRGB(255, 255, 255)}):Play()
- end)
- end
- if current.imagehide then
- ts:Create(ui, TweenInfo.new(0.25), {GroupColor3 = Color3.fromRGB(0, 0, 0)}):Play()
- task.delay(0.25, function()
- img.Image = ""
- img.Visible = false
- ts:Create(ui, TweenInfo.new(1), {GroupColor3 = Color3.fromRGB(255, 255, 255)}):Play()
- end)
- end
- if current.narrate then
- if narr.txt.Text == "" then
- narr.GroupTransparency = 1
- narr.Visible = true
- ts:Create(narr, TweenInfo.new(0.1), {GroupTransparency = 0}):Play()
- task.wait(0.1)
- narr.txt.Text = current.narrate
- narr.txt.MaxVisibleGraphemes = 0
- createlog(current.narrate, true)
- for i = 0, string.len(narr.txt.Text) do
- narr.txt.MaxVisibleGraphemes += 1
- task.wait(0.025)
- end
- else
- for i = string.len(narr.txt.Text), 0 do
- narr.txt.MaxVisibleGraphemes -= 1
- task.wait(0.02)
- end
- narr.txt.Text = current.narrate
- createlog(current.narrate, true)
- for i = 0, string.len(narr.txt.Text) do
- narr.txt.MaxVisibleGraphemes += 1
- task.wait(0.025)
- end
- end
- if closing then
- closedialogue = true
- return
- end
- return
- else
- if narr.Visible then
- ts:Create(narr, TweenInfo.new(0.1), {GroupTransparency = 1}):Play()
- task.wait(0.1)
- narr.Visible = false
- narr.txt.Text = ""
- end
- end
- if current.show1 then
- showing1 = true
- end
- if current.show2 then
- showing2 = true
- end
- if current.hide1 then
- showing1 = false
- end
- if current.hide2 then
- showing2 = false
- end
- if showing1 and showing2 then
- ts:Create(chr1, exponential, {Size = UDim2.fromScale(0.5, 1)}):Play()
- ts:Create(chr2, exponential, {Size = UDim2.fromScale(0.5, 1)}):Play()
- elseif showing1 then
- ts:Create(chr1, exponential, {Size = UDim2.fromScale(1, 1)}):Play()
- ts:Create(chr2, exponential, {Size = UDim2.fromScale(0, 1)}):Play()
- elseif showing2 then
- ts:Create(chr1, exponential, {Size = UDim2.fromScale(0, 1)}):Play()
- ts:Create(chr2, exponential, {Size = UDim2.fromScale(1, 1)}):Play()
- end
- if current.event then
- if current.event:IsA("RemoteEvent") then
- current.event:FireServer()
- elseif current.event:IsA("BindableEvent") then
- current.event:Fire()
- end
- end
- local talking = current.talking
- box.character.Text = current.name
- emotionchange(1,
- chr1,
- current.emotion1
- )
- if chr2:GetAttribute("Character") and dialogues.configs.characters[2] then
- emotionchange(2,
- chr2,
- current.emotion2
- )
- end
- typewriter(current.msg, 0.02, current.text, current.talking)
- if closing then
- closedialogue = true
- return
- end
- end
- local function start()
- gui.Enabled = true
- box.character.Text = dialogues.messages[1][1].name
- txt.Text = ""
- local initem1 = expressions:FindFirstChild(chr1:GetAttribute("Character"))[dialogues.messages[1][1].emotion1]:Clone()
- local initem2
- if chr2:GetAttribute("Character") and expressions:FindFirstChild(chr2:GetAttribute("Character")) then
- if dialogues.messages[1][1].emotion2 then
- local check = expressions:FindFirstChild(chr2:GetAttribute("Character"))[dialogues.messages[1][1].emotion2]
- if check then
- initem2 = check:Clone()
- end
- end
- end
- for _, em:Model in pairs(expressions[chr1:GetAttribute("Character")]:GetChildren()) do
- if em:IsA("Model") then
- local clone = em:Clone()
- clone.Parent = chr1:FindFirstChildOfClass("WorldModel")
- clone:PivotTo(CFrame.new(0, -10, 0))
- col:AddTag(clone, "Loader")
- end
- end
- if initem2 then
- for _, em in pairs(expressions[chr2:GetAttribute("Character")]:GetChildren()) do
- if em:IsA("Model") then
- local clone = em:Clone()
- clone.Parent = chr2:FindFirstChildOfClass("WorldModel")
- clone:PivotTo(CFrame.new(0, -10, 0))
- col:AddTag(clone, "Loader")
- end
- end
- end
- for _, emotion in pairs(chr1.WorldModel:GetChildren()) do
- if emotion:IsA("Model") then
- if col:HasTag(emotion, "Loader") then continue end
- emotion:Destroy()
- end
- end
- initem1.Parent = chr1:FindFirstChildOfClass("WorldModel")
- emotions[1] = dialogues.messages[1][1].emotion1
- if initem2 then
- initem2.Parent = chr2:FindFirstChildOfClass("WorldModel")
- emotions[2] = dialogues.messages[1][1].emotion2
- end
- task.wait(0.1)
- ts:Create(chars, exponential, {Position = UDim2.fromScale(0 ,0)}):Play()
- ts:Create(grad, exponential, {Position = UDim2.fromScale(1, 1)}):Play()
- ts:Create(msg, exponential, {Position = UDim2.fromScale(0, 1)}):Play()
- task.wait(1)
- line = 1
- layer = 1
- skip.Visible = true
- ts:Create(logs, exponential, {Position = UDim2.new(1, -10, 0, 10)}):Play()
- showline()
- end
- local function skipline()
- if responding then return end
- if closedialogue then
- close()
- return
- end
- if not talking then
- if plrtalking then
- plrtalking = false
- return
- else
- line = (line or 0) + 1
- end
- showline()
- else
- talking = false
- end
- end
- skip.MouseButton1Click:Connect(function()
- skipline()
- end)
- uis.InputBegan:Connect(function(input, gpr)
- if gpr then return end
- if not dialogues then return end
- if not skip.Visible then return end
- if input.KeyCode == Enum.KeyCode.Space then
- skipline()
- end
- end)
- rs.start.OnClientEvent:Connect(function(dialogue)
- dialogues = list[dialogue]
- if dialogues.messages[1][1].show1 then
- showing1 = true
- else
- showing1 = false
- end
- if dialogues.messages[1][1].show2 then
- showing2 = true
- else
- showing2 = false
- end
- if showing1 and showing2 then
- chr1.Size = UDim2.fromScale(0.5, 1)
- chr2.Size = UDim2.fromScale(0.5, 1)
- elseif showing1 then
- chr1.Size = UDim2.fromScale(1, 1)
- chr2.Size = UDim2.fromScale(0, 1)
- elseif showing2 then
- chr1.Size = UDim2.fromScale(0, 1)
- chr2.Size = UDim2.fromScale(1, 1)
- end
- chr1:SetAttribute("Character", dialogues.configs.characters[1])
- emotions[1] = dialogues.messages[1][1].emotion1
- if dialogues.configs.characters[2] then
- chr2:SetAttribute("Character", dialogues.configs.characters[2])
- emotions[2] = dialogues.messages[1][1].emotion2
- end
- start()
- end)
Advertisement
Add Comment
Please, Sign In to add comment