WhiteLionATX

clienttest

May 12th, 2014
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.13 KB | None | 0 0
  1. function setTurtleID(x)
  2.     if turtleID == nil or x == 1 then
  3.         print("Enter ID of receiver (WLAN turtle):")
  4.         turtleID = read()
  5.         turtleID = tonumber(turtleID)
  6.         print("Thanks!\n")
  7.     end
  8.     return turtleID
  9. end
  10.  
  11. function sendcmd(cmd)
  12.     print(turtleID.." -> "..cmd)
  13.     t = rednet.send(turtleID, cmd)
  14.     -- print(t)
  15.     x,y,z = rednet.receive()
  16.     print("received:"..y)
  17. end
  18.  
  19. function menu()
  20.     print("\nJassens Commander V1.20\n")
  21.     print("-- M E N U --\n")   
  22.     print("1 - single commands")
  23.     print("2 - commands file")
  24.     print("3 - single command list")
  25.     print("4 - info")
  26.     print("5 - execute command")
  27.     print("6 - change receiver")
  28.     print("7 - change monitor side")
  29.     print("8 - exit\n")
  30. end
  31.  
  32. function info()
  33.     print("Current receiver is: "..tostring(turtleID))
  34. end
  35.  
  36. function multiCmd()
  37.     xy = 0 
  38.     while xy == 0 do
  39.         sendcmd("left 4")
  40.         sleep(2)
  41.     end
  42. end
  43.  
  44. function readFile(file)
  45.     datei = io.open(file, "r")
  46.     if datei == nil then
  47.         print("File not found!")
  48.         return
  49.     end
  50.         zeile = "xxx"
  51.     counter = 1
  52.                 while zeile ~= "" do
  53.                         zeile = datei:read()
  54.             --print("debug:".."-"..zeile.."-")
  55.             if zeile ~= nil then
  56.                             print("Line Nr: "..counter)
  57.                 sendcmd(zeile)
  58.                 counter = counter + 1
  59.             else
  60.                 print("- End of command-file -")
  61.                 return
  62.             end
  63.                 end
  64.          datei:close()        
  65. end
  66.  
  67. function connectModen(positionx)
  68.                 if rednet.isOpen(positionx) then
  69.                         print("Modem found and ready for communication!")
  70.                 else
  71.                         rednet.open(positionx)
  72.                         if rednet.isOpen(positionx) then
  73.                                 print("Modem found and connected")
  74.                         else
  75.                                 print("Modem NOT found! Install to right side!")
  76.                                 exit()
  77.                         end
  78.                 end
  79. end
  80.  
  81.  
  82. function writeMonitor(output)
  83.     monitor.write(output.."\n")
  84. end
  85.  
  86. function intallMonitor(side)
  87.     if side == nil or side == 1 then
  88.         print("Enter side of monitor to connect to (right,left,back,top ...):")
  89.         print("... or press enter to skip")
  90.         side2 = read()
  91.         if side2 == "" then
  92.             return ""
  93.         end
  94.         monitor = peripheral.wrap(side2)
  95.         print("Thanks!\n")
  96.         writeMonitor("Thanks!"..">")
  97.         writeMonitor("test!"..">")
  98.     end
  99.     return side2
  100. end
  101.  
  102. function main()
  103.     menu()
  104.     input = read()
  105.     if input == "1" then
  106.         print("Enter a command like: up 1")
  107.         comd = read()
  108.         sendcmd(comd)
  109.     elseif input == "2" then
  110.         print("Enter a command-file please!")
  111.         comd = read()
  112.         readFile(comd)
  113.     elseif input == "3" then
  114.         print("\n-- Commandlist --\n")
  115.         print("fwd + Anzahl = Vorwaerts")
  116.         print("up + Anzahl = Hoch")
  117.         print("down + Anzahl = Runter")
  118.         print("left = links")
  119.         print("right = rechts")
  120.         print("...enter for next site")
  121.         read()
  122.         print("startmatrix [argument] begin with newmatrix")
  123.         print(" - argument: 0 - digs and collects all items expect the items in slots 1-4")
  124.         print(" - argument: 1 - build with items in all slots where matrix not nil")
  125.         print(" - argument: 4 - build with 4 different items matrix 1 for slots 1-4")
  126.         print("                 matrix 2 for slots 5-8, matrix 3 for slots 9-12 .... aso")
  127.         print("matrix [argumentrow] - builds a blox for each argument.")
  128.         print(" - argument: 0 - empty - 1 set a block of type 1 .... 2 ste a block of type 2 ...aso")
  129.         print("newlayer - sends the turtle to begin of next layer")
  130.         print("endmatrix - sets turtle to first layer at position -1 of the matrix")
  131.         print("...enter back to menu")
  132.         read()     
  133.     elseif input == "4" then
  134.         info()
  135.     elseif input == "5" then
  136.         print("Enter a command to execute on your receiver")
  137.         comd = read()
  138.         sendcmd("execute "..comd)
  139.     elseif input == "6" then
  140.         turtleID = setTurtleID(1)
  141.     elseif input == "7" then
  142.         side = intallMonitor(1)
  143.     elseif input == "8" then
  144.         return "leave"
  145.     else
  146.         print("Error - Unknown command!\n")
  147.     end
  148. end
  149.  
  150. connectModen("right")
  151. turtleID = setTurtleID(2)
  152. monitor = ""
  153. side = intallMonitor()
  154.  
  155. while abc == nil do
  156.     what = main()
  157.     if what == "leave" then
  158.         return 0
  159.     end
  160. end
Advertisement
Add Comment
Please, Sign In to add comment