Advertisement
guitarplayer616

testing it WORKS

Jan 8th, 2017
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.79 KB | None | 0 0
  1. --no pastebin? no problem!
  2. --fs.open("setup","w").write(http.post("http://pastebin.com/raw/8Th5VpE5").readAll())
  3.  
  4. local tArgs = {...}
  5. --local filename
  6.  
  7. function get(name,address)
  8.     local response = nil
  9.     local tmp = fs.open(name,"w")
  10.     local function setColor(color)
  11.         if term.isColor() then
  12.             term.setTextColor(color)
  13.         end
  14.     end
  15.     setColor(colors.yellow)
  16.     if address:sub(1,4) == "http" then
  17.         write("Connecting to Github.com... ")
  18.         response = http.get(address)
  19.     else
  20.         write("Connecting to Pastebin.com... ")
  21.         response = http.get("http://pastebin.com/raw/"..tostring(address))
  22.     end
  23.     if response then
  24.         setColor(colors.green)
  25.         print("Success")
  26.         tmp.write( response.readAll() )
  27.         tmp.close()
  28.         setColor(colors.white)
  29.         return true
  30.     else
  31.         setColor(colors.red)
  32.         print("Failed")
  33.         setColor(colors.white)
  34.         return false
  35.     end
  36. end
  37.  
  38. if tArgs[1] == "download" or tArgs[1] == "dl" then
  39.     get("market","BztihKh3")
  40.     get("refill","cds0sp3C")
  41.     get("time","6zRMTLyF")
  42.     get("turtle","7mnsWVwz")
  43.     get("blueprint","kQ7xueqL")
  44.     get("simulate","Th40FmCz")
  45.     get("multisetup","y7t1FUbY")
  46.     return
  47. else
  48.     assert(tArgs[1],"no tArgs[1]")
  49.     if not fs.exists(tArgs[1]) then
  50.         error("File non existent")
  51.     end
  52. end
  53.  
  54. if not fs.exists("turtle") then
  55.     error("dont forget to dl the api skrub")
  56. end
  57.     --shell.run("turtle reset")
  58.  
  59. function file2table(filename)
  60.     local h = fs.open(filename,"r")
  61.     local sOutput = h.readAll()
  62.     sOutput = textutils.unserialize(sOutput)
  63.     h.close()
  64.     return sOutput
  65. end
  66.  
  67. --slots = textutils.unserialize(fs.open("slots","r").readAll())
  68.  
  69.  
  70.  
  71. --  dynamic method  --
  72.  
  73. function recordStep(n)
  74.     local h = fs.open("nObjective",'w')
  75.     h.writeLine("nObjective = "..tostring(n))
  76.     h.close()
  77. end
  78.  
  79. --  deprecated  --
  80.  
  81.  
  82. local startup = [[
  83.    
  84. --  reference  --
  85.  
  86.     shell.run("]]..tostring(tArgs[1])..[[")
  87.     reference.filename = "]]..tostring(tArgs[1])..[["
  88.  
  89. --  startup  --
  90.  
  91.     shell.run("turtle") --runs position
  92.     shell.run("nObjective")
  93.     shell.run("time")
  94.  
  95.     --if nObjective <= #instructions then --goes to height on startup so it doesnt break other blocks
  96.         --could also try refilling first
  97.         local x,y,z,id,data = unpack(instructions[nObjective])
  98.         goto(reference.finalx+1,y,z)
  99.     --end
  100.    
  101.     local function setLine(n)
  102.         term.setCursorPos(1,n)
  103.         term.clearLine()
  104.         term.setCursorPos(1,n)
  105.     end
  106.    
  107.     local function setColor(c)
  108.         if term.isColor() then
  109.             term.setTextColor(c)
  110.         end
  111.     end
  112.  
  113.     local function a1()
  114.         while true do
  115.             --break and return when finished
  116.             if nObjective > #instructions then
  117.                 return true
  118.             end
  119.             --repeat
  120.             local x,y,z,id,data = unpack(instructions[nObjective])
  121.             goto(x+1,y,z)
  122.             findAndPlace(id,data,slots,reference.wrench)
  123.             nObjective = nObjective + 1
  124.             recordStep(nObjective)
  125.         end
  126.     end
  127.  
  128.     local function b1()
  129.         while true do
  130.             setLine(1)
  131.             setColor(colors.yellow)
  132.             term.write("CurrentPosition: ")
  133.             setColor(colors.white)
  134.             term.write(heightPos..","..widthPos..","..lengthPos..","..face)
  135.             setLine(2)
  136.             if nObjective > #instructions then
  137.                 return true
  138.             end
  139.             local id,data = unpack(instructions[nObjective],4,5)
  140.             local name,dmg = nil,nil
  141.             if slots[id] and slots[id][data] then
  142.                 name,dmg = unpack(slots[id][data])
  143.             end
  144.             setColor(colors.yellow)
  145.             term.write("NextBlock: ")
  146.             setColor(colors.white)
  147.             term.write(tostring(name)..","..tostring(dmg))
  148.             setLine(4)
  149.             local fuelCost,timeRemaining = estimate(nObjective,instructions,heightPos,widthPos,lengthPos)
  150.             setColor(colors.yellow)
  151.             term.write("Time Remaining: ")
  152.             setColor(colors.white)
  153.             term.write(formatTime(timeRemaining))
  154.             setLine(5)
  155.             setColor(colors.yellow)
  156.             term.write("fuelCost: ")
  157.             setColor(colors.white)
  158.             term.write(fuelCost)
  159.             setLine(6)
  160.             setColor(colors.yellow)
  161.             term.write("fuelLevel: ")
  162.             setColor(colors.white)
  163.             term.write(turtle.getFuelLevel())
  164.             sleep(0.4)
  165.         end
  166.     end
  167.  
  168.     parallel.waitForAny(a1,b1)
  169.  
  170.     shell.run("clr")
  171.     print("finished")
  172.     goto(reference.finalx+1,reference.returny,reference.returnz)
  173.     turn("south")
  174.     goto(reference.returnx,reference.returny,reference.returnz)
  175.  
  176.     shell.run("rm startup")
  177. ]]
  178.  
  179. local h = fs.open("startup","w")
  180. h.write(startup)
  181. h.close()
  182.  
  183. if fs.exists("time") then
  184.     shell.run(tArgs[1])
  185.     shell.run("time")
  186.     local fuelCost,timeRemaining = estimate(1,instructions,0,0,0)
  187.     print("Estimated Time: "..formatTime(timeRemaining))
  188.     print("Fuel Cost: "..fuelCost)
  189.     if fuelCost > turtle.getFuelLevel() then
  190.         error("requires at least"..tostring( tonumber(fuelCost)-turtle.getFuelLevel() ).." more fuel")
  191.     end
  192. end
  193. recordStep(1)
  194. shell.run("turtle")
  195. for i = 1,2 do
  196.     term.scroll(i)
  197.     sleep(0)
  198. end
  199. print("all set, reboot to start")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement