oblinger

RCT v1.9 (Terminal)

Mar 8th, 2014
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.00 KB | None | 0 0
  1. --Startup
  2.  
  3. rednet.open("right")
  4. term.clear()
  5. term.setCursorPos(1,1)
  6. print("RCT v1.9")
  7. print("Turtle ID: ")
  8. select = 1
  9.  
  10. term.setCursorPos(12,2)
  11. id = read()
  12. id = tonumber(id)
  13.  
  14. --Code
  15.  
  16.  
  17. local function writeCentered( text )
  18.   local x, y = term.getSize()
  19.   local centerYPos = y / 2
  20.   local centerXStartingPos = ( x - string.len(text) ) / 2
  21.   term.setCursorPos( centerXStartingPos, centerYPos )
  22.   write( text )
  23. end
  24.  
  25. local function writeCentered2( text )
  26.   local x, y = term.getSize()
  27.   local centerYPos = y / 2
  28.   local centerYPos = centerYPos + 1
  29.   local centerXStartingPos = ( x - string.len(text) ) / 2
  30.   term.setCursorPos( centerXStartingPos, centerYPos )
  31.   write( text )
  32. end
  33.  
  34.  
  35.  
  36.  
  37.  
  38. function findTurtle()       -- Finds Online Turtle
  39.   term.setCursorPos(1,2)
  40.   term.clearLine()
  41.   print("Searching...")
  42.   rednet.send(id,"on")
  43.   sid,msg,dis = rednet.receive(5)
  44.  
  45.   if msg == nill then
  46.     term.setCursorPos(1,2)
  47.     print("Turtle #"..id.." Is Not Online")
  48.   elseif msg == "on" then
  49.     term.setCursorPos(1,2)
  50.     print("Connected To Turtle #"..id)
  51.   elseif msg == "atk" then
  52.     a = 1
  53.     term.setCursorPos(1,2)
  54.     print("Connected To Turtle #"..id)
  55.   end
  56. end
  57.  
  58.  
  59.  
  60.  
  61. function printGui()       -- Prints Controls
  62.  
  63.   term.setCursorPos(1,5)
  64.   print("Controls:")
  65.   print("W/Forward")
  66.   print("A/Left")
  67.   print("D/Right")
  68.   print("S/Back")
  69.   print()
  70.   print("Space/Up")
  71.   print("LShift/Down")
  72.   if msg == "on" then
  73.   print("F/Attack")
  74.   print("G/Dig")
  75.   print("Q/Toggle Dig Direction: Off")
  76.   print()
  77.   print("Press T To Quit And Disconnect")
  78.   elseif msg == "atk" then
  79.   print("F/Attack")
  80.   print("Q/Toggle Attack Direction: Off")
  81.   print()
  82.   print("Press T To Quit And Disconnect")
  83. end
  84. end
  85.  
  86.  
  87.  
  88.  
  89.  
  90. function sendKey()                      -- Sends Commands to Turtle
  91.   event,p1,p2,p3 = os.pullEvent()
  92.  
  93.   if event == "key" then
  94.     local key = p2
  95.  
  96.     if key == 17 then
  97.       rednet.send(id,"w")
  98.  
  99.     elseif key == 30 then
  100.       rednet.send(id,"a")
  101.  
  102.     elseif key == 31 then
  103.       rednet.send(id,"s")
  104.  
  105.     elseif key == 32 then
  106.       rednet.send(id,"d")
  107.  
  108.     elseif key == 42 then
  109.       rednet.send(id,"lsft"
  110.         )
  111.     elseif key == 57 then
  112.       rednet.send(id,"spc")
  113.  
  114.     elseif key == 33 and select == 2 then
  115.       rednet.send(id,"au")
  116.  
  117.     elseif key == 33 and select == 3 then
  118.       rednet.send(id,"ad")
  119.  
  120.     elseif key == 33 then
  121.       rednet.send(id,"f")
  122.  
  123.     elseif key == 34 and select == 2 then
  124.       rednet.send(id,"du")
  125.  
  126.     elseif key == 34 and select == 3 then
  127.       rednet.send(id,"dd")
  128.  
  129.     elseif key == 34 then
  130.       rednet.send(id,"g")
  131.  
  132.     elseif key == 16 then
  133.       if select < 3 then
  134.         select = select + 1
  135.       elseif select == 3 then
  136.         select = 1
  137.       end
  138.  
  139.     elseif key == 18 then
  140.       if select > 1 then
  141.         select = select - 1
  142.       elseif select == 1 then
  143.         select = 3
  144.       end
  145.  
  146.     elseif key == 34 then
  147.       rednet.send(id,"du")
  148.  
  149.     elseif key == 20 then
  150.       rednet.send(id,"dsc")
  151.  
  152.       term.clear()
  153.       term.setCursorPos(1,1)
  154.       rednet.close("right")
  155.       os.reboot()
  156.     end
  157.  
  158.    if a == 1 then
  159.      term.setCursorPos(28,14)
  160.      print("            ")
  161.      term.setCursorPos(28,14)
  162.     if select == 1 then
  163.       print("Off")
  164.  
  165.     elseif select == 2 then
  166.       print("Up")
  167.  
  168.     elseif select == 3 then
  169.       print("Down")
  170.  
  171.     end
  172.    
  173.    else
  174.     term.setCursorPos(25,15)
  175.     print("        ")
  176.     term.setCursorPos(25,15)
  177.      if select == 1 then
  178.        print("Off")
  179.      elseif select == 2 then
  180.        print("Up")
  181.      elseif select == 3 then
  182.        print("Down")
  183.      end
  184.    end
  185.   end
  186. end
  187.  
  188.  
  189.  
  190.  
  191.  
  192.                                                                                                                                                                                                                                                                
  193. findTurtle()
  194. if msg == "on" then
  195.   printGui()
  196.   while true do
  197.     sendKey()
  198.   end
  199. end
Advertisement
Add Comment
Please, Sign In to add comment