Advertisement
Shaka01

sheet/plate automater

Mar 3rd, 2023 (edited)
851
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.58 KB | None | 0 0
  1. items = {
  2. "plate",
  3. "sheet",
  4. "paper"
  5.  
  6. }
  7. machine = "create:depot_0"
  8. wormhole = "occultism:stable_wormhole_5"
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15. if fs.exists("API") == false then
  16. shell.run("pastebin", "get", "EzkfU5ZM", "API")
  17. end
  18. shaka = require("API")
  19. if fs.exists("targetInv") then
  20.     local file = fs.open("targetInv", "r")
  21.     storage = file.readAll()
  22.     file.close()
  23. else
  24.     storage = ""
  25. end
  26. lastMoved = {}
  27. shaka.findAvailableInventory()
  28. inv = peripheral.wrap(storage)
  29. depotInv = peripheral.wrap(machine)
  30. wormInv = peripheral.wrap(wormhole)
  31. startTimer = false
  32.  
  33. function checkSlot(itemName)
  34.     for _, item in pairs(items) do
  35.         if shaka.stringFind(itemName, item) then
  36.             return true
  37.         end
  38.     end
  39. return false
  40. end
  41.  
  42. function findFilteredItems()
  43. for k, v in pairs(inv.list()) do
  44.     if checkSlot(v.name) == false then
  45.         inv.pushItems(machine, k)
  46.         startTimer = true
  47.     end
  48. end
  49. end
  50.  
  51. function moveFinishedItems()
  52. for k, v in pairs(depotInv.list()) do
  53.     if checkSlot(v.name) then
  54.         depotInv.pushItems(wormhole, k)
  55.     end
  56. end
  57. end
  58.  
  59. function checkTimer()
  60.     if startTimer == true then
  61.         processingItems = {}
  62.         startTimer = false
  63.         for k, v in pairs(depotInv.list()) do
  64.             processingItems[v.name] = v.count
  65.         end
  66.         sleep(1)
  67.         for k, v in pairs(depotInv.list()) do
  68.             for a, b in pairs(processingItems) do
  69.                 if a == v.name and b == v.count then
  70.                     print(v.name.. " has been here too long. Begone.")
  71.                     depotInv.pushItems(wormhole, k)
  72.                     return true
  73.                 end
  74.             end
  75.         end
  76.     else
  77.         sleep(0.1)
  78.     end
  79. end
  80.        
  81.  
  82. while true do
  83. moveFinishedItems()
  84. findFilteredItems()
  85. checkTimer()
  86. end
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement