Advertisement
ElectroFactory

Untitled

Oct 9th, 2024 (edited)
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.61 KB | None | 0 0
  1. -- Associer le moniteur et les tanks à leurs périphériques respectifs
  2. local monitor = peripheral.wrap("top") -- Moniteur sur le côté "top"
  3. local tanks = {
  4.     {id = 9, peripheral = peripheral.wrap("fluidTank_9")},
  5.     {id = 18, peripheral = peripheral.wrap("fluidTank_18")},
  6.     {id = 19, peripheral = peripheral.wrap("fluidTank_19")},
  7.     {id = 20, peripheral = peripheral.wrap("fluidTank_20")},
  8.     {id = 21, peripheral = peripheral.wrap("fluidTank_21")}
  9. }
  10.  
  11. monitor.clear()
  12. monitor.setTextScale(1)
  13.  
  14. -- Noms manuels des liquides pour chaque tank
  15. local fluidNames = {
  16.     [9] = "Water 1",
  17.     [18] = "Water 2",
  18.     [19] = "Water 3",
  19.     [20] = "Water 4",
  20.     [21] = "Water 5"
  21. }
  22.  
  23. -- Stocker les valeurs précédentes pour comparer
  24. local previousInfo = {}
  25.  
  26. -- Fonction pour récupérer les informations d'un tank avec nom manuel
  27. function getTankInfo(tank, tankId)
  28.     local tankInfo = tank.getInfo()
  29.     local fluidName = fluidNames[tankId] or "Unknown Fluid"
  30.     local amount = tankInfo and tankInfo.amount or 0
  31.     return fluidName, amount
  32. end
  33.  
  34. -- Fonction pour afficher les informations sur l'Advanced Monitor
  35. function displayTankInfo()
  36.     for index, tankData in ipairs(tanks) do
  37.         local tank = tankData.peripheral
  38.         local tankId = tankData.id
  39.         local name, amount = getTankInfo(tank, tankId)
  40.         local capacity = 432000  -- Capacité maximale fixe
  41.         local percentage = (amount / capacity) * 100
  42.  
  43.         -- Vérifier si les informations ont changé par rapport à la dernière fois
  44.         if not previousInfo[tankId] or previousInfo[tankId].name ~= name or previousInfo[tankId].amount ~= amount then
  45.             -- Mettre à jour les informations sur le moniteur uniquement si elles ont changé
  46.             monitor.setCursorPos(1, (index - 1) * 3 + 1)  -- Espacement entre les lignes
  47.             monitor.write(string.rep(" ", monitor.getSize())) -- Effacer la ligne précédente
  48.             monitor.setCursorPos(1, (index - 1) * 3 + 1)
  49.             monitor.write(name)
  50.  
  51.             monitor.setCursorPos(1, (index - 1) * 3 + 2)
  52.             monitor.write(string.rep(" ", monitor.getSize())) -- Effacer la ligne précédente
  53.             monitor.setCursorPos(1, (index - 1) * 3 + 2)
  54.             monitor.write(amount .. " / " .. capacity .. " mB (" .. string.format("%.2f", percentage) .. "%)")
  55.  
  56.             -- Stocker les valeurs actuelles pour le prochain cycle
  57.             previousInfo[tankId] = { name = name, amount = amount }
  58.         end
  59.     end
  60. end
  61.  
  62. -- Rafraîchir les informations toutes les secondes sans clignotement
  63. while true do
  64.     displayTankInfo()
  65.     sleep(1)
  66. end
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement