Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("By colhaydutu /ps colhaydutu")
- print("Setup")
- print("Place wired modem on the back side of the computer")
- print("Place wired modem on any side of the IC2 battery (like PESU, MFE, MSFU, BatBox), but it must be a block modem")
- print("Right-click all modems to connect")
- print("Place monitors 2x4 like this and place the modem on the back side of any monitor (yellow are monitors, red is computer)")
- paintutils.drawPixel(10, 16, colors.yellow)
- paintutils.drawPixel(12, 16, colors.yellow)
- paintutils.drawPixel(14, 16, colors.yellow)
- paintutils.drawPixel(16, 16, colors.yellow)
- paintutils.drawPixel(8, 18, colors.red)
- paintutils.drawPixel(10, 18, colors.yellow)
- paintutils.drawPixel(12, 18, colors.yellow)
- paintutils.drawPixel(14, 18, colors.yellow)
- paintutils.drawPixel(16, 18, colors.yellow)
- -- Function to find monitors
- local function findMonitors()
- local monitors = {}
- for _, name in pairs(peripheral.getNames()) do
- if string.match(name, "^monitor_") then
- local monitor = peripheral.wrap(name)
- table.insert(monitors, monitor)
- end
- end
- return monitors
- end
- local monitors = findMonitors()
- local monitor = monitors[1]
- local modem = peripheral.wrap("back")
- modem.open(11)
- -- Function to draw energy bar on the monitor
- local function drawBar(monitor, x, y, width, fillPercentage)
- local w, h = monitor.getSize()
- term.redirect(monitor)
- paintutils.drawLine(3, 3, 4, 3, colors.orange)
- paintutils.drawLine(13, 3, w - 2, 3, colors.orange)
- paintutils.drawLine(3, 3, 3, h - 1, colors.orange)
- paintutils.drawLine(w - 2, 3, w - 2, h - 1, colors.orange)
- paintutils.drawLine(w - 2, h - 1, 3, h - 1, colors.orange)
- monitor.setBackgroundColor(colors.gray)
- monitor.setTextColor(colors.black)
- monitor.setCursorPos(6, 3)
- monitor.write("[INFO]")
- local fillWidth = math.floor(width * fillPercentage)
- monitor.setBackgroundColor(colors.gray)
- monitor.setTextColor(colors.black)
- monitor.setCursorPos(x, y)
- monitor.write("[ ")
- for i = 1, width do
- if i <= fillWidth then
- monitor.setBackgroundColor(colors.green)
- monitor.write(" ")
- else
- monitor.setBackgroundColor(colors.red)
- monitor.write(" ")
- end
- end
- monitor.setBackgroundColor(colors.gray)
- monitor.write(" ] " .. math.floor(fillPercentage * 100) .. "%")
- end
- -- Finding 3 IC2 batteries
- local batteries = {}
- for _, name in pairs(peripheral.getNames()) do
- if string.match(name, "^ic2:") then
- local battery = peripheral.wrap(name)
- if battery and battery.getEUStored then -- Check if the battery has the getEUStored method
- table.insert(batteries, battery)
- end
- if #batteries >= 3 then
- break
- end
- end
- end
- if #batteries == 0 then
- print("No IC2 battery found. Please use the modem and right-click on it to connect.")
- return
- end
- -- Initial energy calculation
- local previousEnergy = 0
- for _, battery in pairs(batteries) do
- previousEnergy = previousEnergy + battery.getEUStored() -- Ensure getEUStored() is not nil
- end
- local energy = previousEnergy
- -- Main loop: continuously update energy values
- while true do
- local totalEnergy = 0
- local totalCapacity = 0
- -- Calculate total energy and capacity of all batteries
- for _, battery in pairs(batteries) do
- local batteryEnergy = battery.getEUStored()
- local batteryCapacity = battery.getEUCapacity()
- -- Safeguard against any nil values
- if batteryEnergy and batteryCapacity then
- totalEnergy = totalEnergy + batteryEnergy
- totalCapacity = totalCapacity + batteryCapacity
- end
- end
- local capPercentage = totalCapacity > 0 and totalEnergy / totalCapacity or 0
- local energyUsed = previousEnergy - totalEnergy
- previousEnergy = totalEnergy
- local energyInput = totalEnergy - energy
- energy = totalEnergy
- monitor.clear()
- drawBar(monitor, 5, 7, 20, capPercentage)
- -- Display total energy and energy usage on the screen
- monitor.setCursorPos(5, 5)
- monitor.setBackgroundColor(colors.gray)
- monitor.setTextColor(colors.black)
- monitor.write("Total Energy: " .. (totalEnergy / 1000) .. " K EU")
- monitor.setCursorPos(5, 9)
- monitor.write("Energy Used: " .. (energyUsed / 1000) .. " K EU")
- monitor.setCursorPos(5, 10)
- monitor.write("Energy Production: " .. (energyInput / 1000) .. " K EU")
- os.sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement