asdaa0

Crap Chat

Aug 17th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local mon = peripheral.find("monitor")
  2. local speaker = peripheral.wrap("left")
  3. local sFile = "data.txt"
  4. local accent,range = "en",100
  5.  
  6. function writemon(msg)
  7.  if mon then
  8.   mon.write(msg)
  9.   mX,mY = mon.getCursorPos()
  10.   mon.setCursorPos(1,mY+1)
  11.  end
  12. end
  13.  
  14. function writeln(msg)
  15.  print(msg)
  16.  tX,tY = term.getCursorPos()
  17.  writemon(msg)
  18. end
  19.  
  20. function clear()
  21.  term.clear()
  22.  term.setCursorPos(1,1)
  23.  if mon then
  24.   mon.clear()
  25.   mon.setCursorPos(1,1)
  26.  end
  27. end
  28.  
  29. function getUsername()
  30.  if fs.exists(sFile) then
  31.   local hRead = assert(fs.open(sFile, "r"))
  32.   username = hRead.readAll()
  33.   hRead.close()
  34.  end
  35. end
  36.  
  37. rednet.open("back")
  38. username = "Steve"
  39.  
  40. function help()
  41.  writeln("Welcome to some shit chat")
  42.  writeln("Press H to set your Handle")
  43.  writeln("Press A to change the Accent")
  44.  writeln("Press T to Type in the chat")
  45.  writeln("Press E to Exit the program")
  46.  writeln("Press R to adjust the Range")
  47. end
  48.  
  49. clear()
  50. getUsername()
  51. help()
  52.  
  53. while true do
  54.  event, id, msg = os.pullEvent()
  55.  
  56.  if event == "rednet_message" then
  57.   writeln(msg)
  58.   spk = msg:gsub('%<[^)]*%>', "")
  59.   speaker.speak(spk, range, accent)
  60.  
  61.  elseif event == "char" then
  62.   if id == "t" then
  63.    write("<"..username.."> ")
  64.    msgsent = read()
  65.    speaker.speak(msgsent, range, accent)
  66.    writemon("<"..username.."> "..msgsent)
  67.    rednet.broadcast("<"..username.."> "..msgsent)
  68.  
  69.   elseif id == "h" then
  70.    write("New username: ")
  71.    username = read()
  72.    hWrite = fs.open(sFile, "w")
  73.    hWrite.write(username)
  74.    hWrite.close()
  75.  
  76.   elseif id == "a" then
  77.    write("New accent: ")
  78.    accent = read()
  79.  
  80.   elseif id == "r" then
  81.    write("New range: ")
  82.    range = read()
  83.  
  84.   elseif id == "e" then
  85.    error("Quit program")
  86.  
  87.   end
  88.  
  89.  end
  90.  
  91. end
Advertisement
Add Comment
Please, Sign In to add comment