Advertisement
dadragon84

FarmerTurtLe

Feb 26th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.31 KB | None | 0 0
  1. -- farmerturt v1.0 (Severino) [GNU GPL License, given here: <http://www.gnu.org/licenses/gpl.txt>]
  2. -- Some code based from Deluxe Turtle Farming Suite V1.0 Beta (alux35)
  3. -- http://www.computercraft.info/forums2/index.php?/topic/4639-deluxe-turtle-farming-suite/
  4. -----------------------------------------------------------------------
  5. shell.run("delete turtlename")
  6. term.clear()
  7. term.setCursorPos(1, 1)
  8. minerID = os.getComputerID()
  9. turtleName = nil
  10. consoleID = 0
  11. version = "1.0"
  12. function getConsoleID()
  13.   local fname = "ConsoleID"
  14.   if fs.exists(fname) then
  15.     file = fs.open(fname, "r")
  16.     consoleID = tonumber(file.readAll())
  17.     file.close()
  18.     print("Monitor Console ID: "..consoleID)
  19.   else
  20.     updateStatus("Waiting for Console ID...",true)
  21.     term.write("Monitor Console ID: ")
  22.     consoleID = io.read()
  23.     file = fs.open(fname, "w")
  24.     file.write(consoleID)
  25.     file.close()
  26.     consoleID = tonumber(consoleID)
  27.   end
  28. end
  29. function updateStatus(msg, silent)
  30.   if not rednet.isOpen("right") then rednet.open("right") end
  31.   if rednet.isOpen("right") then
  32.     if turtleName == nil then return end
  33.     networkmsg = "MM:"..turtleName..": "..msg
  34.     if consoleID == 0 then
  35.       rednet.broadcast(networkmsg)
  36.     else
  37.       rednet.send(consoleID,networkmsg)
  38.     end
  39.   end
  40.   if not silent then print(msg) end
  41. end
  42. function getTurtleName()
  43.   local fname = "TurtleName"
  44.   if fs.exists(fname) then
  45.     file = fs.open(fname, "r")
  46.     turtleName = file.readAll()
  47.     file.close()
  48.   else
  49.     term.write("Turtle Name: ")
  50.     turtleName = io.read()
  51.     file = fs.open(fname, "w")
  52.     file.write(turtleName)
  53.     file.close()
  54.   end
  55. end
  56. -- Main Program
  57. updateStatus("Starting")
  58. term.clear()
  59. term.setCursorPos(1,1)
  60. getTurtleName()
  61. getConsoleID()
  62. function update()
  63.   print("Internet connection required...")
  64.   print("  installing FarmerTurt files...")
  65.   print("     press ENTER key to continue...")
  66.   updateStatus("Waiting for User")
  67.   io.read()
  68.   shell.run("delete do_wheat")
  69.   shell.run("pastebin get nvWd6fqD do_wheat")
  70.   updateStatus("Updating do_wheat.")
  71.   shell.run("delete do_wheatplant")
  72.   shell.run("pastebin get UscYxzsZ do_wheatplant ")
  73.   updateStatus("Updating do_wheatplant.")
  74.   shell.run("delete do_sugar")
  75.   shell.run("pastebin get TUx4PwVm do_sugar")
  76.   updateStatus("Updating do_sugar.")
  77.   shell.run("delete do_sugarplant")  
  78.   shell.run("pastebin get uRVizvya do_sugarplant")
  79.   updateStatus("Updating do_sugarplant.")
  80.   shell.run("delete do_veggies")
  81.   shell.run("pastebin get tTxmq0nV do_veggies")
  82.   updateStatus("Updating do_veggies.")
  83.   shell.run("delete do_veggiesplant")
  84.   shell.run("pastebin get uh2jDUG2 do_veggiesplant")
  85.   updateStatus("Updating do_veggiesplant.")
  86. end
  87.  
  88. function menu()
  89.   updateStatus("Waiting at the Menu.")
  90.   print("** Severino Farming Turtles Menu **")
  91.   print("What type of farming would you like this turtle to perform?")
  92.   print("    1) Wheat (Harvest)")
  93.   print("    2) Wheat (Plant)")
  94.   print("    3) SugarCane (Harvest)")
  95.   print("    4) SugarCane (Plant)")
  96.   print("    5) Veggies (Harvest)")
  97.   print("    6) Veggies (Plant)")
  98.   print("    0) Automate")
  99.   print("    99) Exit")
  100.   selection = io.read()
  101.  
  102.   if tonumber(selection) == 1 then
  103.       print("you're choice was 1; running do_wheat")
  104.       shell.run("do_wheat","")
  105.   elseif tonumber(selection) == 2 then
  106.       print("you're choice was 2; running do_wheatplant")
  107.       shell.run("do_wheatplant","")
  108.   elseif tonumber(selection) == 3 then
  109.       print("you're choice was 3; running do_sugar")
  110.       shell.run("do_sugar","")
  111.   elseif tonumber(selection) == 4 then
  112.       print("you're choice was 4; running do_sugarplant")
  113.       shell.run("do_sugarplant","")
  114.   elseif tonumber(selection) == 5 then
  115.       print("you're choice was 5; running do_veggies")
  116.       shell.run("do_veggies","")
  117.   elseif tonumber(selection) == 6 then
  118.       print("you're choice was 6; running do_veggiesplant")
  119.       shell.run("do_veggiesplant","")
  120.   elseif tonumber(selection) == 0 then
  121.       print("Automation is still in development (press ENTER)")
  122.       io.read()
  123.       shell.run("clear","")
  124.       menu()
  125.   elseif tonumber(selection) == 99 then
  126.       print("exiting...")
  127.       shell.exit()
  128.   end  
  129. end
  130.  
  131. update()
  132. print("PREREQUISITES: Fuel in last slot 16.")
  133. print("************************************")
  134. menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement