Squanou

PowahServer

Jun 24th, 2024
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. local monitor = peripheral.find("monitor")
  2. local modem = peripheral.find("modem")
  3.  
  4. if not monitor then
  5. print("Erreur: Moniteur non trouvé.")
  6. return
  7. end
  8.  
  9. if not modem then
  10. print("Erreur: Modem non trouvé.")
  11. return
  12. end
  13.  
  14. rednet.open(peripheral.getName(modem))
  15.  
  16. monitor.setTextScale(1)
  17. monitor.setBackgroundColor(colors.black)
  18. monitor.clear()
  19.  
  20. local function displayStatsOnMonitor()
  21. while true do
  22. local senderId, stats, protocol = rednet.receive("powah")
  23.  
  24. if protocol == "powah" then
  25. local energyStored = stats.energyStored
  26. local energyCapacity = stats.energyCapacity
  27. local energyPercent = stats.energyPercent
  28.  
  29. monitor.clear()
  30. monitor.setCursorPos(1, 1)
  31. monitor.setTextColor(colors.white)
  32. monitor.write("Cellule d'Énergie Powah\n")
  33. monitor.write("---------------------------------------------\n")
  34. monitor.write("Énergie Stockée: " ..
  35. energyStored .. " / " .. energyCapacity .. " FE (" .. energyPercent .. "%)\n")
  36.  
  37. local barWidth = 20
  38. local barFill = math.floor(barWidth * (energyStored / energyCapacity))
  39. local barEmpty = barWidth - barFill
  40.  
  41. monitor.setCursorPos(1, 4)
  42. monitor.write("Energie: ")
  43.  
  44. monitor.setBackgroundColor(colors.green)
  45. monitor.write(string.rep(" ", barFill))
  46.  
  47. monitor.setBackgroundColor(colors.red)
  48. monitor.write(string.rep(" ", barEmpty))
  49.  
  50. monitor.setBackgroundColor(colors.black)
  51.  
  52. monitor.setCursorPos(1, 6)
  53. monitor.write(energyStored .. " RF (" .. energyPercent .. "%)")
  54. end
  55.  
  56. sleep(1)
  57. end
  58. end
  59.  
  60. displayStatsOnMonitor()
  61.  
Advertisement
Add Comment
Please, Sign In to add comment