Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ...use responsibly.
- --
- -- Get with
- -- pastebin get ruyCGxps fakechat
- -- std ld fakechat
- local prefix = "" --global prefix
- local suffix = "" --global suffix
- local tArg = {...}
- local channel = 1251
- local modem = peripheral.find("modem")
- if not modem then
- error("Requires a modem.")
- end
- modem.open(channel)
- term.setBackgroundColor(colors.black)
- term.clear()
- if prevnames == nil then
- prevnames = {}
- end
- term.setCursorPos(1,1)
- local name
- if tArg[1] then
- name = tArg[1]
- if name:gsub(" ","") ~= "" and prevnames[#prevnames] ~= name then
- table.insert(prevnames,name)
- end
- else
- print("Enter your name:")
- write(">")
- name = read(nil,prevnames)
- if name:gsub(" ","") ~= "" and prevnames[#prevnames] ~= name then
- table.insert(prevnames,name)
- end
- end
- local names = { --Add names to quickly switch between using UP and DOWN
- {
- name = name,
- prefix = "<",
- suffix = "> ",
- realname = name
- },
- {
- name = "&o&6Jesus",
- prefix = "<",
- suffix = "> ",
- },
- {
- name = "&dServer",
- prefix = "&d[",
- suffix = "&d] ",
- msgprefix = "&d",
- realname = "But nobody"
- },
- {
- name = "dan200",
- prefix = "<",
- suffix = "> ",
- },
- }
- local colors_names = { --for use with colors api, you see
- ["0"] = colors.black,
- ["1"] = colors.blue,
- ["2"] = colors.green,
- ["3"] = colors.cyan,
- ["4"] = colors.red,
- ["5"] = colors.purple,
- ["6"] = colors.orange,
- ["7"] = colors.lightGray,
- ["8"] = colors.gray,
- ["9"] = colors.blue, --they don't translate perfectly, okay??
- ["a"] = colors.lime,
- ["b"] = colors.lightBlue,
- ["c"] = colors.red,
- ["d"] = colors.magenta,
- ["e"] = colors.yellow,
- ["f"] = colors.white,
- }
- local codeNames = { --just for checking
- ["k"] = "obfuscate",
- ["o"] = "italic",
- ["l"] = "bold",
- ["m"] = "strikethrough",
- ["n"] = "underline",
- ["r"] = "reset",
- }
- filterColors = function(str,doprint)
- local p = 1
- local output = ""
- local code = "&"
- local col = "f"
- while p <= #str do
- if str:sub(p,p) == code then
- if colors_names[str:sub(p+1,p+1)] then
- col = str:sub(p+1,p+1)
- p = p + 1
- elseif codeNames[str:sub(p+1,p+1)] then
- if str:sub(p+1,p+1) == "r" then
- col = "f"
- end
- p = p + 1
- else
- if doprint then
- term.setTextColor(colors_names[col])
- write(str:sub(p,p))
- end
- end
- p = p + 1
- else
- output = output..str:sub(p,p)
- if doprint then
- term.setTextColor(colors_names[col])
- write(str:sub(p,p))
- end
- p = p + 1
- end
- end
- return output
- end
- local pos = 1
- local scr_x, scr_y = term.getSize()
- local send = function(n,m,p,s,mp,rn) --name, message, prefix, suffix
- local data = {
- name = n,
- realname = rn or n,
- msg = mp..m,
- prefix = p or "<",
- suffix = s or "> ",
- }
- modem.transmit(channel,channel,data)
- end
- local renderMenu = function()
- local x,y = term.getCursorPos()
- local bg = term.getBackgroundColor()
- local txt = term.getTextColor()
- term.setBackgroundColor(colors.black)
- for a = 1, #names do
- term.setCursorPos(1,a)
- term.setTextColor(colors.white)
- if pos == a then
- write("*")
- else
- write(" ")
- end
- filterColors(prefix.."&r"..names[a].prefix.."&r"..names[a].name.."&r"..names[a].suffix.."&r"..suffix,true)
- end
- term.setCursorPos(x,y)
- term.setBackgroundColor(bg)
- term.setTextColor(txt)
- end
- local msgHistory = {}
- local function doRead()
- while true do
- term.setBackgroundColor(colors.black)
- term.clear()
- renderMenu()
- term.setCursorPos(1,1)
- term.setCursorPos(1,scr_y-1)
- term.setBackgroundColor(colors.gray)
- term.clearLine()
- term.setTextColor(colors.white)
- write(">")
- local msg = read(nil,msgHistory)
- if (msg:gsub(" ","") ~= "") and (msg ~= msgHistory[#msgHistory]) then
- msgHistory[#msgHistory+1] = msg
- end
- if msg:gsub(" ","") == "/exit" then
- return
- end
- if msg:gsub(" ","") ~= "" then
- local sdata = {
- names[pos].name,
- msg,
- prefix..names[pos].prefix or "<",
- suffix..names[pos].suffix or "> ",
- names[pos].msgprefix or "",
- }
- if type(names[pos].realname) == "string" then
- table.insert(sdata,names[pos].realname)
- end
- send(unpack(sdata))
- end
- end
- end
- local function changename()
- while true do
- local evt, key = os.pullEvent("key")
- if key == keys.pageUp then
- pos = pos - 1
- end
- if key == keys.pageDown then
- pos = pos + 1
- end
- if pos <= 0 then
- pos = #names
- elseif pos > #names then
- pos = 1
- end
- renderMenu()
- end
- end
- parallel.waitForAny(changename,doRead)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement