Advertisement
Guest User

startup

a guest
Apr 24th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 27.81 KB | None | 0 0
  1. --[[
  2.    
  3. ]] 
  4.    
  5.     --VARIABLES
  6.    
  7. local line                                      --line inside file
  8. local stringQuestionAsked                       --Question for the Menu
  9. local x,y = term.getSize()                      --Size of the screen
  10. local highlighted = 1                           --Chosen Element inside menu
  11. local choices = {}                              --Table of choices inside menu
  12. local chosenOne                                 --Chosen element of the menu
  13. local removed = 0                               --Variable to remove the right element from list
  14. local success, data                             --Variables for inspection of Blocks
  15. local encodedString
  16. local i                                         --Variable for Calculation
  17. local m                                         --Variable for Calculation
  18. local n                                         --Variable for Calculation
  19.    
  20.     --FILES
  21.    
  22.     --Names
  23.    
  24. local turtleDataFile = "turtleDataFile"         --Name of the File that saves 1: X coordinate, 2: Z coordinate, 3: Rotation, 4: Number of Holes
  25. local turtleModemFile = "turtleModemFile"       --Name of the File that saves the side of the Wireless Modem
  26. local overseerIDFile = "overseerID"             --Name of the File that saves the IDs of every Overseer
  27. local trashBlockFile = "trashBlock"             --Name of the File that saves every Block that the Turtle shouldn't mine
  28. local trackingBlockFile = "trackingBlock"       --Name of the File that saves the Blocks that are supposed to be tracked
  29. local turtleActivityFile = "turtleActivity"     --Name of the File that saves the Blocks that are supposed to be tracked
  30.     --Tables
  31.    
  32. local turtleData = {}                           --Table to save the Data inside the turtleDataFile
  33. local turtleModem = {}                          --Table to save the Data inside the turtleModemFile
  34. local overseerID = {}                           --Table to save the Data inside the overseerIDFile
  35. local trashBlock = {}                           --Table to save the Data inside the trachBlockFile
  36. local newTrashBlock = {}                        --Table to save the new Data of Trash Blocks
  37. local trackingBlock = {}                        --Table to save the Data inside the trackingBlockFile
  38. local newTrackingBlock = {}                     --Table to save the Data inside the trackingBlockFile
  39. local turtleActivity = {}                       --Table to save the Data inside the trackingBlockFile
  40.  
  41.     --FUNKTIONS
  42.  
  43. function load(fileName,arrayName)               --Loading data that is inside File
  44.     file = fs.open("Data/"..fileName,"r") -- Open a file for reading.
  45.     line = file.readLine() -- This function reads the next line in the file, until the end.
  46.     repeat -- Start a loop which will read lines into a table until no lines are left.
  47.         table.insert(arrayName,line) -- Puts the value of the current line into the table we have.
  48.         line = file.readLine() -- read the next line
  49.     until line == nil -- readLine() returns nil when the end of the file is reached.
  50.     file.close() -- Close up the file ready for use again.
  51. end
  52.  
  53. function createFile(File)                       --Function that is used for the sole purpose of creating a file without editing it
  54.     local file = fs.open("Data/"..File,"a")
  55.     file.close()
  56. end
  57.  
  58. function resetScreen()
  59.     term.clear()
  60.     term.setCursorPos(1,1)
  61. end
  62.  
  63.     --MENU
  64.  
  65. function writeChoices()                         --writes the choices down made for the menu
  66.     for i=1,#choices do
  67.         if i == highlighted then
  68.             term.setCursorPos(((x/2)-(("<| "..choices[i].." |>"):len()/2)),i + 2)
  69.             term.clearLine()
  70.             term.write("<| "..choices[i].." |>")
  71.         else
  72.             term.setCursorPos(((x/2)-(choices[i]:len()/2)),i + 2)
  73.             term.clearLine()
  74.             term.write(choices[i])
  75.         end
  76.     end
  77. end
  78.  
  79. function menuSelection()                        --waits for key input and changes the highlighted menuElemnt
  80.     while true do
  81.         writeChoices()
  82.         local event, key = os.pullEvent( "key" )
  83.         if key == keys.down then
  84.             highlighted = highlighted + 1
  85.         end
  86.         if key == keys.up then
  87.             highlighted = highlighted - 1
  88.         end
  89.         if key == keys.enter then
  90.             chosenOne = choices[highlighted]
  91.             break
  92.         end
  93.         if highlighted == 0 then
  94.             highlighted = #choices
  95.         end
  96.         if highlighted == #choices + 1 then
  97.             highlighted = 1
  98.         end
  99.     end
  100. end
  101.  
  102. function Menu()                                 --Creates a menu
  103.     term.clear()
  104.     term.setCursorPos(math.ceil((x/2)-(stringQuestionAsked:len()/2)),1)
  105.     term.write(stringQuestionAsked)
  106.     menuSelection()
  107. end
  108.  
  109. function encodeMinerSend()
  110.     turtleModem = {}
  111.     load(turtleModemFile,turtleModem)
  112.     rednet.open(turtleModem[1])
  113.     turtleData = {}
  114.     load(turtleDataFile,turtleData)
  115.     table.insert(turtleData,turtle.getFuelLevel())
  116.     trackingBlock = {}
  117.     load(trackingBlockFile,trackingBlock)
  118.     table.insert(turtleData,trackingBlock[1])
  119.     table.insert(turtleData,trackingBlock[2])
  120.     table.remove(turtleData,3)
  121.     table.remove(turtleData,4)
  122.     encodedString = "Miner%"
  123.     for i=1,#turtleData,1 do
  124.         encodedString = encodedString..turtleData[i].."%"
  125.     end
  126.     overseerID = {}
  127.     load(overseerIDFile,overseerID)
  128.     for i=1,#overseerID,1 do
  129.         local x = tonumber(overseerID[i])
  130.         rednet.send(x,encodedString)
  131.     end
  132. end
  133.  
  134. function refuel()
  135.     while true do
  136.         if turtle.getFuelLevel() < (turtle.getFuelLimit() - 100) and turtle.getItemCount(4) > 1 then
  137.             turtle.select(4)
  138.             turtle.refuel(1)
  139.         else
  140.             break
  141.         end
  142.     end
  143.     turtle.select(1)
  144. end
  145. function space()
  146.     local x = {}
  147.     for i = 5,16,1 do
  148.         if turtle.getItemCount(i) == 0 then
  149.             table.insert(x,"i")
  150.         end
  151.     end
  152.     if #x < 2 then
  153.         turtle.select(2)
  154.         if turtle.detect() == true then
  155.             turtle.dig()
  156.         end
  157.         turtle.place()
  158.         for i=5,16,1 do
  159.             turtle.select(i)
  160.             turtle.drop()
  161.         end
  162.         turtle.select(1)
  163.         turtle.dig()
  164.     end
  165. end
  166. function writeArrayFile(array,file)
  167.     local file = fs.open("Data/"..file,"w")
  168.     for i=1,#array,1 do
  169.             file.writeLine(array[i])
  170.     end
  171.     file.close()
  172. end
  173. function changeDirectionL()
  174.     turtleData = {}
  175.     load(turtleDataFile,turtleData)
  176.     turtle.turnLeft()
  177.     if turtleData[3] == "1" then
  178.         table.remove(turtleData,3)
  179.         table.insert(turtleData,3,"4")
  180.         writeArrayFile(turtleData,turtleDataFile)
  181.     elseif turtleData[3] == "2" then
  182.         table.remove(turtleData,3)
  183.         table.insert(turtleData,3,"1")
  184.         writeArrayFile(turtleData,turtleDataFile)
  185.     elseif turtleData[3] == "3" then
  186.         table.remove(turtleData,3)
  187.         table.insert(turtleData,3,"2")
  188.         writeArrayFile(turtleData,turtleDataFile)
  189.     elseif turtleData[3] == "4" then
  190.         table.remove(turtleData,3)
  191.         table.insert(turtleData,3,"3")
  192.         writeArrayFile(turtleData,turtleDataFile)
  193.     end
  194. end
  195.  
  196. function changeDirectionR()
  197.     turtleData= {}
  198.     load(turtleDataFile,turtleData)
  199.     turtle.turnRight()
  200.     if turtleData[3] == "1" then
  201.         table.remove(turtleData,3)
  202.         table.insert(turtleData,3,"2")
  203.         writeArrayFile(turtleData,turtleDataFile)
  204.     elseif turtleData[3] == "2" then
  205.         table.remove(turtleData,3)
  206.         table.insert(turtleData,3,"3")
  207.         writeArrayFile(turtleData,turtleDataFile)
  208.     elseif turtleData[3] == "3" then
  209.         table.remove(turtleData,3)
  210.         table.insert(turtleData,3,"4")
  211.         writeArrayFile(turtleData,turtleDataFile)
  212.     elseif turtleData[3] == "4" then
  213.         table.remove(turtleData,3)
  214.         table.insert(turtleData,3,"1")
  215.         writeArrayFile(turtleData,turtleDataFile)
  216.     end
  217. end
  218.  
  219. function override(array,file,position,move)     --Change one line of a file
  220.     array = {}
  221.     load(file,array)
  222.     local x = array[tonumber(position)] + tonumber(move)
  223.     table.remove(array,position)
  224.     table.insert(array,position,x)
  225.     local file = fs.open("Data/"..file,"w")
  226.     for i=1,#array,1 do
  227.             file.writeLine(array[i])
  228.     end
  229.     file.close()
  230. end
  231.  
  232. function walking(facing)
  233.     if facing == "1" then
  234.         while true do
  235.             if turtle.forward() == true then
  236.                 break
  237.             elseif turtle.dig() == true then
  238.                 turtle.dig()
  239.             end
  240.         end
  241.         override(turtleActivity,turtleActivityFile,"3","-1")
  242.         override(turtleData,turtleDataFile,"2","-1")
  243.     end
  244.    
  245.     if facing == "2" then
  246.         while true do
  247.             if turtle.forward() == true then
  248.                 break
  249.             elseif turtle.dig() == true then
  250.                 turtle.dig()
  251.             end
  252.         end
  253.  
  254.         override(turtleActivity,turtleActivityFile,"2","1")
  255.         override(turtleData,turtleDataFile,"1","1")
  256.     end
  257.    
  258.     if facing == "3" then
  259.         while true do
  260.             if turtle.forward() == true then
  261.                 break
  262.             elseif turtle.dig() == true then
  263.                 turtle.dig()
  264.             end
  265.         end
  266.  
  267.         override(turtleActivity,turtleActivityFile,"3","1")
  268.         override(turtleData,turtleDataFile,"2","1")
  269.     end
  270.     if facing == "4" then
  271.         while true do
  272.             if turtle.forward() == true then
  273.                 break
  274.             elseif turtle.dig() == true then
  275.                 turtle.dig()
  276.             end
  277.         end
  278.  
  279.         override(turtleActivity,turtleActivityFile,"2","-1")
  280.         override(turtleData,turtleDataFile,"1","-1")
  281.     end
  282. end
  283.  
  284. function newH2()
  285.     turtleActivity = {}
  286.     load(turtleActivityFile,turtleActivity)
  287.     turtleData = {}
  288.     load(turtleDataFile,turtleData)
  289.     turtleActivity = {}
  290.     load(turtleActivityFile,turtleActivity)
  291.    
  292.     while true do
  293.         turtleData = {}
  294.         load(turtleDataFile,turtleData)
  295.         turtleActivity = {}
  296.         load(turtleActivityFile,turtleActivity)
  297.         print(turtleActivity[2])
  298.         if tostring(turtleActivity[2]) == "0.0" then
  299.             break
  300.         end
  301.        
  302.         if tostring(turtleActivity[2]) > "0" then
  303.             turtleData = {}
  304.             load(turtleDataFile,turtleData)
  305.             while tostring(turtleData[3]) ~= "4" do
  306.                 changeDirectionR()
  307.                 turtleData = {}
  308.                 load(turtleDataFile,turtleData)
  309.             end
  310.             turtleData = {}
  311.             load(turtleDataFile,turtleData)
  312.             walking(turtleData[3])
  313.         end
  314.        
  315.         if tostring(turtleActivity[2]) < "0" then
  316.             while tostring(turtleData[3]) ~= "2" do
  317.                 changeDirectionR()
  318.                 turtleData = {}
  319.                 load(turtleDataFile,turtleData)
  320.             end
  321.             turtleData = {}
  322.             load(turtleDataFile,turtleData)
  323.             walking(turtleData[3])
  324.         end
  325.     end
  326.    
  327.     while true do
  328.         turtleData = {}
  329.         load(turtleDataFile,turtleData)
  330.         turtleActivity = {}
  331.         load(turtleActivityFile,turtleActivity)
  332.         print(turtleActivity[2])
  333.         if tostring(turtleActivity[3]) == "0.0" then
  334.             turtleData = {}
  335.             load(turtleDataFile,turtleData)
  336.             while tostring(turtleData[3]) ~= turtleData[5] do
  337.                 changeDirectionR()
  338.                 turtleData = {}
  339.                 load(turtleDataFile,turtleData)
  340.             end
  341.             break
  342.         end
  343.        
  344.         if tostring(turtleActivity[3]) > "0" then
  345.             turtleData = {}
  346.             load(turtleDataFile,turtleData)
  347.             while tostring(turtleData[3]) ~= "1" do
  348.                 changeDirectionR()
  349.                 turtleData = {}
  350.                 load(turtleDataFile,turtleData)
  351.             end
  352.             turtleData = {}
  353.             load(turtleDataFile,turtleData)
  354.             walking(turtleData[3])
  355.         end
  356.        
  357.         if tostring(turtleActivity[3]) < "0" then
  358.             while tostring(turtleData[3]) ~= "3" do
  359.                 changeDirectionR()
  360.                 turtleData = {}
  361.                 load(turtleDataFile,turtleData)
  362.             end
  363.             turtleData = {}
  364.             load(turtleDataFile,turtleData)
  365.             walking(turtleData[3])
  366.         end
  367.     end
  368. end
  369.     --CODE
  370.    
  371.     --VOID START
  372.  
  373. fs.makeDir("Data") 
  374. createFile(turtleDataFile)
  375. createFile(turtleModemFile)
  376. createFile(overseerIDFile)
  377. createFile(trashBlockFile)
  378. createFile(trackingBlockFile)
  379. createFile(turtleActivityFile)
  380.  
  381. load(turtleDataFile,turtleData)
  382. load(turtleModemFile,turtleModem)
  383. load(overseerIDFile,overseerID)
  384. load(trashBlockFile,trashBlock)
  385. load(trackingBlockFile,trackingBlock)
  386. load(turtleActivityFile,turtleActivity)
  387.  
  388.     --FIRST TIME SETUP
  389. --TURTLE DATA
  390.  
  391. turtleData = {}
  392. load(turtleDataFile,turtleData)
  393. if turtleData[1] == nil then                    --TurtleData first time installation
  394.  
  395.     while true do                               --Turtles X Coordinate
  396.         resetScreen()
  397.         term.write("What is the turtles X Coordinate?")
  398.         term.setCursorPos(1,2)
  399.         term.write("X: ")
  400.         local x = read()
  401.         highlighted = 1
  402.         stringQuestionAsked = "Is the X Coordinate really: "..x.."?"
  403.         choices ={"Yes it is","No it's not"}
  404.         Menu()
  405.         if choices[1] == chosenOne then
  406.             table.insert(turtleData,1,x)
  407.             break
  408.         end
  409.     end
  410.    
  411.     while true do                               --Turtles Z Coordinate
  412.         resetScreen()
  413.         term.write("What is the turtles Z Coordinate?")
  414.         term.setCursorPos(1,2)
  415.         term.write("Z: ")
  416.         local x = read()
  417.         stringQuestionAsked = "Is the Z Coordinate really: "..x.."?"
  418.         highlighted = 1
  419.         Menu()
  420.         if choices[1] == chosenOne then
  421.             table.insert(turtleData,2,x)
  422.             break
  423.         end
  424.     end
  425.    
  426.     while true do                               --Turtles Rotation
  427.         resetScreen()
  428.         stringQuestionAsked = "Which way is the turtle Facing?"
  429.         choices = {"North","East","South","West"}
  430.         highlighted = 1
  431.         Menu()
  432.         local x = chosenOne
  433.         stringQuestionAsked = "You sure the turtle is facing "..x.."?"
  434.         choices = {"Yes I am","No I'm not"}
  435.         highlighted = 1
  436.         Menu()
  437.         if choices[1] == chosenOne then
  438.             if x == "North" then
  439.                 x = "1"
  440.             elseif x == "East" then
  441.                 x = "2"
  442.             elseif x == "South" then
  443.                 x = "3"
  444.             elseif x == "West" then
  445.                 x = "4"
  446.             end
  447.            
  448.             table.insert(turtleData,3,x)
  449.             break
  450.         end
  451.     end
  452.    
  453.     table.insert(turtleData,4,"0")              --Turtle Holes
  454.     table.insert(turtleData,5,turtleData[3])
  455.     local file = fs.open("Data/"..turtleDataFile,"a")
  456.     for i=1, #turtleData, 1 do
  457.         file.writeLine(turtleData[i])
  458.     end
  459.     file.close()
  460.    
  461. end
  462.  
  463. --TURTLE WIRELESS MODEM SIDE
  464.  
  465. turtleModem = {}
  466. load(turtleModemFile,turtleModem)
  467. if turtleModem[1] == nil then
  468.     resetScreen()
  469.     print("On which side is the Wireless Modem of the turtle from the turtles Perspective?")
  470.     os.sleep(8)
  471.     stringQuestionAsked = "Where is the Wireless Modem"
  472.     choices = {"left","right"}
  473.     Menu()
  474.     local file = fs.open("Data/"..turtleModemFile,"a")
  475.     file.writeLine(chosenOne)
  476.     file.close()
  477. end
  478.  
  479.  
  480. --OVERSEER IDS
  481.  
  482. overseerID = {}
  483. load(overseerIDFile,overseerID)
  484. if overseerID[1] == nil then
  485.     while true do
  486.         resetScreen()
  487.         term.write("What is the overseer's ID?")
  488.         term.setCursorPos(1,2)
  489.         term.write("Command: os.getComputerID()")
  490.         term.setCursorPos(1,3)
  491.         term.write("ID: ")
  492.         local x = read()
  493.         stringQuestionAsked = "Are you sure this is the ID "..x.."?"
  494.         choices = {"Yes I am","No I'm not"}
  495.         highlighted = 1
  496.         Menu()
  497.         if choices[1] == chosenOne then
  498.         local add = true
  499.         load(overseerIDFile,overseerID)
  500.             for i=1, #overseerID, 1 do
  501.                 if x == overseerID[i] then
  502.                     add = false
  503.                 end
  504.             end
  505.             if add == true then
  506.                 local file = fs.open("Data/"..overseerIDFile,"a")
  507.                 file.writeLine(x)
  508.                 file.close()
  509.             else
  510.                 resetScreen()
  511.                 term.write("That Overseer has already been added")
  512.                 os.sleep(1)
  513.             end
  514.             stringQuestionAsked = "Do you want to add another overseer?"
  515.             choices = {"Yes I do","No I don't"}
  516.             highlighted = 1
  517.             Menu()
  518.             if choices[2] == chosenOne then
  519.                 break
  520.             end
  521.         end
  522.     end
  523. end
  524.  
  525. --TRASHBLOCKS
  526.  
  527. trashBlock = {}
  528. load(trashBlockFile,trashBlock)
  529. if trashBlock[1] == nil then
  530.     while true do
  531.         stringQuestionAsked = "Add a new Block to ignore"
  532.         choices = {"Type in Code","Place block in front","Banned Blocks","Quit","Tutorial [start]"}
  533.         highlighted = 1
  534.         Menu()
  535.        
  536.         if choices[1] == chosenOne then             --Type in Code
  537.             while true do
  538.                 resetScreen()
  539.                 print("Type in the code of the Block")
  540.                 print("for example minecraft:stone")
  541.                 term.write("Code: ")
  542.                 local x = read()
  543.                 stringQuestionAsked = "Is "..x.." correct?"
  544.                 choices = {"Yes it is", "No it isn't"}
  545.                 highlighted = 1
  546.                 Menu()
  547.                 if choices[1] == chosenOne then
  548.                     local add = true
  549.                     trashBlock = {}
  550.                     load(trashBlockFile,trashBlock)
  551.                     for i = 1,#trashBlock,1 do
  552.                         if trashBlock[i] == x then
  553.                             add = false
  554.                         end
  555.                     end
  556.                     if add == true then
  557.                         local file = fs.open("Data/"..trashBlockFile,"a")
  558.                         file.writeLine(x)
  559.                         file.close()
  560.                         resetScreen()
  561.                         print(x.." won't get mined any more.")
  562.                         os.sleep(2)
  563.                     else
  564.                         resetScreen()
  565.                         term.write("That Block has already been added")
  566.                         os.sleep(2)
  567.                     end
  568.                     break
  569.                 end
  570.             end
  571.            
  572.         elseif choices[2] == chosenOne then         --Place a Block in front of turtle
  573.             while true do
  574.                 success, data = turtle.inspect()
  575.                 if data.name == nil then
  576.                     resetScreen()
  577.                     print("You have to place a Block in front of the turtle before starting this function!")
  578.                     os.sleep(3)
  579.                     break
  580.                 end
  581.                 stringQuestionAsked = "Is "..data.name.." correct?"
  582.                 choices = {"Yes it is", "No it isn't"}
  583.                 highlighted = 1
  584.                 Menu()
  585.                 if choices[1] == chosenOne then
  586.                     local add = true
  587.                     trashBlock = {}
  588.                     load(trashBlockFile,trashBlock)
  589.                     for i = 1,#trashBlock,1 do
  590.                         if trashBlock[i] == data.name then
  591.                             add = false
  592.                         end
  593.                     end
  594.                     if add == true then
  595.                         local file = fs.open("Data/"..trashBlockFile,"a")
  596.                         file.writeLine(data.name)
  597.                         file.close()
  598.                         resetScreen()
  599.                         print(data.name.." won't get mined any more.")
  600.                         os.sleep(2)
  601.                         break
  602.                     else
  603.                         resetScreen()
  604.                         term.write("That Block has already been added")
  605.                         os.sleep(2)
  606.                         break
  607.                     end
  608.                 end
  609.             end
  610.            
  611.         elseif choices[3] == chosenOne then         --Remove Block from List
  612.             removed = 0
  613.             trashBlock = {}
  614.             newTrashBlock = {}
  615.             load(trashBlockFile,trashBlock)
  616.             for m=1,#trashBlock,1 do
  617.                 table.insert(newTrashBlock,m,trashBlock[m])
  618.             end
  619.             for i=1,#trashBlock do
  620.                 stringQuestionAsked = "Remove "..trashBlock[i].."?"
  621.                 choices = {"Yes I will","No I won't"}
  622.                 highlighted = 2
  623.                 Menu()
  624.                 if choices[1] == chosenOne then
  625.                     table.remove(newTrashBlock,i-removed)
  626.                     removed = removed + 1
  627.                 end
  628.             end
  629.             trashBlock = newTrashBlock
  630.             local file = fs.open("Data/"..trashBlockFile,"w")
  631.             for n=1,#trashBlock,1 do
  632.                 file.writeLine(trashBlock[n])
  633.             end
  634.             file.close()
  635.            
  636.         elseif choices[4] == chosenOne then         --Quit
  637.         trashBlock = {}
  638.         load(trashBlockFile,trashBlock)
  639.             if trashBlock[1] == nil then
  640.                 local file = fs.open("Data/"..trashBlockFile,"a")
  641.                 file.writeLine(1)
  642.                 file.close()
  643.             end
  644.             break
  645.            
  646.         elseif choices[5] == chosenOne then         --Tutorial
  647.             while true do
  648.                 stringQuestionAsked = "Tutorial"
  649.                 choices = {"Type in Code","Place block in front","Banned Blocks","Quit","Tutorial [stop]"}
  650.                 highlighted = 1
  651.                 Menu()
  652.                 if choices[1] == chosenOne then
  653.                     resetScreen()
  654.                     print("Type in Code:")
  655.                     print("You will be able to type in a code id for any block in the game that the turtle is not supposed to mine. You will have to know the Code though. For example minecraft:stone for stone.")
  656.                     os.sleep(8)
  657.                 elseif choices[2] == chosenOne then
  658.                     resetScreen()
  659.                     print("Place block in front:")
  660.                     print("First Place the Block you want to add in front of the Turtle then Select this Button. This will add that Block to the list of Blocks that it won't mine")
  661.                     os.sleep(4)
  662.                 elseif choices[3] == chosenOne then
  663.                     resetScreen()
  664.                     print("Let's you remove previously added Blocks")
  665.                     os.sleep(2)
  666.                 elseif choices[4] == chosenOne then
  667.                     resetScreen()
  668.                     print("Quit:")
  669.                     term.write("Quits the Add new Block Menu")
  670.                     os.sleep(3)
  671.                 elseif choices[5] == chosenOne then
  672.                     print("Banned Blocks:")
  673.                     print("Displays a list of all of the Blocks that have been banned by the system")
  674.                     os.sleep(3)
  675.                 elseif choices[5] == chosenOne then
  676.                     break
  677.                 end
  678.             end
  679.         end
  680.        
  681.     end
  682. end
  683.  
  684. --TRACKING BLOCKS
  685.  
  686. trackingBlock = {}
  687. load(trackingBlockFile,trackingBlock)
  688. if trackingBlock[1] == nil then
  689.     while true do
  690.         stringQuestionAsked = "Add a new Block to track"
  691.         choices = {"Type in Code","Place block in front","Tracked Blocks","Quit"}
  692.         highlighted = 1
  693.         Menu()
  694.        
  695.         if choices[1] == chosenOne then             --Type in Code
  696.             while true do
  697.                 trackingBlock = {}
  698.                 load(trackingBlockFile,trackingBlock)
  699.                 if trackingBlock[1] ~= nil then
  700.                     resetScreen()
  701.                     term.write("You can only Track one Block")
  702.                     os.sleep(5)
  703.                     break
  704.                 end
  705.                 resetScreen()
  706.                 print("Type in the code of the Block")
  707.                 print("for example minecraft:diamond_ore")
  708.                 term.write("Code: ")
  709.                 local x = read()
  710.                 stringQuestionAsked = "Is "..x.." correct?"
  711.                 choices = {"Yes it is", "No it isn't"}
  712.                 highlighted = 1
  713.                 Menu()
  714.                 if choices[1] == chosenOne then
  715.                     local add = true
  716.                     trackingBlock = {}
  717.                     load(trackingBlockFile,trackingBlock)
  718.                     for i = 1,#trackingBlock,1 do
  719.                         if trackingBlock[i] == x then
  720.                             add = false
  721.                         end
  722.                     end
  723.                     if add == true then
  724.                         local file = fs.open("Data/"..trackingBlockFile,"a")
  725.                         file.writeLine(x)
  726.                         file.close()
  727.                         resetScreen()
  728.                         print(x.." will be tracked")
  729.                         os.sleep(2)
  730.                     else
  731.                         resetScreen()
  732.                         term.write("That Block has already been added")
  733.                         os.sleep(2)
  734.                     end
  735.                     break
  736.                 end
  737.             end
  738.            
  739.         elseif choices[2] == chosenOne then         --Place a Block in front of turtle
  740.             while true do
  741.                 trackingBlock = {}
  742.                 load(trackingBlockFile,trackingBlock)
  743.                 if trackingBlock[1] ~= nil then
  744.                     resetScreen()
  745.                     term.write("You can only Track one Block")
  746.                     os.sleep(5)
  747.                     break
  748.                 end
  749.                 success, data = turtle.inspect()
  750.                 if data.name == nil then
  751.                     resetScreen()
  752.                     print("You have to place a Block in front of the turtle before starting this function!")
  753.                     os.sleep(3)
  754.                     break
  755.                 end
  756.                 stringQuestionAsked = "Is "..data.name.." correct?"
  757.                 choices = {"Yes it is", "No it isn't"}
  758.                 highlighted = 1
  759.                 Menu()
  760.                 if choices[1] == chosenOne then
  761.                     local add = true
  762.                     trackingBlock = {}
  763.                     load(trackingBlockFile,trackingBlock)
  764.                     for i = 1,#trackingBlock,1 do
  765.                         if trackingBlock[i] == data.name then
  766.                             add = false
  767.                         end
  768.                     end
  769.                     if add == true then
  770.                         local file = fs.open("Data/"..trackingBlockFile,"a")
  771.                         file.writeLine(data.name)
  772.                         file.close()
  773.                         resetScreen()
  774.                         print(data.name.." will be tracked.")
  775.                         os.sleep(2)
  776.                         break
  777.                     else
  778.                         resetScreen()
  779.                         term.write("That Block has already been added")
  780.                         os.sleep(2)
  781.                         break
  782.                     end
  783.                 end
  784.             end
  785.            
  786.         elseif choices[3] == chosenOne then         --Remove Block from List
  787.             removed = 0
  788.             trackingBlock = {}
  789.             newTrackingBlock = {}
  790.             load(trackingBlockFile,trackingBlock)
  791.             for m=1,#trackingBlock,1 do
  792.                 table.insert(newTrackingBlock,m,trackingBlock[m])
  793.             end
  794.             for i=1,#trackingBlock do
  795.                 stringQuestionAsked = "Remove "..trackingBlock[i].."?"
  796.                 choices = {"Yes I will","No I won't"}
  797.                 highlighted = 2
  798.                 Menu()
  799.                 if choices[1] == chosenOne then
  800.                     table.remove(newTrackingBlock,i-removed)
  801.                     removed = removed + 1
  802.                 end
  803.             end
  804.             trackingBlock = newTrackingBlock
  805.             local file = fs.open("Data/"..trackingBlockFile,"w")
  806.             for n=1,#trackingBlock,1 do
  807.                 file.writeLine(trackingBlock[n])
  808.             end
  809.             file.close()
  810.            
  811.         elseif choices[4] == chosenOne then         --Quit
  812.         trackingBlock = {}
  813.         load(trackingBlockFile,trackingBlock)
  814.             if trackingBlock[1] == nil then
  815.                 local file = fs.open("Data/"..trackingBlockFile,"a")
  816.                 file.writeLine(1)
  817.                 file.close()
  818.             end
  819.             break
  820.         end
  821.     end
  822. end
  823.  
  824. trackingBlock = {}
  825. load(trackingBlockFile,trackingBlock)
  826. if trackingBlock[2] == nil then
  827.     local file = fs.open("Data/"..trackingBlockFile,"a")
  828.     file.writeLine("0")
  829.     file.close()
  830. end
  831. turtleActivity = {}
  832. load(turtleActivityFile,turtleActivity)
  833. if turtleActivity[1] == nil then
  834.     local file = fs.open("Data/"..turtleActivityFile,"a")
  835.     file.writeLine("start")
  836.     file.close()
  837. end
  838. --CODE
  839. while true do
  840.     encodeMinerSend()
  841.     turtleActivity = {}
  842.     load(turtleActivityFile,turtleActivity)
  843.     if turtleActivity[1] == "start" then
  844.         if turtle.detectUp() == true then
  845.             turtle.digUp()
  846.         end
  847.         turtle.select(1)
  848.         turtle.placeUp()
  849.         refuel()
  850.         space()
  851.         local file = fs.open("Data/"..turtleActivityFile,"w")
  852.         file.writeLine("digD")
  853.         file.close()
  854.     end
  855.     turtleActivity = {}
  856.     load(turtleActivityFile,turtleActivity)
  857.     if turtleActivity[1] == "digD" then
  858.         while true do
  859.             success, data = turtle.inspectDown()
  860.             if data.name == "minecraft:bedrock" then
  861.                 local file = fs.open("Data/"..turtleActivityFile,"w")
  862.                 file.writeLine("digU")
  863.                 file.close()
  864.                 break
  865.             end
  866.             load(trackingBlockFile,trackingBlock)
  867.             if data.name == trackingBlock[1] then
  868.                 local x = tonumber(trackingBlock[2]) + 1
  869.                 local file = fs.open("Data/"..trackingBlockFile,"w")
  870.                 file.writeLine(trackingBlock[1])
  871.                 file.writeLine(tostring(x))
  872.                 file.close()
  873.                 encodeMinerSend()
  874.             end
  875.             turtle.digDown()
  876.             turtle.down()
  877.             space()
  878.             refuel()
  879.             encodeMinerSend()
  880.         end
  881.     end
  882.     turtleActivity = {}
  883.     load(turtleActivityFile,turtleActivity)
  884.     if turtleActivity[1] == "digU" then
  885.         while true do
  886.             trackingBlock = {}
  887.             load(trackingBlockFile,trackingBlock)
  888.             trashBlock = {}
  889.             load(trashBlockFile,trashBlock)
  890.             success, data = turtle.inspectUp()
  891.             if data.name == "ChickenChunks:chickenChunkLoader" then
  892.                 local file = fs.open("Data/"..turtleActivityFile,"w")
  893.                 file.writeLine("newH1")
  894.                 file.close()
  895.                 if turtle.getItemCount(3) > 1 then
  896.                     turtle.select(3)
  897.                     turtle.placeDown()
  898.                     turtle.select(1)
  899.                 end
  900.                 turtleData = {}
  901.                 load(turtleDataFile,turtleData)
  902.                 while tostring(turtleData[3]) ~= turtleData[5] do
  903.                     changeDirectionL()
  904.                     turtleData = {}
  905.                     load(turtleDataFile,turtleData)
  906.                 end
  907.                 turtleData = {}
  908.                 load(turtleDataFile,turtleData)
  909.                 override(turtleData,turtleDataFile,4,1)
  910.                 break
  911.             end
  912.             for i=1,4,1 do
  913.                 local mine = "true"
  914.                 success, data = turtle.inspect()
  915.                 if data.name == trackingBlock[1] then
  916.                     local x = tonumber(trackingBlock[2]) + 1
  917.                     local file = fs.open("Data/"..trackingBlockFile,"w")
  918.                     file.writeLine(trackingBlock[1])
  919.                     file.writeLine(tostring(x))
  920.                     file.close()
  921.                     encodeMinerSend()
  922.                     mine = "true"
  923.                 end
  924.                 for n=1,#trashBlock,1 do
  925.                     success, data = turtle.inspect()
  926.                     if data.name == trashBlock[n] then
  927.                         mine = "false"
  928.                     end
  929.                 end
  930.                 if mine == "true" then
  931.                     turtle.dig()
  932.                     space()
  933.                 end
  934.                 turtle.turnLeft()
  935.             end
  936.             turtle.up()
  937.             refuel()
  938.         end
  939.     end
  940.     turtleActivity = {}
  941.     load(turtleActivityFile,turtleActivity)
  942.     if turtleActivity[1] == "newH1" and turtleActivity[2] == nil then
  943.         local file = fs.open("Data/"..turtleActivityFile,"a")
  944.         file.writeLine(0)       --X
  945.         file.writeLine(0)       --Z
  946.         file.close()
  947.     elseif turtleActivity[1] == "newH1" and turtleActivity[2] ~= nil then
  948.         print("Hello")
  949.         newH2()
  950.     end
  951.     turtleActivity = {}
  952.     load(turtleActivityFile,turtleActivity)
  953.     if turtleActivity[1] == "newH1" then
  954.         turtleData = {}
  955.         load(turtleDataFile,turtleData)
  956.         walking(turtleData[3])
  957.         encodeMinerSend()
  958.         changeDirectionR()
  959.         turtleData = {}
  960.         load(turtleDataFile,turtleData)
  961.         walking(turtleData[3])
  962.         encodeMinerSend()
  963.         turtleData = {}
  964.         load(turtleDataFile,turtleData)
  965.         walking(turtleData[3])
  966.         encodeMinerSend()
  967.         turtle.select(1)
  968.         turtle.digUp()
  969.         turtle.placeUp()
  970.         changeDirectionL()
  971.         turtleActivity = {}
  972.         load(turtleActivityFile,turtleActivity)
  973.         table.remove(turtleActivity,1)
  974.         table.insert(turtleActivity,1,"newH2")
  975.         local file = fs.open("Data/"..turtleActivityFile,"w")
  976.         for i=1,#turtleActivity,1 do
  977.             file.writeLine(turtleActivity[i])
  978.         end
  979.         file.close()
  980.     end
  981.     turtleActivity = {}
  982.     load(turtleActivityFile,turtleActivity)
  983.     if turtleActivity[1] == "newH2" then
  984.         newH2()
  985.         turtle.digUp()
  986.         turtleActivity = {}
  987.         load(turtleActivityFile,turtleActivity)
  988.         table.remove(turtleActivity,1)
  989.         table.insert(turtleActivity,1,"newH3")
  990.         local file = fs.open("Data/"..turtleActivityFile,"w")
  991.         file.writeLine(turtleActivity[1])
  992.         file.close()
  993.     end
  994.     turtleActivity = {}
  995.     load(turtleActivityFile,turtleActivity)
  996.     if turtleActivity[1] == "newH3" and turtleActivity[3] == nil then
  997.         local file = fs.open("Data/"..turtleActivityFile,"a")
  998.         file.writeLine(0)       --X
  999.         file.writeLine(0)       --Z
  1000.         file.close()
  1001.     elseif turtleActivity[1] == "newH3" and turtleActivity[3] ~= nil then
  1002.         newH2()
  1003.     end
  1004.    
  1005.     turtleActivity = {}
  1006.     load(turtleActivityFile,turtleActivity)
  1007.     if turtleActivity[1] == "newH3" then
  1008.         turtleData = {}
  1009.         load(turtleDataFile,turtleData)
  1010.         walking(turtleData[3])
  1011.         encodeMinerSend()
  1012.         changeDirectionR()
  1013.         turtleData = {}
  1014.         load(turtleDataFile,turtleData)
  1015.         walking(turtleData[3])
  1016.         encodeMinerSend()
  1017.         turtleData = {}
  1018.         load(turtleDataFile,turtleData)
  1019.         walking(turtleData[3])
  1020.         encodeMinerSend()
  1021.         turtleActivity = {}
  1022.         load(turtleActivityFile,turtleActivity)
  1023.         table.remove(turtleActivity,1)
  1024.         table.insert(turtleActivity,1,"digD")
  1025.         local file = fs.open("Data/"..turtleActivityFile,"w")
  1026.         file.writeLine(turtleActivity[1])
  1027.         file.close()
  1028.     end
  1029. end
  1030.  
  1031. --next Step send to overseer
  1032. --then start digging first hole whilest updating stats and sending to overseer
  1033. --then create more scripts to reset overseer ID's, Everything, trackingBlocks, trackedBlockes, trashBlocks
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement