Advertisement
Guest User

Zos

a guest
Jan 24th, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.97 KB | None | 0 0
  1. local = arg{...}
  2. if arg[1] == nil then
  3.   print("no table to save")
  4.   return false
  5.   end
  6.  
  7. local of = io,open(drone,w)
  8. if of then
  9.   for n,sLineB in ipairs(arg[1]) do
  10.     of:write(sLineB)
  11.     print(sLineB)
  12.     of:write("\n")
  13.     end
  14.   of:close()
  15. else
  16.   print("error could not open file")
  17.   end
  18.  
  19. local args = {...}
  20. local dist = 1
  21. if args[1] then dist = tonumber(args[1]) end
  22. local i = 0
  23. local hit = false
  24. local hitc = 0
  25.  
  26. if not (dist > 0) then dist = 1 end
  27.  
  28. while i < dist do
  29. if turtle.up() then
  30.   i = i + 1
  31.  else
  32.   print("I hit Something")
  33.   sleep(1/4)
  34.   hitc = hitc + 1
  35.  end
  36. if hitc > dist/2 then
  37.   print("hit = "..hitc)
  38.   return false end
  39. end
  40.  
  41. return true
  42. local tfile = {}
  43.  
  44. function printtbl(tbl,comment)
  45. print("printtbl("..tostring(tbl).."["..#tbl.."],"..tostring(comment)..")")
  46. for i,j in ipairs(tbl) do
  47. print("tbl"..tostring(comment).."- "..i..","..j)
  48. end
  49. end
  50.  
  51. function load()
  52. b = io.open("drone","r")
  53. if b then
  54.   local sLine = b:read()
  55.   while sLine do
  56.     table.insert(tfile, sLine)
  57.     sLine = b:read()
  58.     end
  59.   b:close()
  60. end
  61. if #tfile == 0 then
  62.   table.insert(tfile, "")
  63.   end
  64. end
  65.  
  66. function save()
  67. d = io.open("drone","w")
  68. if d then
  69.     for n,sLineB in ipairs(tfile) do
  70.     d:write(sLineB)
  71.     print(sLineB)
  72.     d:write("\n")
  73.     end
  74.   end
  75. d:close()
  76. end
  77.  
  78. function updatePos()
  79. local x,y,z
  80. local oldx = tonumber(tfile[7])
  81. local oldy = tonumber(tfile[8])
  82. local oldz = tonumber(tfile[9])
  83. local gpx,gpy,gpz = gps.locate(2,true)
  84. if gpx then x = gpx else x = oldx end
  85. if gpy then y = gpy else y = oldy end
  86. if gpz then z = gpz else z = oldz end
  87. tfile[7] = tonumber(x)
  88. tfile[8] = tonumber(y)
  89. tfile[9] = tonumber(z)
  90. end
  91.  
  92. local args = {...}
  93. local dist = 1
  94. if args[1] then dist = tonumber(args[1]) end
  95. local i = 0
  96. local hit = false
  97. local hitc = 0
  98.  
  99. if not (dist > 0) then dist = 1 end
  100.  
  101. while i < dist do
  102. turtle.digUp()
  103. turtle.digDown()
  104. turtle.dig()
  105. if turtle.forward() then
  106.   i = i + 1
  107.  else
  108.   print("I hit Something")
  109.   sleep(1/4)
  110.   hitc = hitc + 1
  111.  end
  112. if hitc > dist/2 then
  113.   print("hit = "..hitc)
  114.   return false end
  115. end
  116.  
  117. turtle.digUp()
  118. turtle.digDown()
  119. return true
  120. local args = {...}
  121. local dist = 1
  122. if args[1] then dist = tonumber(args[1]) end
  123. local i = 0
  124. local hit = false
  125. local hitc = 0
  126.  
  127. if not (dist > 0) then dist = 1 end
  128.  
  129. while i < dist do
  130. if turtle.forward() then
  131.   i = i + 1
  132.  else
  133.   print("I hit Something")
  134.   sleep(1/4)
  135.   hitc = hitc + 1
  136.  end
  137. if hitc > dist/2 then
  138.   print("hit = "..hitc)
  139.   return false end
  140. end
  141.  
  142. return true
  143. local args = {...}
  144. local dist = 1
  145. if args[1] then dist = tonumber(args[1]) end
  146. local i = 0
  147. local hit = false
  148. local hitc = 0
  149.  
  150. if not (dist > 0) then dist = 1 end
  151.  
  152. while i < dist do
  153. if turtle.back() then
  154.   i = i + 1
  155.  else
  156.   print("I hit Something")
  157.   sleep(1/4)
  158.   hitc = hitc + 1
  159.  end
  160. if hitc > dist/2 then
  161.   print("hit = "..hitc)
  162.   return false end
  163. end
  164.  
  165. return true
  166. local tfile = {}
  167.  
  168. function load()
  169. b = io.open("drone","r")
  170. if b then
  171.   local sLine = b:read()
  172.   while sLine do
  173.     table.insert(tfile, sLine)
  174.     sLine = b:read()
  175.     end
  176.   b:close()
  177. end
  178. if #tfile == 0 then
  179.   table.insert(tfile, "")
  180.   end
  181. end
  182.  
  183. function save()
  184. d = io.open("drone","w")
  185. if d then
  186.     for n,sLineB in ipairs(tfile) do
  187.     d:write(sLineB)
  188.     print(sLineB)
  189.     d:write("\n")
  190.     end
  191.   end
  192. d:close()
  193. end
  194.  
  195. function updateFuel()
  196. local cur = turtle.getFuelLevel()
  197. local max = turtle.getFuelLimit()
  198. tfile[5] = "moves - "..tostring(cur)
  199. tfile[6] = "fuel - "..(cur/max*100).."%"
  200. end
  201.  
  202. load()
  203. updateFuel()
  204. save()
  205. local tfile = {}
  206.  
  207. function load()
  208.   a,b,c = os.run({tfile},"z/load")
  209.   print(a)
  210.   print(b)
  211.   print(c)
  212.   print(tfile)
  213.   for i,j in pairs(tfile) do
  214.     print(i..":"..j)
  215.     end
  216. end
  217.  
  218. function send()
  219. local msg = "{"..os.getComputerLabel().."}"
  220. for n,sLineB in ipairs(tfile) do
  221.   msg = msg.."{"..sLineB.."}"
  222.   end
  223. rednet.broadcast(msg)
  224. end
  225.  
  226. load()
  227. send()
  228. local args = {...}
  229. local dist = 1
  230. if args[1] then dist = tonumber(args[1]) end
  231. local i = 0
  232. local hit = false
  233. local hitc = 0
  234.  
  235. if not (dist > 0) then dist = 1 end
  236.  
  237. turtle.turnRight()
  238. turtle.turnRight()
  239. while i < dist do
  240. turtle.dig()
  241. if turtle.forward() then
  242.   i = i + 1
  243.  else
  244.   print("I hit Something")
  245.   sleep(1/4)
  246.   hitc = hitc + 1
  247.  end
  248. if hitc > dist/2 then
  249.   print("hit = "..hitc)
  250.   return false end
  251. end
  252.  
  253. return true
  254. turtle.turnRight()
  255. local args = {...}
  256. local dist = 1
  257. if args[1] then dist = tonumber(args[1]) end
  258. local i = 0
  259. local hit = false
  260. local hitc = 0
  261.  
  262. if not (dist > 0) then dist = 1 end
  263.  
  264. while i < dist do
  265. turtle.dig()
  266. if turtle.forward() then
  267.   i = i + 1
  268.  else
  269.   print("I hit Something")
  270.   sleep(1/4)
  271.   hitc = hitc + 1
  272.  end
  273. if hitc > dist/2 then
  274.   print("hit = "..hitc)
  275.   return false end
  276. end
  277.  
  278. return true
  279.  
  280. local of = io.open("drone","r")
  281. if of then
  282.   local sLine = of:read()
  283.   while sLine do
  284.     table.insert(tfile, sLine)
  285.     sLine = of.read()
  286.     end
  287.   of:close()
  288.   end
  289.  
  290. --for i,j in pairs(tfile) do
  291. --  print(i..":"..j)
  292. --  end
  293.  
  294. return tfile  
  295. --print("updateDrone initiated")
  296. local args = {...}
  297. local tfile = {}
  298.  
  299. function printtbl(tbl,comment)
  300. print("printtbl("..tostring(tbl).."["..#tbl.."],"..tostring(comment)..")")
  301. for i,j in ipairs(tbl) do
  302. print("tbl"..tostring(comment).."- "..i..","..j)
  303. end
  304. end
  305.  
  306. function load()
  307. b = io.open("drone","r")
  308. if b then
  309.   local sLine = b:read()
  310.   while sLine do
  311.     table.insert(tfile, sLine)
  312.     sLine = b:read()
  313.     end
  314.   b:close()
  315. end
  316. if #tfile == 0 then
  317.   table.insert(tfile, "")
  318.   end
  319. end
  320.  
  321. function save()
  322. d = io.open("drone","w")
  323. if d then
  324.     for n,sLineB in ipairs(tfile) do
  325.     d:write(sLineB)
  326.     print(sLineB)
  327.     d:write("\n")
  328.     end
  329.   end
  330. d:close()
  331. end
  332.  
  333. function updatefuel()
  334. local cur = turtle.getFuelLevel()
  335. local max = turtle.getFuelLimit()
  336. tfile[5] = "moves - "..tostring(cur)
  337. tfile[6] = "fuel - "..(cur/max*100).."%"
  338. end
  339.  
  340. function updatetool()
  341. local preSlot = turtle.getSelectedSlot()
  342. local space = turtle.getItemCount(15)
  343. local tool = "none"
  344. if space < 1 then
  345.   turtle.select(16)
  346.   turtle.equipLeft()
  347.   sleep(1/10)
  348.   tool = turtle.getItemDetail()
  349.   sleep(1/10)
  350.   --printtbl(tool)
  351.   turtle.equipLeft()
  352.   turtle.select(preSlot)
  353.   tfile[4] ="tool - "..tostring(tool[name])
  354.   end
  355. end
  356.  
  357. function updatePos()
  358. local x,y,z
  359. local oldx = tonumber(tfile[7])
  360. local oldy = tonumber(tfile[8])
  361. local oldz = tonumber(tfile[9])
  362. local gpx,gpy,gpz = gps.locate(2,true)
  363. if gpx then x = gpx else x = oldx end
  364. if gpy then y = gpy else y = oldy end
  365. if gpz then z = gpz else z = oldz end
  366. tfile[7] = tonumber(x)
  367. tfile[8] = tonumber(y)
  368. tfile[9] = tonumber(z)
  369. end
  370.  
  371. function update()
  372. load()
  373. updatetool()
  374. updatefuel()
  375. updatePos()
  376. term.clear()
  377. term.setCursorPos(1,1)
  378. save()
  379. end
  380.  
  381. --print("Load Complete")
  382. update()
  383. local args = {...}
  384. local dist = 1
  385. if args[1] then dist = tonumber(args[1]) end
  386. local i = 0
  387. local hit = false
  388. local hitc = 0
  389.  
  390. if not (dist > 0) then dist = 1 end
  391.  
  392. while i < dist do
  393. if turtle.down() then
  394.   i = i + 1
  395.  else
  396.   print("I hit Something")
  397.   sleep(1/4)
  398.   hitc = hitc + 1
  399.  end
  400. if hitc > dist/2 then
  401.   print("hit = "..hitc)
  402.   return false end
  403. end
  404.  
  405. return true
  406. turtle.turnLeft()
  407. local args = {...}
  408. local dist = 1
  409. if args[1] then dist = tonumber(args[1]) end
  410. local i = 0
  411. local hit = false
  412. local hitc = 0
  413.  
  414. if not (dist > 0) then dist = 1 end
  415.  
  416. while i < dist do
  417. turtle.digDown()
  418. if turtle.down() then
  419.   i = i + 1
  420.  else
  421.   print("I hit Something")
  422.   sleep(1/4)
  423.   hitc = hitc + 1
  424.  end
  425. if hitc > dist/2 then
  426.   print("hit = "..hitc)
  427.   return false end
  428. end
  429.  
  430. return true
  431. local args = {...}
  432. local dist = 1
  433. if args[1] then dist = tonumber(args[1]) end
  434. local i = 0
  435. local hit = false
  436. local hitc = 0
  437.  
  438. if not (dist > 0) then dist = 1 end
  439.  
  440. while i < dist do
  441. turtle.digUp()
  442. if turtle.up() then
  443.   i = i + 1
  444.  else
  445.   print("I hit Something")
  446.   sleep(1/4)
  447.   hitc = hitc + 1
  448.  end
  449. if hitc > dist/2 then
  450.   print("hit = "..hitc)
  451.   return false end
  452. end
  453.  
  454. return true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement