djbigmac9

PokePull

Jul 17th, 2026 (edited)
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. math.randomseed(os.epoch("utc"))
  2. local lastChest = nil
  3. local lastSlot = nil
  4.  
  5. local REDSTONE_SIDE = "front" -- change if needed
  6.  
  7. local output = peripheral.wrap("right")
  8. local left = peripheral.wrap("left")
  9. local top = peripheral.wrap("top")
  10. local bottom = peripheral.wrap("bottom")
  11. local back = peripheral.wrap("back")
  12.  
  13. local function isEmpty(chest)
  14. return next(chest.list()) == nil
  15. end
  16.  
  17. local function pullRandom(chest)
  18. if not chest then
  19. print("Chest not found!")
  20. return
  21. end
  22.  
  23. local chestName = peripheral.getName(chest)
  24.  
  25. while true do
  26. local occupied = {}
  27.  
  28. for slot, item in pairs(chest.list()) do
  29. if not (chestName == lastChest and slot == lastSlot) then
  30. table.insert(occupied, slot)
  31. end
  32. end
  33.  
  34. if #occupied > 0 then
  35. local slot = occupied[math.random(#occupied)]
  36.  
  37. lastChest = chestName
  38. lastSlot = slot
  39.  
  40. local moved = output.pullItems(chestName, slot, 1)
  41.  
  42. if moved > 0 then
  43. print("Pulled from " .. chestName .. " slot " .. slot)
  44. else
  45. print("Failed to pull from " .. chestName)
  46. end
  47.  
  48. sleep(0.25)
  49. return
  50. end
  51.  
  52. -- Supply chest is empty: pause and wait for the user
  53. print("!! " .. chestName .. " is empty !!")
  54. print("Refill it, then press any key to continue...")
  55. os.pullEvent("key")
  56. sleep(0.5) -- small debounce before re-checking
  57. end
  58. end
  59.  
  60. -- Make sure signal starts off
  61. redstone.setOutput(REDSTONE_SIDE, false)
  62.  
  63. while true do
  64. print("Dealing 9 cards...")
  65.  
  66. for i = 1, 6 do
  67. pullRandom(left)
  68. end
  69.  
  70. pullRandom(top)
  71. pullRandom(bottom)
  72. pullRandom(back)
  73.  
  74. print("Finished sending 9 cards")
  75.  
  76. -- Signal on immediately: cards are ready
  77. redstone.setOutput(REDSTONE_SIDE, true)
  78.  
  79. -- Wait for the output chest to be emptied
  80. print("Waiting for output chest to be emptied...")
  81. repeat
  82. sleep(2)
  83. until isEmpty(output)
  84.  
  85. -- Signal off as soon as it's empty
  86. redstone.setOutput(REDSTONE_SIDE, false)
  87.  
  88. -- Pause before the next deal
  89. print("Signal off - waiting 5 seconds before next deal...")
  90. sleep(5)
  91. end
Advertisement
Add Comment
Please, Sign In to add comment