Squanou

AE2

Jun 23rd, 2024 (edited)
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.91 KB | None | 0 0
  1. local monitor = peripheral.find("monitor")
  2. local meBridge = peripheral.find("meBridge")
  3.  
  4. if not monitor then
  5.     print("Erreur: Moniteur non trouvé.")
  6.     return
  7. end
  8.  
  9. monitor.setTextScale(1)
  10. monitor.setBackgroundColor(colors.black)
  11. monitor.clear()
  12.  
  13. local function drawProgressBar(x, y, width, percent)
  14.     local barFill = math.floor(width * (percent / 100))
  15.     local barEmpty = width - barFill
  16.  
  17.     monitor.setCursorPos(x, y)
  18.     monitor.setBackgroundColor(colors.green)
  19.     monitor.write(string.rep(" ", barFill))
  20.  
  21.     monitor.setBackgroundColor(colors.red)
  22.     monitor.write(string.rep(" ", barEmpty))
  23.  
  24.     monitor.setBackgroundColor(colors.black)
  25. end
  26.  
  27. local function getAE2StorageStats()
  28.     local totalItemStorage = meBridge.getTotalItemStorage()
  29.     local usedItemStorage = meBridge.getUsedItemStorage()
  30.     local percentUsed = math.floor(usedItemStorage / totalItemStorage * 100)
  31.  
  32.     -- Convert usedItemStorage and totalItemStorage to GB (gigaoctets)
  33.     local usedGB = usedItemStorage / 1024
  34.     local totalGB = totalItemStorage / 1024
  35.  
  36.     return usedGB, totalGB, percentUsed
  37. end
  38.  
  39. monitor.setCursorPos(1, 1)
  40. monitor.setTextColor(colors.white)
  41. monitor.write("Applied Energistics 2\n")
  42. monitor.setCursorPos(1, 2)
  43. monitor.write("---------------------------------------------\n")
  44.  
  45. while true do
  46.     local usedGB, totalGB, percentUsed = getAE2StorageStats()
  47.  
  48.     monitor.setCursorPos(1, 3)
  49.     monitor.setBackgroundColor(colors.black)
  50.     monitor.write("                             ")
  51.  
  52.     monitor.setCursorPos(1, 3)
  53.     monitor.write(string.format("Espace Utilisé: %.2f / %.2f Go\n", usedGB, totalGB))
  54.     monitor.setCursorPos(1, 5)
  55.     monitor.write("Pourcentage Utilisé: " .. percentUsed .. "%\n")
  56.  
  57.     monitor.setCursorPos(1, 7)
  58.     monitor.setBackgroundColor(colors.black)
  59.     monitor.write("                    ")
  60.  
  61.     drawProgressBar(1, 5, 20, percentUsed)
  62.  
  63.     sleep(1)
  64. end
  65.  
Advertisement
Add Comment
Please, Sign In to add comment