Guest User

mRemote

a guest
Apr 28th, 2015
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.25 KB | None | 0 0
  1. rednet.open("back")
  2. shell.run("clear")
  3. term.setTextColor(colors.blue)
  4. print("Type in a command you want to run or type 'help' for a list of commands.")
  5.  
  6. function prefix(write)
  7.   term.setTextColor(colors.yellow)
  8.   term.write(write)
  9.   term.setTextColor(colors.white)
  10. end
  11.  
  12. while true do
  13.   prefix(": ")
  14.   input = read()
  15.  
  16.   if input == "help" then
  17.     term.setTextColor(colors.lightBlue)
  18.     print("list - will list available turtles to connect with")
  19.     term.setTextColor(colors.blue)
  20.     print("connect - will connect to a turtle")
  21.     term.setTextColor(colors.lightBlue)
  22.     print("exit - will exit the program")
  23.   elseif input == "exit" then
  24.     shell.run("clear")
  25.     break
  26.  
  27.   elseif input == "list" then
  28.     rednet.broadcast("list")
  29.     term.setTextColor(colors.blue)
  30.     print("id: description")
  31.  
  32.     while true do
  33.       sendID, msg = rednet.receive(1)
  34.    
  35.       if sendID == nil then break end
  36.      
  37.       term.setTextColor(colors.lightBlue)
  38.       print(sendID .. ": " .. msg)
  39.     end
  40.  
  41.   elseif input == "connect" then
  42.     term.setTextColor(colors.blue)
  43.     print("type in the id of the turtle you want to connect with")
  44.     prefix(": ")
  45.     turtleID = read()
  46.  
  47.     if not tonumber(turtleID) then
  48.       term.setTextColor(colors.lightBlue)
  49.       print("make sure not to use letters!")
  50.    
  51.     else
  52.       turtleID = tonumber(turtleID)
  53.       rednet.send(turtleID, "connect")
  54.       connectID, msg = rednet.receive(1)
  55.      
  56.       if connectID == nil then
  57.         term.setTextColor(colors.lightBlue)
  58.         print("invalid ID")
  59.       else
  60.        
  61.         term.setTextColor(colors.green)
  62.         print(msg)
  63.        
  64.         while true do
  65.        
  66.         prefix(connectID .. ": ")
  67.         command = read()
  68.         commandTable = {}
  69.        
  70.         for word in command:gmatch("%S+") do
  71.           table.insert(commandTable, word)
  72.         end
  73.        
  74.        
  75.           if commandTable[1] == "exit" then
  76.             rednet.send(connectID, "exit")
  77.             break
  78.            
  79.           else
  80.             rednet.send(connectID, commandTable)
  81.             ID, message = rednet.receive(1)
  82.             term.setTextColor(colors.green)
  83.             print(message)
  84.           end
  85.         end
  86.       end
  87.     end
  88.   end
  89. end
Advertisement
Add Comment
Please, Sign In to add comment