Eldskogen

Untitled

Mar 11th, 2025
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. local meBridge = peripheral.wrap("left") -- Connect to ME Bridge on the left side
  2. local monitor = peripheral.find("monitor") -- Find a connected monitor
  3.  
  4. if not meBridge then
  5. print("Error: ME Bridge not found on the left side!")
  6. return
  7. else
  8. print("ME Bridge successfully detected!")
  9. end
  10.  
  11. if not monitor then
  12. print("Error: No monitor found!")
  13. return
  14. else
  15. print("Monitor successfully detected!")
  16. monitor.setTextScale(1) -- Set text scale for better visibility
  17. end
  18.  
  19. -- Function to format numbers with commas
  20. function formatNumber(num)
  21. local formatted = tostring(num)
  22. local k = 3
  23. while k < #formatted do
  24. formatted = formatted:sub(1, #formatted - k) .. "," .. formatted:sub(#formatted - k + 1)
  25. k = k + 4
  26. end
  27. return formatted
  28. end
  29.  
  30. -- Function to calculate storage usage
  31. function getStorageUsage()
  32. local itemUsage = meBridge.getUsedItemStorage() or 0
  33. local itemTotal = meBridge.getTotalItemStorage() or 1 -- Avoid division by zero
  34.  
  35. local itemPercent = (itemUsage / itemTotal) * 100
  36.  
  37. return {
  38. item = {
  39. used = itemUsage,
  40. free = itemTotal - itemUsage,
  41. total = itemTotal,
  42. percent = itemPercent
  43. }
  44. }
  45. end
  46.  
  47. -- Function to center text on the monitor
  48. function centerText(y, text, color)
  49. local w, _ = monitor.getSize()
  50. local x = math.floor((w - #text) / 2) + 1
  51. monitor.setCursorPos(x, y)
  52. if color then monitor.setTextColor(color) end
  53. monitor.write(text)
  54. monitor.setTextColor(colors.white) -- Reset text color
  55. end
  56.  
  57. -- Function to update the monitor display
  58. function updateMonitor()
  59. local storage = getStorageUsage()
  60. monitor.clear()
  61.  
  62. centerText(1, "Item Storage", colors.yellow)
  63. centerText(2, "---------------------", colors.yellow)
  64. centerText(3, "Used: " .. formatNumber(storage.item.used) .. " | Free: " .. formatNumber(storage.item.free), colors.white)
  65. centerText(4, string.format("%.1f%% Used | %.1f%% Free", storage.item.percent, 100 - storage.item.percent), colors.white)
  66. end
  67.  
  68. -- Continuously update the monitor
  69. while true do
  70. updateMonitor()
  71. sleep(5) -- Updates every 5 seconds
  72. end
  73.  
Advertisement
Add Comment
Please, Sign In to add comment