#Trying to implement CTC

1 messages · Page 1 of 1 (latest)

orchid hamlet
#

how can i replace the wait time with a ctc? i know id have to add Mouse.Button1Down:Wait() somewhere but im not sure where

lunar zinc
# orchid hamlet how can i replace the wait time with a ctc? i know id have to add Mouse.Button1D...

I'll just assume ctc means "click to continue", referring to just bypassing the yield. If so, then just make something similar to this:

local UIS = game:GetService("UserInputService")

local function Continue()
    --examople function of continueing, will be fired after either a click or after 3 seconds
end

local t:thread = task.delay(5, Continue)

UIS.InputBegan:Connect(function(inp:InputObject)
    if inp.UserInputType ~= Enum.UserInputType.MouseButton1 then return end
    task.cancel(t)
    Continue()
end)
orchid hamlet
shadow robin
#

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local LocalPlayer = Players.LocalPlayer
local Mouse = LocalPlayer:GetMouse()

local function waitForCTC()
    local done = false
    local function resolve()
        if done then return end
        done = true
    end

    local mouseConn = Mouse.Button1Down:Connect(resolve)
    local keyConn = UserInputService.InputBegan:Connect(function(input, gpe)
        if gpe then return end
        local code = input.KeyCode
        if code == Enum.KeyCode.E or code == Enum.KeyCode.Space then
            resolve()
        end
    end)

    while not done do task.wait() end
    mouseConn:Disconnect()
    keyConn:Disconnect()
end

local function typeText(label, text, sound)
    local revealed = false

    local function reveal() revealed = true end
    local mouseConn = Mouse.Button1Down:Connect(reveal)
    local keyConn = UserInputService.InputBegan:Connect(function(input, gpe)
        if gpe then return end
        local code = input.KeyCode
        if code == Enum.KeyCode.E or code == Enum.KeyCode.Space then
            reveal()
        end
    end)

    label.Text = ""
    for i = 1, #text do
        if revealed then
            label.Text = text
            break
        end
        label.Text = string.sub(text, 1, i)
        if sound then sound:Play() end
        task.wait(0.03)
    end

    mouseConn:Disconnect()
    keyConn:Disconnect()
end

local function writeText(label, text, waitMode, sound, gui, box, humanoid)
    humanoid.WalkSpeed = 0
    humanoid.JumpPower = 0
    gui.Enabled = true
    box.Visible = true

    typeText(label, text, sound)

    if typeof(waitMode) == "number" then
        task.wait(waitMode)
    elseif waitMode == "ctc" then
        waitForCTC()
    end
end

local function endDialogue(gui, box, label, humanoid, nameLabel, nameBox, saiSprite, tydeSprite)
    gui.Enabled = false
    box.Visible = false
    label.Text = ""
    humanoid.WalkSpeed = 16
    humanoid.JumpPower = 50
    nameLabel.Text = ""
    nameBox.Visible = false
    saiSprite.Visible = false
    tydeSprite.Visible = false
end

saiDialogue.Triggered:Connect(function()
    if talking then return end
    talking = true
    saiDialogue.Enabled = false
    saisprite.Visible = true
    displayname("Sai")

    local lines = {
        { "Hello...", "ctc", script.Parent.saiTalkSound },
        { "Oh, goodbye...", 2, script.Parent.saiTalkSound }
    }

    for _, line in ipairs(lines) do
        writeText(textLabel, line[1], line[2], line[3], gui, textBox, humanoid)
    end

    endDialogue(gui, textBox, textLabel, humanoid, name, namebox, saisprite, tydesprite)
    saiDialogue.Enabled = true
    talking = false
end)

Or something close to this

orchid hamlet
orchid hamlet
#

holdon ill send a picture of the code

orchid hamlet
orchid hamlet
#

nevermind! i fixed the code :)