Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

How to add a Insert box to this custom chat Gui? + How to delete the main chat? [closed]

Asked by 7 years ago
Edited 7 years ago

Know I have a Chat output - But how to get a inputbox (Where I set the msg I will say)

Sorry for the big code

Using this code:

local gui = {}

function percent(x,y) return UDim2.new(x/100,0,y/100,0) end function gui:percent(x,y) return percent(x,y) end
function scale(x,y) return UDim2.new(x,0,y,0) end           function gui:scale(x,y) return scale(x,y) end
function pixels(x,y) return UDim2.new(0,x,0,y) end          function gui:pixels(x,y) return pixels(x,y) end

local recolor = "BackgroundColor3"

function color(r,g,b)
    return Color3.fromRGB(r,g,b)
end
function gui:color(...) return color(...) end

function gui:pgui() return game.Players.LocalPlayer:WaitForChild("PlayerGui") end

local ColorTranslateAPI = function(text)
    -- Description: Translates text to a brick color so you dont have to input exact names
    local colors = {
        ["red"] = BrickColor.new("Really red"),
        ["dark red"] = BrickColor.new("Bright red"),
        ["blue"] = BrickColor.new("Really blue"),
        ["dark blue"] = BrickColor.new("Bright blue"),
        ["green"] = BrickColor.new("Lime green"),
        ["dark green"] = BrickColor.new("Bright green"),
        ["darker green"] = BrickColor.new("Dark green"),
        ["darkest green"] = BrickColor.new("Earth green"),
        ["earth green"] = BrickColor.new("Earth green"),
        ["purple"] = BrickColor.new("Bright violet"),
        ["orange"] = BrickColor.new("Bright orange"),
        ["dark orange"] = BrickColor.new("Neon orange"),
        ["white"] = BrickColor.new("Institutional white"),
        ["dark white"] = BrickColor.new("White"),
        ["yellow"] = BrickColor.new("New Yeller"),
        ["dark yellow"] = BrickColor.new("Bright yellow"),
        ["grey"] = BrickColor.new("Medium stone grey"),
        ["gray"] = BrickColor.new("Medium stone grey"),
        ["dark grey"] = BrickColor.new("Dark stone grey"),
        ["dark gray"] = BrickColor.new("Dark stone grey"),
        ["dark black"] = BrickColor.new("Really black"),
        ["black"] = BrickColor.new("Black"),
        ["camo"] = BrickColor.new("Camo"),
        ["dark green"] = BrickColor.new("Dark green"),
        ["bright green"] = BrickColor.new("Bright green"),
        ["lavender"] = BrickColor.new("Lavender"),
        ["peach"] = BrickColor.new("Light orange"),
        ["pale peach"] = BrickColor.new("Pastel brown"),
        ["brick yellow"] = BrickColor.new("Brick yellow"),
        ["aqua"] = BrickColor.new("Bright bluish green"),
        ["baby blue"] = BrickColor.new("Toothpaste"),
        ["cyan"] = BrickColor.new("Cyan"),
        ["brown"] = BrickColor.new("Reddish brown")
        -- add to this list if you want.
    }
    local c = BrickColor.Black()
    if colors[text:lower()] then
        c = colors[text:lower()]
    end
    if tonumber(text) then
        c = BrickColor.new(math.floor(tonumber(text)))
    end
    return c
end

function gui:GetTextLength(txt,font,size)
    local pgui = gui:pgui()
    local sc = pgui:FindFirstChild("__TextLengthGetter") or Instance.new("ScreenGui",pgui)
    sc.Name = "__TextLengthGetter"
    local t = sc:FindFirstChild("__TextLabel") or Instance.new("TextLabel",sc)
    t.Name = "__TextLabel" -- Just in case
    t.BackgroundTransparency = 1
    t.TextTransparency = 1
    t.Font = font or t.Font
    t.FontSize = size or t.FontSize
    t.Text = txt or ""
    return t.TextBounds.X
end

function explode(str,div)
    local tab,cur={},""
    for i = 1, #str do
        if str:sub(i,i+(div:len()-1))==div then
            tab[#tab+1]=cur
            cur=""
            i=i+(div:len()-1)
        else
            cur=cur..str:sub(i,i)
        end
    end
    if cur ~= "" then
        tab[#tab+1]=cur
    end
    return tab
end

function gui:Frame()
    local f = Instance.new("Frame")
    f[recolor] = color(255,255,255)
    f.Size = pixels(0,0)
    f.BorderSizePixel = 0
    return f
end

function gui:TextLabel()
    local f = Instance.new("TextLabel")
    f.Size = pixels(0,0)
    f.FontSize = "Size18"
    f.Font = "SourceSans"
    f.Text = ""
    f.TextColor3 = color(255,255,255)
    f.BorderSizePixel = 0
    return f
end

-- {shadow,red:hello} {blue:world}

function FormatLabel(tl,col,layer)
    local shadow,bold,sep,ital,underline,light
    local formats = explode(col,",")
    for _,str in pairs(formats) do
        if str:lower() == "shadow" then
            shadow = true
        elseif str:lower() == "b" then
            bold = true
        elseif str:lower() == "sep" then
            sep = true
        elseif str:lower() == "i" then
            ital = true
        elseif str:lower() == "l" then
            light = true
        elseif str:lower() == "u" then
            underline = true
        else
            tl.TextColor3 = ColorTranslateAPI(str).Color
        end
    end
    -- font changing
    if bold then
        local font = tl.Font.Name
        if font:find("SourceSans") then
            tl.Font = "SourceSansBold"
        elseif font:find("Arial") then
            tl.Font = "ArialBold"
        end
    end
    if ital then
        local font = tl.Font.Name
        if font:find("SourceSans") then
            tl.Font = "SourceSansItalic"
        end
    end
    if light then
        local font = tl.Font.Name
        if font:find("SourceSans") then
            tl.Font = "SourceSansLight"
        end
    end
    -- label formatting
    if underline then
        local u = gui:Frame()
        u.Name = "Underline"
        u.Size = gui:percent(100,0) + gui:pixels(0,2)
        u.Position = gui:percent(0,100) - gui:pixels(0,2)
        u.BackgroundColor3 = tl.TextColor3 -- hack
        u.Parent = tl
        u.ZIndex = layer + 1
    end
    if sep then
        local s = gui:Frame()
        s.Name = "Separator"
        s.Size = gui:percent(0,100) + gui:pixels(2,0)
        s.Position = gui:percent(100,0) - gui:pixels(2,0)
        s.BackgroundColor3 = tl.TextColor3 -- hack
        s.Parent = tl
        s.ZIndex = layer + 1
    end
    -- last
    if shadow then
        local t = tl:Clone()
        t.TextColor3 = gui:color(0,0,0)
        t.Name = "Shadow"
        t.Position = gui:pixels(2,2)
        t.Size = gui:percent(100,100)
        t.BackgroundTransparency = 1
        t.TextTransparency = 0.5
        tl.ZIndex = t.ZIndex + 1
        t.Parent = tl
    end
end

function gui:GetFormattedText(txt, settings)
    settings = settings or {}
    local padding,
        linemax,
        default_format,
        layer = 
        settings.padding or 0,
        settings.linebreak or 1e4,
        settings.default,
        settings.layer or 1
    local f = gui:Frame()
    f.Name = "__TextContainer"
    f.ZIndex = layer
    local tl = gui:TextLabel()
    tl.BackgroundTransparency = 1
    tl.Name = "Text"
    tl.ZIndex = layer + 1
    local init,last = txt,1
    local linepos = padding or 0
    local toppos = padding or 0
    local curline = 0
    local afterstr
    local function NewLabel(ntext, formatted, color)
        local newtext = tl:Clone()
        newtext.Text = ntext
        if formatted then
            FormatLabel(newtext,color,layer)
        elseif default_format then
            FormatLabel(newtext,default_format,layer)
        end
        local tlen = gui:GetTextLength(ntext, newtext.Font, newtext.FontSize)
        if linemax+padding-linepos < tlen then
            f.Size = f.Size + gui:pixels(0, 18)
            linepos = padding or 0
            curline = curline + 1
        end
        newtext.Size = gui:pixels(tlen,18)
        newtext.Position = gui:pixels(linepos, (padding or 0) + (curline * (18 + padding)))
        linepos = linepos + tlen
        newtext.Parent = f
        toppos = math.max(toppos, linepos)
        return newtext
    end
    for before,cstart,cstop,start,stop,after in txt:gmatch("(){().-():().-()}()") do
        local color = txt:sub(cstart,cstop-1) -- get color string
        local text = txt:sub(start,stop-1) -- get text string
        init = txt:sub(last, before-1) -- get before string
        afterstr = txt:sub(after) -- get remaining string after the capture
        last = after
        -- Handle before
            NewLabel(init,false)
        -- Handle formatted
            NewLabel(text,true,color)
    end
    if afterstr then
        -- Handling the final label
            NewLabel(afterstr,false)
    else
        -- Handle whole text
            NewLabel(txt,false)
    end
    f.Size = gui:pixels(toppos + padding, (20*(curline + 1)) + padding)
    return f
end

return gui

Closed as Non-Descriptive by ScriptGuider and User#5423

This question has been closed because its title or content does not adequately describe the problem you are trying to solve.
Please ensure that your question pertains to your actual problem, rather than your attempted solution. That is, you were trying to solve problem X, and you thought solution Y would work, but instead of asking about X when you ran into trouble, you asked about Y.

Why was this question closed?