Advertisement
Guest User

fakechat

a guest
Aug 1st, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.73 KB | None | 0 0
  1. local modem = peripheral.find("modem")
  2. if not modem then
  3.   error("Requires a modem.")
  4. end
  5. modem.open(1251)
  6.  
  7. term.setBackgroundColor(colors.black)
  8. term.clear()
  9.  
  10. if prevnames == nil then
  11.   prevnames = {}
  12. end
  13.  
  14. term.setCursorPos(1,1)
  15. print("Enter your name")
  16. local name = read(nil,prevnames)
  17. if name:gsub(" ","") ~= "" then
  18.   table.insert(prevnames,name)
  19. end
  20. names = { --Add names to quickly switch between using UP and DOWN
  21.   name,
  22.   "Jesus",
  23.   "&4Console",
  24.   "&4dan200",
  25. }
  26.  
  27. local pos = 1
  28. local scr_x, scr_y = term.getSize()
  29.  
  30. renderMenu = function()
  31.   local x,y = term.getCursorPos()
  32.   local bg = term.getBackgroundColor()
  33.   term.setBackgroundColor(colors.black)
  34.   term.setCursorPos(1,1)
  35.   for a = 1, #names do
  36.     if pos == a then
  37.       write("*")
  38.     else
  39.       write(" ")
  40.     end
  41.     print(names[a])
  42.   end
  43.   term.setCursorPos(x,y)
  44.   term.setBackgroundColor(bg)
  45. end
  46.  
  47. function doRead()
  48.   while true do
  49.     term.setBackgroundColor(colors.black)
  50.     term.clear()
  51.     renderMenu()
  52.     term.setCursorPos(1,1)
  53.     term.setCursorPos(1,scr_y-1)
  54.     term.setBackgroundColor(colors.gray)
  55.     term.clearLine()
  56.     term.setTextColor(colors.white)
  57.     write(">")
  58.     local msg = read()
  59.     if msg:gsub(" ","") == "/exit" then
  60.       return
  61.     end
  62.     if msg:gsub(" ","") ~= "" then
  63.       modem.transmit(1251,1251,{names[pos],msg})
  64.     end
  65.   end
  66. end
  67.  
  68. function changename()
  69.   while true do
  70.     local evt, key = os.pullEvent("key")
  71.     if key == keys.up then
  72.       pos = pos - 1
  73.     end
  74.     if key == keys.down then
  75.       pos = pos + 1
  76.     end
  77.     if pos <= 0 then
  78.       pos = #names
  79.     elseif pos > #names then
  80.       pos = 1
  81.     end
  82.     renderMenu()
  83.   end
  84. end
  85. parallel.waitForAny(changename,doRead)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement