Advertisement
McArctic

Untitled

Feb 6th, 2024
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. modem = peripheral.find("modem")
  2. rednet.open("top")
  3.  
  4. local channelID
  5. local currentLine = 2
  6. local privateOrPublic
  7. local inChat = false
  8. local computerID
  9.  
  10. function publicOrPrivate()
  11. while true do
  12. term.clear()
  13. term.setCursorPos(1,1)
  14. term.write("Please Type 1 For Private and 2 For Public")
  15. term.setCursorPos(1,2)
  16. privateOrPublic = tonumber(read())
  17. if privateOrPublic then
  18. break
  19. else
  20. term.clear()
  21. term.setCursorPos(1,1)
  22. term.write("INVALID SELECTION PRESS ANY KEY TO CONTINUE")
  23. local event, key = os.pullEvent("key")
  24. end
  25. end
  26. end
  27.  
  28. function privateMessage()
  29. while true do
  30. term.clear()
  31. term.setCursorPos(1,1)
  32. term.write("Please Input The ID of The Computer")
  33. term.setCursorPos(1,2)
  34. term.write("ID: ")
  35. computerID = tonumber(read())
  36. if computerID then
  37. term.clear()
  38. term.setCursorPos(1,1)
  39. inChat = true
  40. term.write("Press F4 to Exit at Anytime")
  41. term.setCursorPos(1,2)
  42. rednet.send(computerID, "User Has Joined The Chat")
  43.  
  44. while inChat do
  45. parallel.waitForAny(listenForMessages, sendMessageToID, endMessaging)
  46. end
  47. break
  48.  
  49. else
  50. term.clear()
  51. term.setCursorPos(1,1)
  52. term.write("INVALID COMPUTER ID PRESS ANY KEY TO TRY AGAIN")
  53. local event, key = os.pullEvent("key")
  54. end
  55. end
  56.  
  57.  
  58. end
  59.  
  60. function listenForMessages()
  61. while inChat do
  62. local senderID, message = rednet.receive()
  63. term.write("ID " .. senderID .. ": " .. message)
  64. currentLine = currentLine + 1
  65. term.setCursorPos(1, currentLine)
  66. end
  67. end
  68.  
  69. function sendMessageToID()
  70. while inChat do
  71. local message = read()
  72. rednet.send(computerID, message)
  73. currentLine = currentLine + 1
  74. term.setCursorPos(1, currentLine)
  75. end
  76. end
  77.  
  78. function endMessaging()
  79. while inChat do
  80. local event, key = os.pullEvent("key")
  81. if key == keys.f4 then
  82. rednet.send(computerID, "User Has Exited The Chat")
  83. inChat = false
  84. end
  85. end
  86.  
  87. end
  88.  
  89.  
  90.  
  91.  
  92. function publicMessage()
  93.  
  94. while true do
  95. term.clear()
  96. term.setCursorPos(1,1)
  97. term.write("Please Input The ID of The Channel")
  98. term.setCursorPos(1,2)
  99. term.write("ID: ")
  100. channelID = tonumber(read())
  101. modem.open(channelID)
  102. if channelID then
  103. term.clear()
  104. term.setCursorPos(1,1)
  105. inChat = true
  106. term.write("Press F4 to Exit at Anytime")
  107. term.setCursorPos(1,2)
  108. modem.transmit(channelID, channelID, "ID ".. os.computerID() .. ":" .. "Has Joined The Chat")
  109.  
  110. while inChat do
  111. parallel.waitForAny(listenForMessagesPublic, sendMessageToChannel, endMessagingPublic)
  112. end
  113. break
  114.  
  115. else
  116. term.clear()
  117. term.setCursorPos(1,1)
  118. term.write("INVALID COMPUTER ID PRESS ANY KEY TO TRY AGAIN")
  119. local event, key = os.pullEvent("key")
  120. end
  121. end
  122. end
  123.  
  124. function listenForMessages()
  125. while inChat do
  126. local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  127. term.write(message)
  128. currentLine = currentLine + 1
  129. term.setCursorPos(1, currentLine)
  130. end
  131. end
  132.  
  133. function sendMessageToID()
  134. while inChat do
  135. local message = read()
  136. modem.transmit(channelID, channelID, "ID ".. os.computerID() .. ":" .. message)
  137. currentLine = currentLine + 1
  138. term.setCursorPos(1, currentLine)
  139. end
  140. end
  141.  
  142. function endMessaging()
  143. while inChat do
  144. local event, key = os.pullEvent("key")
  145. if key == keys.f4 then
  146. modem.transmit(channelID, channelID, "ID ".. os.computerID() .. ":" .. "Has Left The Chat")
  147. inChat = false
  148. end
  149. end
  150.  
  151. end
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162. while true do
  163. publicOrPrivate()
  164. if privateOrPublic == 1 then
  165. privateMessage()
  166. else
  167. publicMessage()
  168. end
  169. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement