Advertisement
whaamp

Untitled

Jan 9th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. cur_lvl = 0
  2. cur_dir = 0
  3.  
  4. items = {}
  5.  
  6. function save(t, n)
  7. local file = fs.open(n, "w")
  8. file.write(textutils.serialize(t))
  9. file.close()
  10. end
  11.  
  12. function load(n)
  13. local file = fs.open(n, "r")
  14. local data = file.readAll()
  15. file.close()
  16. return textutils.unserialize(data)
  17. end
  18.  
  19. function equals(i1, i2)
  20. return i1.name == i2.name and i1.damage == i2.damage
  21. end
  22.  
  23. function contains(t, i)
  24. for n, v in pairs(t) do
  25. if equals(v, i) then
  26. return n
  27. end
  28. end
  29. return 0
  30. end
  31.  
  32. function go_to(lvl, dir)
  33. while cur_lvl > lvl do
  34. turtle.down()
  35. cur_lvl = cur_lvl - 1
  36. end
  37. while cur_lvl < lvl do
  38. turtle.up()
  39. cur_lvl = cur_lvl + 1
  40. end
  41. turn = cur_dir - dir
  42. if turn == -3 or turn == 1 then
  43. turtle.turnLeft()
  44. else
  45. for i=1, (turn + 4) % 4 do
  46. turtle.turnRight()
  47. end
  48. end
  49. cur_dir = dir
  50. end
  51.  
  52. function add_item(item)
  53. n = contains(items, item)
  54. if n == 0 then
  55. v = {name = item.name, count = item.count, damage = item.damage}
  56. v.level = math.floor(#items / 4) + 1
  57. v.dir = #items % 4
  58. table.insert(items, v)
  59. go_to(v.level, v.dir)
  60. turtle.drop()
  61. else
  62. turtle.drop()
  63. amt = turtle.getItemCount()
  64. items[n].count = items[n].count + i.count - amt
  65. turtle.dropDown()
  66. end
  67. end
  68.  
  69. function deposit_items()
  70. for i=1, 16 do
  71. select(i)
  72. item = turtle.getItemDetail()
  73. if item then
  74. add_item(item)
  75. end
  76. end
  77. go_to(0, 0)
  78. end
  79.  
  80. --while true do
  81. -- if turtle.suckUp() then
  82. -- sleep(3)
  83. -- while turtle.suckUp() do
  84. -- end
  85. -- deposit_items()
  86. -- end
  87. --end
  88.  
  89. go_to(2, 0)
  90. sleep(2)
  91. go_to(0, 0)
  92. sleep(2)
  93. go_to(0, 2)
  94. sleep(2)
  95. go_to(1, 1)
  96.  
  97. --items = {}
  98. --items["diamond_sword"] = 2
  99. --items["iron_axe"] = 6
  100. --items["iron_sword"] = 8
  101. --
  102. --search = io.read()
  103. --print("Searching...")
  104. --
  105. --top_result = nil
  106. --for k, v in pairs(items) do
  107. -- r = string.find(k, search)
  108. -- if r then
  109. -- x = string.len(k) + r
  110. -- if not top_result or x < top_result.val then
  111. -- top_result = {name=k,deets=v,val = x}
  112. -- end
  113. -- end
  114. --end
  115. --print(top_result.name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement