Advertisement
colhaydutu

tekkitsmp1

Oct 17th, 2024 (edited)
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. print("By colhaydutu /ps colhaydutu")
  2. print("Setup")
  3.  
  4. print("Place wired modem on the back side of the computer")
  5. print("Place wired modem on any side of the IC2 battery (like PESU, MFE, MSFU, BatBox), but it must be a block modem")
  6. print("Right-click all modems to connect")
  7.  
  8. print("Place monitors 2x4 like this and place the modem on the back side of any monitor (yellow are monitors, red is computer)")
  9.  
  10. paintutils.drawPixel(10, 16, colors.yellow)
  11. paintutils.drawPixel(12, 16, colors.yellow)
  12. paintutils.drawPixel(14, 16, colors.yellow)
  13. paintutils.drawPixel(16, 16, colors.yellow)
  14.  
  15. paintutils.drawPixel(8, 18, colors.red)
  16. paintutils.drawPixel(10, 18, colors.yellow)
  17. paintutils.drawPixel(12, 18, colors.yellow)
  18. paintutils.drawPixel(14, 18, colors.yellow)
  19. paintutils.drawPixel(16, 18, colors.yellow)
  20.  
  21. -- Function to find monitors
  22. local function findMonitors()
  23. local monitors = {}
  24. for _, name in pairs(peripheral.getNames()) do
  25. if string.match(name, "^monitor_") then
  26. local monitor = peripheral.wrap(name)
  27. table.insert(monitors, monitor)
  28. end
  29. end
  30. return monitors
  31. end
  32.  
  33. local monitors = findMonitors()
  34.  
  35. local monitor = monitors[1]
  36. local modem = peripheral.wrap("back")
  37. modem.open(11)
  38.  
  39. -- Function to draw energy bar on the monitor
  40. local function drawBar(monitor, x, y, width, fillPercentage)
  41. local w, h = monitor.getSize()
  42. term.redirect(monitor)
  43. paintutils.drawLine(3, 3, 4, 3, colors.orange)
  44. paintutils.drawLine(13, 3, w - 2, 3, colors.orange)
  45. paintutils.drawLine(3, 3, 3, h - 1, colors.orange)
  46. paintutils.drawLine(w - 2, 3, w - 2, h - 1, colors.orange)
  47. paintutils.drawLine(w - 2, h - 1, 3, h - 1, colors.orange)
  48.  
  49. monitor.setBackgroundColor(colors.gray)
  50. monitor.setTextColor(colors.black)
  51. monitor.setCursorPos(6, 3)
  52. monitor.write("[INFO]")
  53.  
  54. local fillWidth = math.floor(width * fillPercentage)
  55.  
  56. monitor.setBackgroundColor(colors.gray)
  57. monitor.setTextColor(colors.black)
  58.  
  59. monitor.setCursorPos(x, y)
  60. monitor.write("[ ")
  61.  
  62. for i = 1, width do
  63. if i <= fillWidth then
  64. monitor.setBackgroundColor(colors.green)
  65. monitor.write(" ")
  66. else
  67. monitor.setBackgroundColor(colors.red)
  68. monitor.write(" ")
  69. end
  70. end
  71.  
  72. monitor.setBackgroundColor(colors.gray)
  73. monitor.write(" ] " .. math.floor(fillPercentage * 100) .. "%")
  74. end
  75.  
  76. -- Finding 3 IC2 batteries
  77. local batteries = {}
  78. for _, name in pairs(peripheral.getNames()) do
  79. if string.match(name, "^ic2:") then
  80. local battery = peripheral.wrap(name)
  81. if battery and battery.getEUStored then -- Check if the battery has the getEUStored method
  82. table.insert(batteries, battery)
  83. end
  84. if #batteries >= 3 then
  85. break
  86. end
  87. end
  88. end
  89.  
  90. if #batteries == 0 then
  91. print("No IC2 battery found. Please use the modem and right-click on it to connect.")
  92. return
  93. end
  94.  
  95. -- Initial energy calculation
  96. local previousEnergy = 0
  97. for _, battery in pairs(batteries) do
  98. previousEnergy = previousEnergy + battery.getEUStored() -- Ensure getEUStored() is not nil
  99. end
  100.  
  101. local energy = previousEnergy
  102.  
  103. -- Main loop: continuously update energy values
  104. while true do
  105. local totalEnergy = 0
  106. local totalCapacity = 0
  107.  
  108. -- Calculate total energy and capacity of all batteries
  109. for _, battery in pairs(batteries) do
  110. local batteryEnergy = battery.getEUStored()
  111. local batteryCapacity = battery.getEUCapacity()
  112.  
  113. -- Safeguard against any nil values
  114. if batteryEnergy and batteryCapacity then
  115. totalEnergy = totalEnergy + batteryEnergy
  116. totalCapacity = totalCapacity + batteryCapacity
  117. end
  118. end
  119.  
  120. local capPercentage = totalCapacity > 0 and totalEnergy / totalCapacity or 0
  121.  
  122. local energyUsed = previousEnergy - totalEnergy
  123. previousEnergy = totalEnergy
  124.  
  125. local energyInput = totalEnergy - energy
  126. energy = totalEnergy
  127.  
  128. monitor.clear()
  129. drawBar(monitor, 5, 7, 20, capPercentage)
  130.  
  131. -- Display total energy and energy usage on the screen
  132. monitor.setCursorPos(5, 5)
  133. monitor.setBackgroundColor(colors.gray)
  134. monitor.setTextColor(colors.black)
  135. monitor.write("Total Energy: " .. (totalEnergy / 1000) .. " K EU")
  136.  
  137. monitor.setCursorPos(5, 9)
  138. monitor.write("Energy Used: " .. (energyUsed / 1000) .. " K EU")
  139.  
  140. monitor.setCursorPos(5, 10)
  141. monitor.write("Energy Production: " .. (energyInput / 1000) .. " K EU")
  142.  
  143. os.sleep(1)
  144. end
  145.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement