April_The_Sergal

OrbScript

Jul 27th, 2025 (edited)
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. -- === CONFIG ===
  2. local ORB_SIDE = "right"
  3. local SOURCE_SIDE = "bottom"
  4. local MAX_ORB_SLOTS = 6
  5. local CHECK_INTERVAL = 2
  6.  
  7. -- === INIT ===
  8. local orb = peripheral.wrap(ORB_SIDE)
  9. if not orb then
  10. error("No peripheral on " .. ORB_SIDE .. " (expected Powah Charging Orb)")
  11. end
  12.  
  13. -- Sanity check: does it support inventory methods?
  14. if not orb.list or not orb.pullItems then
  15. error("Peripheral on " .. ORB_SIDE .. " is not inventory-compatible")
  16. end
  17.  
  18. -- === FUNCTIONS ===
  19.  
  20. -- Counts how many occupied slots are in the orb
  21. local function getOrbItemCount()
  22. local success, items = pcall(orb.list)
  23. if not success or not items then
  24. print("Failed to read orb inventory")
  25. return -1
  26. end
  27.  
  28. local count = 0
  29. for slot, item in pairs(items) do
  30. if item then
  31. count = count + 1
  32. end
  33. end
  34. return count
  35. end
  36.  
  37. -- Tries to find an item in the source inventory and insert it into the orb
  38. local function moveOneItem()
  39. for slot = 1, 27 do
  40. local detail = peripheral.call(SOURCE_SIDE, "getItemDetail", slot)
  41. if detail then
  42. print("Found item in source slot " .. slot .. ": " .. detail.name)
  43. local moved = orb.pullItems(SOURCE_SIDE, slot, 1)
  44. if moved > 0 then
  45. print("Moved 1 item into orb.")
  46. else
  47. print("Item move failed.")
  48. end
  49. return
  50. end
  51. end
  52. print("No items found in source to move.")
  53. end
  54.  
  55. -- === MAIN LOOP ===
  56.  
  57. while true do
  58. print("Checking orb inventory...")
  59. local orbCount = getOrbItemCount()
  60. if orbCount == -1 then
  61. print("Skipping this cycle due to read error.")
  62. elseif orbCount == 5 then
  63. print("Orb has exactly 5 items. Attempting to insert 1 more...")
  64. moveOneItem()
  65. else
  66. print("Orb has " .. orbCount .. " item(s). Waiting...")
  67. end
  68. sleep(CHECK_INTERVAL)
  69. end
  70.  
Add Comment
Please, Sign In to add comment