guitarplayer616

[Setup] schem turtle

Nov 25th, 2016
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.57 KB | None | 0 0
  1. --redownload apis
  2. --run apis
  3. --initiate variables
  4.  
  5. --temp ease of access
  6. local f = fs.open("update","w")
  7. f.write([[
  8. local tArgs = {...}
  9. if not tArgs[1] then
  10.     shell.run("pastebin run dS6WANii update")
  11. else
  12.     shell.run("pastebin run dS6WANii "..tArgs[1])
  13. end
  14. ]])
  15. f.close()
  16.  
  17.  
  18.  
  19. --make sure gzip is equipped
  20. tArgs = {...}
  21. if #tArgs ~= 1 then
  22.     print("Usage: schemSetup <gunzipped schematic file>")
  23.     return
  24. end
  25.  
  26. --checkfuel
  27. if turtle.getFuelLevel() == 0 then
  28.         print("No Fuel")
  29.         error()
  30. elseif turtle.getFuelLevel() < 300 then
  31.         print("Low Fuel")
  32.         error()
  33. end
  34.  
  35. function checkWrench()
  36.     local wrench = false
  37.     local mem = turtle.getSelectedSlot()
  38.     turtle.select(14)
  39.     local item = turtle.getItemDetail()
  40.     if item then
  41.         if item.name == "ThermalExpansion:wrench" then
  42.             wrench = true
  43.         else
  44.             wrench = false
  45.         end
  46.     end
  47.     turtle.select(mem)
  48.     return wrench
  49. end
  50.  
  51. function checkTurtleType()
  52.     local advanced = term.isColor()
  53.     return advanced
  54. end
  55.  
  56. function schemAPIs(run)
  57.     --dl and run or just run or just update
  58.     if not fs.isDir("SchematicBuilder") then
  59.         fs.makeDir("SchematicBuilder")
  60.     else
  61.         for i,v in pairs(fs.list("SchematicBuilder")) do
  62.             fs.delete("SchematicBuilder/"..v)
  63.         end
  64.     end
  65.    
  66.     if run ~= "update" then
  67.         local deleteFiles = {"objective","reference","position","startup"}
  68.         for i,v in pairs(deleteFiles) do
  69.             if fs.exists(v) then
  70.                 fs.delete(v)
  71.             end
  72.         end
  73.     end
  74.    
  75.     local apis = {
  76.         GoTo = "1uYUQiJq",
  77.         GPS = "5LXAvfzN",
  78.         SchemParser = "wJ9GPnCP",
  79.         LocationFinder = "ywxA9gpq",
  80.         Refill = "VtrrSeWh",
  81.         Debug = "7kNZpAi6"
  82.     }
  83.  
  84.     for i,v in pairs(apis) do
  85.         if run ~= "run" then
  86.             shell.run("pastebin get "..v.." SchematicBuilder/"..i)
  87.         end
  88.         shell.run("SchematicBuilder/"..i)
  89.     end
  90. end
  91.  
  92. function deleteOldFiles()
  93.     if not fs.exists("reference") then
  94.       if fs.exists("position") then
  95.         fs.delete("position")
  96.       end
  97.       if fs.exists("objective") then
  98.         fs.delete("objective")
  99.       end
  100.     end
  101. end
  102.  
  103.  
  104. function copySetupVars()
  105.         local h = fs.open("reference",'w')
  106.         h.writeLine("slots = {}")
  107.         h.writeLine("filename = ".."\""..tostring(filename).."\"")
  108.         for i,v in pairs(slots) do
  109.                 h.writeLine("slots\["..i.."\] = {}")
  110.                 for i2,v2 in pairs(v) do
  111.                         h.writeLine("slots\["..i.."\]\["..i2.."\] = {}")
  112.                         for i3,v3 in pairs(v2) do
  113.                                 h.writeLine("slots\["..i.."\]\["..i2.."\]\["..i3.."\] = "..tostring(v3))
  114.                         end
  115.                 end
  116.         end
  117.         h.writeLine("invList = {}")
  118.         for i,v in pairs(invList) do
  119.                 h.writeLine("invList\["..i.."\] = {}")
  120.                 for i2,v2 in pairs(v) do
  121.                         h.writeLine("invList\["..i.."\]\[".."\""..i2.."\"".."\] = "..tostring(v2))
  122.                 end
  123.         end
  124.         h.writeLine("height = "..tostring(height))
  125.         h.writeLine("width = "..tostring(width))
  126.         h.writeLine("length = "..tostring(length))
  127.         h.writeLine("chestOrder = "..tostring(chestOrder))
  128.         h.writeLine("enderchest1 = "..tostring(enderchest1))
  129.         h.writeLine("enderchest2 = "..tostring(enderchest2))
  130.         h.writeLine("wrench = "..tostring(wrench))
  131.         h.writeLine("origDir = ".."\""..tostring(origDir).."\"")
  132.         h.writeLine("Hoff, Koff, Loff = "..tostring(Hoff)..", "..tostring(Koff)..", "..tostring(Loff))
  133.         h.writeLine("blocks = {}")
  134.         for i,v in pairs(blocks) do
  135.                 h.writeLine("blocks\["..i.."\] = "..tostring(v))
  136.         end
  137.  
  138.         h.writeLine("data = {}")
  139.         for i,v in pairs(data) do
  140.                 h.writeLine("data\["..i.."\] = "..tostring(v))
  141.         end
  142.      
  143.         h.close()
  144. end
  145.  
  146. function Initiate()
  147.     if tArgs[1] == "update" then
  148.         schemAPIs("update")
  149.         error()
  150.     end
  151.     deleteOldFiles()
  152.     schemAPIs()
  153.     --run new apis
  154.  
  155.     --current location
  156.     heightPos = -1
  157.     widthPos = 0
  158.     lengthPos = 0
  159.     face = "south"
  160.    
  161.     --current objective
  162.     x = 0
  163.     y = 0
  164.     z = 0
  165.  
  166.     --refill vars
  167.     enderchest1 = 15
  168.     enderchest2 = 16
  169.     chestOrder = 1
  170.  
  171.     --schematic vars
  172.     blocks = {}
  173.     data = {}
  174.  
  175.     --initialize if available
  176.     openRednet()
  177.     gpsSetup()
  178.     wrench = checkWrench()
  179.     isAdvanced = checkTurtleType() 
  180.  
  181.     --make sure schematic is good to go
  182.     filename = tArgs[1]
  183.  
  184.     if not fs.exists(filename) then
  185.           print("File does not exist.")
  186.           return
  187.     end
  188.  
  189.     handle = fs.open(filename, "rb")
  190.    
  191.     --corresponding item slots
  192.     shell.run("clr")
  193.     setup()
  194.  
  195.     --copy down entire environment
  196.     copySetupVars()
  197.  
  198.     if tArgs and tArgs[1]~="update" then
  199.         recordPos(-1,0,0,"south")
  200.         recordObj(x,y,z)
  201.         recordObjSlot(1)
  202.     else
  203.         shell.run("reference")
  204.         shell.run("position")
  205.         shell.run("objective")
  206.     end
  207.  
  208.     local h = fs.open("startup","w")
  209.     h.write([[
  210.     shell.run("reference")
  211.     local apis = {
  212.         GoTo = "1uYUQiJq",
  213.         GPS = "5LXAvfzN",
  214.         SchemParser = "wJ9GPnCP",
  215.         LocationFinder = "ywxA9gpq",
  216.         Refill = "VtrrSeWh",
  217.         Debug = "7kNZpAi6"
  218.     }
  219.     for i,v in pairs(apis) do
  220.         shell.run("SchematicBuilder/"..i)
  221.     end
  222.     openRednet()
  223.     checkIfRefill()
  224.     if gps.locate() then
  225.         gpsi = true
  226.     else
  227.         gpsi = false
  228.     end
  229.     resynchronize()
  230.     while true do
  231.         shell.run("position")
  232.         shell.run("objective")
  233.         shell.run("objectiveSlot")
  234.         goto(x,y,z)
  235.         findNextBlock(x,y,z)
  236.         checkIfAir()
  237.     end
  238.     shell.run("clr")
  239.     print("finished")
  240.     ]])
  241.     h.close()
  242. end
  243.  
  244. Initiate()
Add Comment
Please, Sign In to add comment