Advertisement
ElectroFactory

Untitled

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