Advertisement
M0n5t3r

chat

Jul 1st, 2013
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. -- Created by eor84
  2. -- Please Give Credit it Edited
  3.  
  4. local inputThread = nill
  5. local input = ""
  6. local x = 3
  7.  
  8. function checkX()
  9. if x == 16 then
  10. print("")
  11. x = 15
  12. end
  13. end
  14.  
  15. function clear()
  16. term.setCursorPos(1,1)
  17. term.clearLine()
  18. if term.isColor() then
  19. term.setBackgroundColor(colors.blue)
  20. end
  21. print("[ Tech Chat V3 ] =========== [ Use 'exit' To Exit ]")
  22. term.setCursorPos(1,2)
  23. term.clearLine()
  24. print("===================================================")
  25. term.setCursorPos(1,17)
  26. term.clearLine()
  27. print("===================================================")
  28. if term.isColor() then
  29. term.setBackgroundColor(colors.black)
  30. end
  31. term.setCursorPos(1,19)
  32. term.clearLine()
  33. term.setCursorPos(1,16)
  34. term.clearLine()
  35. term.setCursorPos(1,3)
  36. term.clearLine()
  37. term.setCursorPos(1,4)
  38. end
  39.  
  40. function getInput()
  41. while true do
  42. clear()
  43. if term.isColor() then
  44. term.setTextColor(colors.lime)
  45. end
  46. term.setCursorPos(1,18)
  47. term.clearLine()
  48. term.write("Message: ")
  49. if term.isColor() then
  50. term.setTextColor(colors.white)
  51. end
  52. input = read()
  53. if string.sub(input, 1, 1) == "/" then
  54. local cmd = {}
  55. for match in string.gmatch(input, "[^%s]+") do
  56. table.insert(cmd, match)
  57. end
  58.  
  59. if cmd[1] == "/exit" then
  60. if term.isColor() then
  61. term.setTextColor(colors.red)
  62. end
  63. x = x + 1
  64. checkX()
  65. term.setCursorPos(1,x)
  66. print("Exiting Tech Chat...")
  67. --rednet.broacast(name.. " Has Left The Chat")
  68. sleep(2)
  69. os.reboot()
  70.  
  71. elseif cmd[1] == "/me" then
  72. msg = "*"..name.." "..table.concat(cmd, " ", 2)
  73. x = x + 1
  74. checkX()
  75. print(msg) -- right here
  76. rednet.broadcast(msg)
  77.  
  78. elseif cmd[1] == "/kill" then
  79. if cmd[2] then
  80. msg = "*" ..name.. " kills "..cmd[2].."."
  81. else
  82. msg = "*" ..name.. " kills himself."
  83. end
  84. x = x + 1
  85. checkX()
  86. print(msg)
  87. rednet.broadcast(msg)
  88.  
  89. --elseif cmd[1] == "/kill"
  90.  
  91. elseif cmd[1] == "/slap" then
  92. msg = "*" ..name.. " slaps " ..cmd[2] or "someone".. "."
  93. x = x + 1
  94. checkX()
  95. print(msg)
  96. rednet.broadcast(msg)
  97.  
  98. elseif cmd[1] == "/help" or cmd[1] == "/?" then
  99. x = x + 1
  100. checkX()
  101. print("/me, /kill, /slap")
  102. end
  103.  
  104. --elseif cmd[1] == "" then
  105. --getInput()
  106. --end
  107.  
  108. else
  109. x = x + 1
  110. checkX()
  111. term.setCursorPos(1,x)
  112. if term.isColor() then
  113. term.setTextColor(colors.lime)
  114. end
  115. term.write("(" ..os.getComputerID().. ") " ..name.. ": ")
  116. term.setTextColor(colors.white)
  117. term.write(input)
  118. local msg = name.. ": " ..input
  119. rednet.broadcast(msg)
  120. end
  121. end
  122. end
  123.  
  124. function newInputThread()
  125. return coroutine.create(getInput)
  126. end
  127.  
  128. function writeReceivedMessage(msg)
  129. --local xPos, yPos = term.getCursorPos()
  130.  
  131. x = x + 1
  132. checkX()
  133. term.setCursorPos(1,x)
  134. print("[" ..msg)
  135. term.setCursorPos(10,18)
  136.  
  137. end
  138.  
  139. print("o")
  140. function listen()
  141. rednet.open("top")
  142. rednet.open("bottom")
  143. rednet.open("back")
  144. rednet.open("front")
  145. rednet.open("right")
  146. rednet.open("left")
  147. inputThread = newInputThread()
  148.  
  149. coroutine.resume(inputThread)
  150. while true do
  151. local event = {os.pullEvent()}
  152.  
  153. if event[1] == "rednet_message" then
  154. writeReceivedMessage(event[2] .. ": " .. event[3])
  155. event = {}
  156. end
  157.  
  158. coroutine.resume(inputThread, unpack(event))
  159. end
  160. end
  161.  
  162. os.pullEvent = os.pullEventRaw
  163. term.clear()
  164. clear()
  165. print("What is your name?")
  166. if term.isColor() then
  167. term.setTextColor(colors.lime)
  168. end
  169. name = read()
  170. if term.isColor() then
  171. term.setTextColor(colors.lime)
  172. end
  173. term.clear()
  174. if term.isColor() then
  175. term.setTextColor(colors.white)
  176. end
  177. clear()
  178. listen()
  179. print("k")
  180. rednet.broadcast(name.. " Has Joined The Chat")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement