Advertisement
Griffen8280

harvest

Aug 5th, 2014
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.75 KB | None | 0 0
  1. --This is the computer component to the automated farm.  The turtle portion is named Turtle Plant and can be found in my pastebin.
  2.  
  3. --Table Variables
  4.  
  5. t = {
  6.     {text = "Harvest"   , x = 4,  y = 10,  txtCol = colors.green, bgCol = colors.black},
  7.     {text = "Plant Carrots"        , x = 22, y = 10,  txtCol = colors.orange  , bgCol = colors.black},
  8.     {text = "Plant Potatoes"   , x = 4,  y = 12, txtCol = colors.white, bgCol = colors.black},
  9.     {text = "Plant Wheat" , x = 22, y = 12, txtCol = colors.yellow  , bgCol = colors.black}
  10. }
  11.  
  12. --Logo for the Server
  13. local Logo = {
  14. [[    __________             _____ ]],
  15. [[   /_  __/ __/__________ _/ _/ /_]],
  16. [[    / / _\ \/ __/ __/ _ `/ _/ __/]],
  17. [[   /_/ /___/\__/_/  \_,_/_/ \__/ ]],
  18. [[                                 ]],
  19. }
  20.  
  21. --Monitor Variables
  22.  
  23. mon = peripheral.wrap("top")
  24.  
  25. function draw()
  26.     mon.clear()
  27.     term.redirect(mon)
  28.     mon.setBackgroundColor(colors.black)
  29.     --mon.setCursorPos(2,1)
  30.     for i = 1, #Logo do               --Printing ASCII Logo
  31.         mon.setTextColor(colors.white)
  32.         mon.setCursorPos(3,i)
  33.         print(Logo[i])
  34.     end
  35.     mon.setCursorPos(9,6)
  36.     mon.setTextColor(colors.white)
  37.     mon.write("TSCraft Server Autofarm")
  38.     mon.setCursorPos(10,7)
  39.     mon.setTextColor(colors.white)
  40.     mon.write("By Griffen8280")
  41.     mon.setCursorPos(9,8)
  42.     mon.setTextColor(colors.white)
  43.     mon.write("Select Farm Action Below")
  44. end
  45.  
  46. --Functions
  47.  
  48. function writeButtons(_table)
  49.     for i, v in pairs(_table) do
  50.         mon.setCursorPos(v.x, v.y)
  51.         mon.setTextColor(v.txtCol)
  52.         mon.setBackgroundColor(v.bgCol)
  53.         mon.write(v.text)
  54.     end
  55. end
  56.  
  57. function isValidClick(_table, mx, my)
  58.  
  59.     for i, v in pairs(_table) do
  60.         if mx >= v.x and mx <= (v.x + #v.text) and my == v.y then
  61.              return true, v.text
  62.         end
  63.     end
  64.     return false, nil
  65. end
  66.  
  67. function harvest()
  68.  
  69.     rs.setOutput("back", true)
  70.     sleep(18)
  71.     rs.setOutput("back", false)
  72.     sleep(10)
  73.     rs.setOutput("bottom", true)
  74.     sleep(12)
  75.     rs.setOutput("bottom", false)
  76.     os.reboot()
  77. end
  78.  
  79. function carrots()  --For planting the carrots with the turtle.
  80.     rednet.open("right")
  81.     rednet.send(1, "carrots") --Be sure to set the number to the id number of your turtle
  82.     while true do
  83.         id, msg = rednet.receive(1)  --Be sure to set the number to the id number of your turtle
  84.         if msg == "fuel" then
  85.             mon.clear()
  86.             mon.setCursorPos(9,6)
  87.             mon.write("The turtle is out of fuel")
  88.             mon.setCursorPos(9,7)
  89.             mon.write("Please add more coal/charcoal")
  90.             mon.setCursorPos(9,8)
  91.             mon.write("To any open slot on the turtle")
  92.         elseif msg == "full" then
  93.             mon.clear()
  94.             mon.setCursorPos(3,8)
  95.             mon.write("Good for gas, will alert if fuel is needed!")
  96.         elseif msg == "done" then
  97.             rednet.close("right")
  98.             os.reboot()
  99.         end
  100.     end
  101. end
  102.  
  103. function potatoes()  --For planting the potatoes with the turtle.
  104.     rednet.open("right")
  105.     rednet.send(1, "potatoes")  --Be sure to set the number to the id number of your turtle
  106.     while true do
  107.         id, msg = rednet.receive(1)  --Be sure to set the number to the id number of your turtle
  108.         if msg == "fuel" then
  109.             mon.clear()
  110.             mon.setCursorPos(9,6)
  111.             mon.write("The turtle is out of fuel")
  112.             mon.setCursorPos(9,7)
  113.             mon.write("Please add more coal/charcoal")
  114.             mon.setCursorPos(9,8)
  115.             mon.write("To any open slot on the turtle")
  116.         elseif msg == "full" then
  117.             mon.clear()
  118.             mon.setCursorPos(3,8)
  119.             mon.write("Good for gas, will alert if fuel is needed!")
  120.         elseif msg == "done" then
  121.             rednet.close("right")
  122.             os.reboot()
  123.         end
  124.     end
  125. end
  126.  
  127. function wheat()  --For planting the wheat with the turtle.
  128.     rednet.open("right")
  129.     rednet.send(1, "wheat")  --Be sure to set the number to the id number of your turtle
  130.     while true do
  131.         id, msg = rednet.receive(1)  --Be sure to set the number to the id number of your turtle
  132.         if msg == "fuel" then
  133.             mon.clear()
  134.             mon.setCursorPos(9,6)
  135.             mon.write("The turtle is out of fuel")
  136.             mon.setCursorPos(9,7)
  137.             mon.write("Please add more coal/charcoal")
  138.             mon.setCursorPos(9,8)
  139.             mon.write("To any open slot on the turtle")
  140.         elseif msg == "full" then
  141.             mon.clear()
  142.             mon.setCursorPos(3,8)
  143.             mon.write("Good for gas, will alert if fuel is needed!")
  144.         elseif msg == "done" then
  145.             rednet.close("right")
  146.             os.reboot()
  147.         end
  148.     end
  149. end
  150.    
  151. --Program
  152.  
  153. draw()
  154. writeButtons(t)
  155.  
  156. while true do
  157.     _, but, x, y = os.pullEvent("monitor_touch")
  158.     bClick, option = isValidClick(t, x, y)
  159.     if bClick then
  160.     -- Yes, it's a valid click. Now let's do something with the returned text 'option'
  161.       if option == "Harvest" then
  162.         harvest()
  163.       elseif option == "Plant Carrots" then
  164.         carrots()
  165.       elseif option == "Plant Potatoes" then
  166.         potatoes()
  167.       elseif option == "Plant Wheat" then
  168.         wheat()
  169.       end
  170.    end
  171. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement