Advertisement
SirMongoose

SirChat

Jul 23rd, 2014
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.46 KB | None | 0 0
  1. --SirChat v1.0.0 -Created by Sir.Mongoose
  2.  
  3. local ex = false
  4. local ID = os.getComputerID()
  5. local cl = false
  6. local line = 3
  7.  
  8. function receive()
  9.     local senderID, message = rednet.receive()
  10.     term.clearLine()
  11.     term.setCursorPos(1,line)
  12.     print("<ID#"..senderID.."> "..(tostring(message)))
  13.     line = line + 1
  14. end
  15.  
  16. function send()
  17.     term.write("<ID#"..ID.."> ")
  18.     local mesg = read()
  19.     if mesg == "/exit" then
  20.         ex = true
  21.         term.clear()
  22.         term.setCursorPos(1,1)
  23.     elseif mesg == "/commands" then
  24.         print("> '/exit' terminates the program.")
  25.         print("> '/clear' clears chat completely.")
  26.         print("> '/connect' connects you to a different ID.")
  27.         print("> '/info' Tells you about SirChat.")
  28.         line = line + 5
  29.     elseif mesg == "/clear" then
  30.         cl = true
  31.     elseif mesg == "/connect" then
  32.         connect()
  33.     elseif mesg == "/info" then
  34.         print("> SirChat was a program made by Sir.Mongoose.")
  35.         print("> SirChat is currently in version 1.0.")
  36.     elseif mesg ~= "/exit" or "/commands" or "/clear" or "/connect" or "/info" then
  37.         rednet.send((tonumber(targetID)), (tostring(mesg)))
  38.         line = line + 1
  39.     end
  40. end
  41.  
  42. function chat()
  43.     term.clear()
  44.     term.setCursorPos(1,1)
  45.     print("**Connected with ComputerID#"..(tostring(targetID)).."**")
  46.     print("**Type '/commands' for the list of commands**")
  47.     while ex == false do
  48.         parallel.waitForAny(receive, send)
  49.         if cl == true then
  50.             term.clear()
  51.             term.setCursorPos(1,1)
  52.             print("**Connected with ComputerID#"..(tostring(targetID)).."**")
  53.             print("**Type '/commands' for the list of commands**")
  54.             line = 3
  55.             cl = false
  56.         end
  57.     end
  58. end
  59.  
  60. function numCheck(a)
  61.   if ((tonumber(a)) == nil) == true then
  62.     return false
  63.   else
  64.     return true
  65.    end
  66. end
  67.  
  68. function connect()
  69.   term.clear()
  70.   term.setCursorPos(1,1)
  71.   print("**Enter the ComputerID you want to connect to**")
  72.   targetID = read()
  73.  
  74.   if numCheck(targetID) == true then
  75.     chat()
  76.   else
  77.     while numCheck(targetID) == false do
  78.         term.setCursorPos(1,2)
  79.         term.clearLine()
  80.         targetID = read()
  81.     end
  82.     chat()
  83.   end
  84. end
  85.  
  86. function connectModem()
  87. term.clear()
  88. term.setCursorPos(1,1)
  89. print("**Enter the side of an available Modem** (back,right,left,top,front,bottom, or exit to exit)")
  90.  
  91. local side = read()
  92.   if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
  93.     rednet.open(side)
  94.     connect()
  95.   elseif side == "exit" then
  96.     term.clear()
  97.     term.setCursorPos(1,1)
  98.   else
  99.     connectModem()
  100.    end
  101. end
  102.  
  103. connectModem()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement