Greygraphics

TurtleCommander

Oct 21st, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.26 KB | None | 0 0
  1. --This is code for the mod ComputerCraft. It works in CC 1.74. This is the code for the computer
  2.  
  3. local args = {...}
  4.  
  5. local function printAt(x,y,s)
  6.     term.setCursorPos(x,y)
  7.     term.write(s)
  8. end
  9.  
  10. local function connect(Trgt)
  11.     rednet.open(args[2])
  12.     rednet.send(Trgt,"Ping","Ask")
  13.     print("If this screen appears, pleas start 'Remote' on the turtle.\n\nTo end this program, please press 'CMD' + 'T'")
  14.     rednet.receive("Ans")
  15.     print(">> Connected to turtle "..Trgt)
  16.     print("Use arrows to move the turtle.\n")
  17.     TrgtID = Trgt
  18. end
  19.  
  20. local function send(sInput)
  21.     rednet.send(TrgtID,sInput,"CMD")
  22.     local nID,sOutput,prt = rednet.receive("Ans")
  23. end
  24.  
  25. local function update()
  26.     local idT,blT,prT = rednet.receive("BLS")
  27.     local idM,blM,prM = rednet.receive("BLS")
  28.     local idD,blD,prD = rednet.receive("BLS")
  29.     local idF,fuel,prF = rednet.receive("FL")
  30.     local idF,coal,prF = rednet.receive("FL")
  31.    
  32.     term.clear()
  33.     term.setCursorPos(1,1)
  34.     print("TurtleCommander 1.2")
  35.     print("Connected to turtle "..TrgtID)
  36.     print("\nView of turtle:")
  37.     print(blT)
  38.     print(blM)
  39.     print(blD)
  40.     print("\nArrow keys to move the turtle")
  41.     print("Space and LShift to move the turtle up and down")
  42.     print("Enter to stop the program")
  43.     print("Fuel level: "..fuel)
  44.     print("Press 'X' to dig")
  45.     print("Press 'C' to dig down and 'V' to dig up")
  46.     print("Press 'R' to refuel")
  47.     print(coal.." fuel item/s left")
  48. end
  49.  
  50.  
  51. term.clear()
  52. term.setCursorPos(1,1)
  53.  
  54. if #args == 2 then
  55.     connect(tonumber(args[1]))
  56.     send("inspect")
  57.     update()
  58.     while true do
  59.         local k,v = os.pullEvent()
  60.         if k =="key" then
  61.             local key = v
  62.             if key == 208 then
  63.                 send("back")
  64.             elseif key == 200 then
  65.                 send("forward")
  66.             elseif key == 203 then
  67.                 send("turnLeft")
  68.             elseif key == 205 then
  69.                 send("turnRight")
  70.             elseif key == 57 then
  71.                 send("up")
  72.             elseif key == 42 then
  73.                 send("down")
  74.             elseif key == 28 then
  75.                 send("end")
  76.                 print(">> Connection terminated")
  77.                 break
  78.             elseif key == 45 then
  79.                 send("dig")
  80.             elseif key == 46 then
  81.                 send("digD")
  82.             elseif key == 47 then
  83.                 send("digU")
  84.             elseif key == 19 then
  85.                 send("refuel")
  86.             else
  87.                 print("Not implemented")
  88.                 send("Nope")
  89.             end
  90.             update()
  91.             sleep(0.2)
  92.         end
  93.     end
  94. else
  95.     print("Usage: TurtleCommander <ID> [Modem]")
  96. end
Advertisement
Add Comment
Please, Sign In to add comment