Marech

Turtle_CommandProgram_Marech

Jun 26th, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.15 KB | None | 0 0
  1. --command program created by Marech
  2.  
  3.  
  4. local args = { ... }
  5.  
  6. function display(message)
  7.         print(message)
  8. end
  9.  
  10.  
  11. function help()
  12.         print("Help :")
  13.         print("left or l : turnLeft")
  14.         print("right or t : turnRight")
  15.         print("back or b : back")
  16.         print("go or g : goForward")
  17.         print("up or u : up")
  18.         print("dig or i : dig")
  19.         print("down or d : down")
  20.         print("help or h : help")  
  21.         print("quit or q : exit")
  22. end
  23.  
  24. function dig()
  25.        
  26.         while not turtle.forward() do
  27.                 refuel()
  28.                 turtle.attack()
  29.                 turtle.dig()
  30.         end
  31. end
  32.  
  33. function refuel()
  34.     if turtle.getFuelLevel() ~= "unlimited" and turtle.getFuelLevel() < 1 then
  35.                 turtle.select(1)
  36.  
  37.                 if not turtle.refuel(0) then
  38.                         print('Need fuel in slot 1')
  39.                 end
  40.  
  41.                 turtle.refuel(1)
  42.         end
  43. end
  44.  
  45.  
  46. continue = true
  47.  
  48. local peripheralConnected = peripheral.getType("right")
  49. if (peripheralConnected == "modem") then
  50.     isWirelessTurtle = true
  51.     rednet.open("right")
  52. end
  53.  
  54. peripheralConnected = peripheral.getType("left")
  55. if (peripheralConnected == "modem") then
  56.     isWirelessTurtle = true
  57.     rednet.open("left")
  58. end
  59.  
  60. if #args == 1 then
  61.     if args[1] == "off" or args[1] == "offline" then
  62.         isWirelessTurtle = false
  63.     end
  64. end
  65.  
  66.  
  67. print()
  68. print("Waiting for commands")
  69. print()
  70.  
  71. while continue do
  72.     refuel()
  73.  
  74.     if isWirelessTurtle then
  75.         id,command = rednet.receive()
  76.         print("Wireless Command " .. command)
  77.     else
  78.         print("Command ?")
  79.         command = read()
  80.     end
  81.  
  82.     number = string.match(command,"%d+")
  83.  
  84.     if command == "left" or command == "l" then
  85.         turtle.turnLeft()
  86.     elseif command == "right" or command == "r" then
  87.         turtle.turnRight()
  88.     elseif string.find(command, "tunneling") then
  89.         shell.run(command)
  90.     elseif string.find(command, "up") or string.find(command, "u") then
  91.         if number ~= nil then
  92.             for i=0, number-1 do
  93.                 turtle.digUp()
  94.                 turtle.up()
  95.             end
  96.         else
  97.             turtle.up()
  98.         end
  99.     elseif string.find(command, "down") or string.find(command, "d") then
  100.         if number ~= nil then
  101.             for i=0, number-1 do
  102.                 turtle.digDown()
  103.                 turtle.down()
  104.             end
  105.         else
  106.             turtle.down()
  107.         end
  108.     elseif string.find(command, "go") or string.find(command, "g") then
  109.         if number ~= nil then
  110.             for i=0, number-1 do
  111.                 turtle.forward()
  112.             end
  113.         else
  114.             turtle.forward()
  115.         end
  116.     elseif string.find(command, "back") or string.find(command, "b") then
  117.         if number ~= nil then
  118.             for i=0, number-1 do
  119.                 turtle.back()
  120.             end
  121.         else
  122.             turtle.back()
  123.         end
  124.     elseif string.find(command, "i") or string.find(command,"dig") then
  125.         if number ~= nil then
  126.             for i=0, number-1 do
  127.                 dig()
  128.             end
  129.         else
  130.             dig()
  131.         end
  132.     elseif string.find(command, "t") or string.find(command,"attack") then
  133.         turtle.attack()
  134.     elseif command == "off" or command == "f" then
  135.         isWirelessTurtle = false
  136.     elseif command == "on" or command == "o" then
  137.         isWirelessTurtle = true
  138.     elseif command == "help" or command == "h" then
  139.         help()
  140.     elseif command == "exit" or command == "quit" or command == "q" then
  141.         continue = false
  142.         print("bye")
  143.     else
  144.         help()
  145.     end
  146. end
Advertisement
Add Comment
Please, Sign In to add comment