Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Associer le moniteur et les tanks à leurs périphériques respectifs
- local monitor = peripheral.wrap("top") -- Moniteur sur le côté "top"
- local tanks = {
- {id = 9, peripheral = peripheral.wrap("fluidTank_9")},
- {id = 18, peripheral = peripheral.wrap("fluidTank_18")},
- {id = 19, peripheral = peripheral.wrap("fluidTank_19")},
- {id = 20, peripheral = peripheral.wrap("fluidTank_20")},
- {id = 21, peripheral = peripheral.wrap("fluidTank_21")}
- }
- monitor.clear()
- monitor.setTextScale(1)
- -- Noms manuels des liquides pour chaque tank
- local fluidNames = {
- [9] = "Water 1",
- [18] = "Water 2",
- [19] = "Water 3",
- [20] = "Water 4",
- [21] = "Water 5"
- }
- -- Stocker les valeurs précédentes pour comparer
- local previousInfo = {}
- -- Fonction pour récupérer les informations d'un tank avec nom manuel
- function getTankInfo(tank, tankId)
- local tankInfo = tank.getInfo()
- local fluidName = fluidNames[tankId] or "Unknown Fluid"
- local amount = tankInfo and tankInfo.amount or 0
- return fluidName, amount
- end
- -- Fonction pour afficher les informations sur l'Advanced Monitor
- function displayTankInfo()
- for index, tankData in ipairs(tanks) do
- local tank = tankData.peripheral
- local tankId = tankData.id
- local name, amount = getTankInfo(tank, tankId)
- local capacity = 432000 -- Capacité maximale fixe
- local percentage = (amount / capacity) * 100
- -- Vérifier si les informations ont changé par rapport à la dernière fois
- if not previousInfo[tankId] or previousInfo[tankId].name ~= name or previousInfo[tankId].amount ~= amount then
- -- Mettre à jour les informations sur le moniteur uniquement si elles ont changé
- monitor.setCursorPos(1, (index - 1) * 3 + 1) -- Espacement entre les lignes
- monitor.write(string.rep(" ", monitor.getSize())) -- Effacer la ligne précédente
- monitor.setCursorPos(1, (index - 1) * 3 + 1)
- monitor.write(name)
- monitor.setCursorPos(1, (index - 1) * 3 + 2)
- monitor.write(string.rep(" ", monitor.getSize())) -- Effacer la ligne précédente
- monitor.setCursorPos(1, (index - 1) * 3 + 2)
- monitor.write(amount .. " / " .. capacity .. " mB (" .. string.format("%.2f", percentage) .. "%)")
- -- Stocker les valeurs actuelles pour le prochain cycle
- previousInfo[tankId] = { name = name, amount = amount }
- end
- end
- end
- -- Rafraîchir les informations toutes les secondes sans clignotement
- while true do
- displayTankInfo()
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement