Squanou

FN_3

Jun 24th, 2024 (edited)
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.28 KB | None | 0 0
  1. local modem = peripheral.find("modem")
  2. local monitor = peripheral.find("monitor")
  3.  
  4. if not modem then
  5.     print("Erreur: Modem non trouvé. Vérifiez la connexion et le nom du périphérique.")
  6.     return
  7. end
  8.  
  9. if not monitor then
  10.     print("Erreur: Moniteur non trouvé. Vérifiez la connexion et le nom du périphérique.")
  11.     return
  12. end
  13.  
  14. rednet.open(peripheral.getName(modem))
  15.  
  16. local function displayStatsOnMonitor(stats)
  17.  
  18.     monitor.setTextScale(1)
  19.     monitor.setBackgroundColor(colors.black)
  20.     monitor.setTextColor(colors.white)
  21.     monitor.clear()
  22.  
  23.     -- Afficher le titre
  24.     local title = "Consommation de la base TsykiTeam en temps réel:"
  25.     monitor.setCursorPos(1, 1)
  26.     monitor.write(title)
  27.     monitor.setCursorPos(1, 2)
  28.     monitor.write(string.rep("-", #title))
  29.  
  30.     -- Afficher la barre de progression
  31.     local energyStored = stats.energyStored
  32.     local energyCapacity = stats.energyCapacity
  33.     local energyPercent = stats.energyPercent
  34.  
  35.     local barTitle = string.format("Utilisation de la capacité: %d%% (%d / %d RF)", energyPercent, energyStored, energyCapacity)
  36.     local barWidth = 20
  37.     local barFill = math.floor(barWidth * (energyStored / energyCapacity))
  38.     local barEmpty = barWidth - barFill
  39.  
  40.     local width, height = monitor.getSize()
  41.     local x = math.floor((width - #barTitle) / 2)
  42.     monitor.setCursorPos(x, 4)
  43.     monitor.write(barTitle)
  44.  
  45.     monitor.setCursorPos(math.floor((width - barWidth * 2) / 2), 5)
  46.     monitor.setBackgroundColor(colors.green)
  47.     monitor.write(string.rep(" ", barFill * 2))
  48.     monitor.setBackgroundColor(colors.red)
  49.     monitor.write(string.rep(" ", barEmpty * 2))
  50.     monitor.setBackgroundColor(colors.black)
  51.  
  52.     -- Afficher les autres informations
  53.     monitor.setCursorPos(1, 7)
  54.     monitor.write(string.format("Capacité: %d RF", energyCapacity))
  55.     monitor.setCursorPos(1, 8)
  56.     monitor.write(string.format("Non utilisé: %d RF", energyCapacity - energyStored))
  57.     monitor.setCursorPos(1, 9)
  58.     monitor.write(string.format("Consommation: %d RF/t", stats.transfer or 0))
  59. end
  60.  
  61. while true do
  62.     local senderId, stats, protocol = rednet.receive("flux_network_server")
  63.    
  64.     if protocol == "flux_network_server" then
  65.         displayStatsOnMonitor(stats)
  66.     end
  67.  
  68.     os.sleep(0.1)
  69. end
  70.  
Advertisement
Add Comment
Please, Sign In to add comment