Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.find("modem")
- local monitor = peripheral.find("monitor")
- if not modem then
- print("Erreur: Modem non trouvé. Vérifiez la connexion et le nom du périphérique.")
- return
- end
- if not monitor then
- print("Erreur: Moniteur non trouvé. Vérifiez la connexion et le nom du périphérique.")
- return
- end
- rednet.open(peripheral.getName(modem))
- local function displayStatsOnMonitor(stats)
- monitor.setTextScale(1)
- monitor.setBackgroundColor(colors.black)
- monitor.setTextColor(colors.white)
- monitor.clear()
- -- Afficher le titre
- local title = "Consommation de la base TsykiTeam en temps réel:"
- monitor.setCursorPos(1, 1)
- monitor.write(title)
- monitor.setCursorPos(1, 2)
- monitor.write(string.rep("-", #title))
- -- Afficher la barre de progression
- local energyStored = stats.energyStored
- local energyCapacity = stats.energyCapacity
- local energyPercent = stats.energyPercent
- local barTitle = string.format("Utilisation de la capacité: %d%% (%d / %d RF)", energyPercent, energyStored, energyCapacity)
- local barWidth = 20
- local barFill = math.floor(barWidth * (energyStored / energyCapacity))
- local barEmpty = barWidth - barFill
- local width, height = monitor.getSize()
- local x = math.floor((width - #barTitle) / 2)
- monitor.setCursorPos(x, 4)
- monitor.write(barTitle)
- monitor.setCursorPos(math.floor((width - barWidth * 2) / 2), 5)
- monitor.setBackgroundColor(colors.green)
- monitor.write(string.rep(" ", barFill * 2))
- monitor.setBackgroundColor(colors.red)
- monitor.write(string.rep(" ", barEmpty * 2))
- monitor.setBackgroundColor(colors.black)
- -- Afficher les autres informations
- monitor.setCursorPos(1, 7)
- monitor.write(string.format("Capacité: %d RF", energyCapacity))
- monitor.setCursorPos(1, 8)
- monitor.write(string.format("Non utilisé: %d RF", energyCapacity - energyStored))
- monitor.setCursorPos(1, 9)
- monitor.write(string.format("Consommation: %d RF/t", stats.transfer or 0))
- end
- while true do
- local senderId, stats, protocol = rednet.receive("flux_network_server")
- if protocol == "flux_network_server" then
- displayStatsOnMonitor(stats)
- end
- os.sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment