funkd0ct0r

Scan Em All

Apr 18th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. --put a turtle facing an ME interface
  2. --after running the program turtle will pull items into slot one
  3. --you need to pick up the thaumometer after the item changes for it to work, scan the item, then put the thaumometer back down (inside the turtle)
  4. --if you place thaumometer inside the turtle, it will automatically move to the next item
  5. --press P to pause, any other key will skip all item matching current ID (fuzzy skip for different durability armor, etc)
  6. --released into public domain pastebin.com/4xtrcVHp
  7.  
  8. useTimerMethod = false --in case you want to scan on a timer instead of inventory change
  9. useInventoryMethod = true
  10.  
  11. --change these directions to match your setup
  12. interface = peripheral.wrap("front")
  13. interface_export_dir = "south"
  14.  
  15. avail = interface.getAvailableItems()
  16.  
  17. turtle.select(1)
  18. turtle.drop()
  19. skip_id = ""
  20. timerID = 0
  21.  
  22. count = 0
  23. print("Total items = " .. table.getn(avail))
  24.  
  25. for k,v in pairs(avail) do
  26.  
  27. count = count + 1
  28. if v.fingerprint.id ~= skip_id and v.size > 0 then
  29. print(count .. ": " .. v.fingerprint.id)
  30.  
  31. interface.exportItem(v.fingerprint, interface_export_dir, 1)
  32. sleep(0.5)
  33.  
  34. if useTimerMethod then
  35. timerID = os.startTimer(4)
  36. end
  37. while true do
  38. event, key = os.pullEvent()
  39. if event == "key" then
  40. if key == 25 then -- P
  41. print("Paused, ENTER to resume")
  42. io.read()
  43. print("Unpaused")
  44. else
  45. skip_id = v.fingerprint.id
  46. os.cancelTimer(timerID)
  47. break
  48. end
  49. end
  50. if event == "timer" then
  51. break
  52. end
  53. if useInventoryMethod and event == "turtle_inventory" then
  54. found_item = false
  55. for slot = 2, 16 do
  56. if turtle.getItemCount(slot) > 0 then
  57. found_item = true
  58. end
  59. end
  60. if found_item then
  61. os.cancelTimer(timerID)
  62. break
  63. end
  64. end
  65. end
  66. turtle.drop()
  67. end
  68. end
Advertisement
Add Comment
Please, Sign In to add comment