Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local VERISON = "NEW"
- function checkVersionTooOld()
- local monitorsCheck = {peripheral.find("monitor")}
- end
- function checkVersionNEW()
- local reactorsArray = {peripheral.find("BigReactors-Reactor")}
- reactorsArray[0].getEnergyStats();
- end
- function checkErrors()
- if pcall(checkVersionTooOld) then
- else
- error("The version of ComputerCraft is too old to use this program, sorry", 0)
- end
- local monitorsCheck = {peripheral.find("monitor")}
- local reactorsCheck = {peripheral.find("BigReactors-Reactor")}
- if monitorsCheck[1] == nil then
- error("The Monitor is not being detected, make sure the connections(modem) are activated", 0)
- end
- if reactorsCheck[1] == nil then
- error("The Reactor is not being detected, make sure the connections(modem) are activated. The problem could also be related to chunk protection on some public servers, ask an admin about it.", 0)
- end
- if pcall(checkVersionNEW) then
- VERISON = "NEW"
- else
- VERISON = "OLD"
- end
- end
- -- you need to give the index to be able to use the program
- -- ex : Reactor Data
- local args = { ... }
- local button = {}
- local filleds = {}
- local boxes = {}
- local lines = {}
- local texts = {}
- local refresh = true
- local infosSize = {}
- local controlsSize = {}
- local numbersSize = {}
- local currentRfTotal = 1
- local currentRfTick = 1
- local currentFuelConsumedLastTick = 0.00001
- local rfPerTickMax = 1
- local minPowerRod = 0
- local maxPowerRod = 100
- local currentRodLevel = 1
- local index = ""
- checkErrors()
- if (#args == 0) then
- error("No index Given, Make sure to start the 'start' program and not the 'reactor' program", 0)
- end
- if (#args == 1) then
- index = args[1]
- end
- local monitors = {peripheral.find("monitor")}
- local mon = monitors[1]
- local reactors = {peripheral.find("BigReactors-Reactor")}
- term.redirect(mon)
- mon.clear()
- mon.setTextColor(colors.white)
- mon.setBackgroundColor(colors.black)
- function clearTable()
- button = {}
- end
- function setButton(name, title, func, xmin, ymin, xmax, ymax, elem, elem2, color)
- button[name] = {}
- button[name]["title"] = title
- button[name]["func"] = func
- button[name]["active"] = false
- button[name]["xmin"] = xmin
- button[name]["ymin"] = ymin
- button[name]["xmax"] = xmax
- button[name]["ymax"] = ymax
- button[name]["color"] = color
- button[name]["elem"] = elem
- button[name]["elem2"] = elem2
- end
- function fill(text, color, bData)
- mon.setBackgroundColor(color)
- mon.setTextColor(colors.white)
- local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
- local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(bData["title"])) /2) +1
- for j = bData["ymin"], bData["ymax"] do
- mon.setCursorPos(bData["xmin"], j)
- if j == yspot then
- for k = 0, bData["xmax"] - bData["xmin"] - string.len(bData["title"]) +1 do
- if k == xspot then
- mon.write(bData["title"])
- else
- mon.write(" ")
- end
- end
- else
- for i = bData["xmin"], bData["xmax"] do
- mon.write(" ")
- end
- end
- end
- mon.setBackgroundColor(colors.black)
- end
- function screen()
- local currColor
- for name,data in pairs(button) do
- local on = data["active"]
- currColor = data["color"]
- fill(name, currColor, data)
- end
- end
- function flash(name)
- screen()
- end
- function checkxy(x, y)
- for name, data in pairs(button) do
- if y>=data["ymin"] and y <= data["ymax"] then
- if x>=data["xmin"] and x<= data["xmax"] then
- data["func"](data["elem"], data["elem2"])
- flash(data['name'])
- return true
- --data["active"] = not data["active"]
- --print(name)
- end
- end
- end
- return false
- end
- function label(w, h, text)
- mon.setCursorPos(w, h)
- mon.write(text)
- end
- function draw()
- for key,value in pairs(filleds) do
- local counter = 1
- for i=value[2],value[4],1 do
- paintutils.drawLine(value[1] , value[2]+counter, value[3], value[2]+counter, value[5])
- counter = counter + 1
- end
- end
- for key,value in pairs(boxes) do
- paintutils.drawLine(value[1] , value[2], value[1], value[4], value[5])
- paintutils.drawLine(value[1] , value[2], value[3], value[2], value[5])
- paintutils.drawLine(value[1] , value[4], value[3], value[4], value[5])
- paintutils.drawLine(value[3] , value[2], value[3], value[4], value[5])
- end
- for key,value in pairs(lines) do
- paintutils.drawLine(value[1] , value[2], value[3], value[4], value[5])
- end
- for key,value in pairs(texts) do
- mon.setCursorPos(value[1], value[2])
- mon.setTextColor(value[4])
- mon.setBackgroundColor(value[5])
- mon.write(value[3])
- end
- screen()
- resetDraw()
- end
- function resetDraw()
- filleds = {}
- boxes = {}
- lines = {}
- texts = {}
- end
- function clickEvent()
- local myEvent={os.pullEvent("monitor_touch")}
- checkxy(myEvent[3], myEvent[4])
- end
- function powerUp(m,n)
- local reactor = reactors[1]
- reactor.setActive(true)
- end
- --M & Ns are a good source of food, right?
- function powerDown(m,n)
- local reactor = reactors[1]
- reactor.setActive(false)
- end
- function modifyRods(limit, number)
- local tempLevel = 0
- if limit == "min" then
- tempLevel = minPowerRod + number
- if tempLevel <= 0 then
- minPowerRod = 0
- end
- if tempLevel >= maxPowerRod then
- minPowerRod = maxPowerRod -10
- end
- if tempLevel < maxPowerRod and tempLevel > 0 then
- minPowerRod = tempLevel
- end
- else
- tempLevel = maxPowerRod + number
- if tempLevel <= minPowerRod then
- maxPowerRod = minPowerRod +10
- end
- if tempLevel >= 100 then
- maxPowerRod = 100
- end
- if tempLevel > minPowerRod and tempLevel < 100 then
- maxPowerRod = tempLevel
- end
- end
- table.insert(lines, {controlsSize['inX'], controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, controlsSize['inX'] + controlsSize['width'], controlsSize['inY']+(controlsSize['sectionHeight']*1)+4, colors.black})
- table.insert(texts, {controlsSize['inX']+5, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, minPowerRod .. '%', colors.lightBlue, colors.black})
- table.insert(texts, {controlsSize['inX']+13, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, '--', colors.white, colors.black})
- table.insert(texts, {controlsSize['inX']+20, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, maxPowerRod .. '%', colors.purple, colors.black})
- setInfoToFile()
- adjustRodsLevel()
- end
- function adjustRodsLevel()
- local reactor = reactors[1]
- local rfTotalMax = 10000000
- local allStats = getAllStats()
- local currentRfTotal = allStats["rfTotal"]
- local reactorRodsLevel = allStats["reactorRodsLevel"]
- differenceMinMax = maxPowerRod - minPowerRod
- maxPower = (rfTotalMax/100) * maxPowerRod
- minPower = (rfTotalMax/100) * minPowerRod
- if currentRfTotal >= maxPower then
- currentRfTotal = maxPower
- end
- if currentRfTotal <= minPower then
- currentRfTotal = minPower
- end
- currentRfTotal = currentRfTotal - (rfTotalMax/100) * minPowerRod
- local rfInBetween = (rfTotalMax/100) * differenceMinMax
- local rodLevel = math.ceil((currentRfTotal/rfInBetween)*100)
- if VERSION == "NEW" then
- if reactor.mbIsConnected() == true and reactor.mbIsAssembled() == true then
- for key,value in pairs(reactorRodsLevel) do
- reactorRodsLevel[key] = rodLevel
- end
- reactor.setControlRodsLevels(reactorRodsLevel)
- end
- else
- reactor.setAllControlRodLevels(rodLevel)
- end
- end
- function addDrawBoxesSingleReactor()
- local w, h = mon.getSize()
- local margin = math.floor((w/100)*2)
- infosSize['startX'] = margin + 1
- infosSize['startY'] = margin + 1
- infosSize['endX'] = (((w-(margin*2))/3)*2)-margin
- infosSize['endY'] = h - margin
- infosSize['height'] = infosSize['endY']-infosSize['startY']-(margin*2)-2
- infosSize['width'] = infosSize['endX']-infosSize['startX']-(margin*2)-2
- infosSize['inX'] = infosSize['startX'] + margin +1
- infosSize['inY'] = infosSize['startY'] + margin +1
- infosSize['sectionHeight'] = math.floor(infosSize['height']/3)
- table.insert(boxes, {infosSize['startX'] , infosSize['startY'], infosSize['endX'], infosSize['endY'], colors.gray})
- local name = "INFOS"
- table.insert(lines, {infosSize['startX'] + margin , infosSize['startY'], infosSize['startX'] + (margin*2) + #name+1, infosSize['startY'], colors.black})
- table.insert(texts, {infosSize['startX'] + (margin*2), infosSize['startY'], name, colors.white, colors.black})
- local names = {}
- names[1] = 'ENERGY LAST TICK'
- names[2] = 'ENERGY STORED'
- names[3] = 'CONTROL ROD LEVEL'
- for i=0,2,1 do
- table.insert(texts, {infosSize['inX'] + margin, infosSize['inY'] + (infosSize['sectionHeight']*i) +i, names[i+1], colors.white, colors.black})
- table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 2 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + infosSize['width'], infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.lightGray})
- end
- controlsSize['startX'] = infosSize['endX'] + margin + 1
- controlsSize['startY'] = margin + 1
- controlsSize['endX'] = w-margin
- controlsSize['endY'] = (((h - (margin*2))/3)*2) +1
- controlsSize['height'] = controlsSize['endY']-controlsSize['startY']-(margin)-1
- controlsSize['width'] = controlsSize['endX']-controlsSize['startX']-(margin*2)-2
- controlsSize['inX'] = controlsSize['startX'] + margin +1
- controlsSize['inY'] = controlsSize['startY'] + margin
- table.insert(boxes, {controlsSize['startX'] , controlsSize['startY'], controlsSize['endX'], controlsSize['endY'], colors.gray})
- name = "CONTROLS"
- table.insert(lines, {controlsSize['startX'] + margin , controlsSize['startY'], controlsSize['startX'] + (margin*2) + #name+1, controlsSize['startY'], colors.black})
- table.insert(texts, {controlsSize['startX'] + (margin*2), controlsSize['startY'], name, colors.white, colors.black})
- controlsSize['sectionHeight'] = math.floor(controlsSize['height']/4)
- reactor = reactors[1]
- mon.setTextColor(colors.white)
- setButton("ON","ON", powerUp, controlsSize['inX'], controlsSize['inY'], controlsSize['inX'] + math.floor(controlsSize['width']/2) -1, controlsSize['inY'] +2, 0, 0, colors.green)
- setButton("OFF","OFF", powerDown, controlsSize['inX'] + math.floor(controlsSize['width']/2) +2, controlsSize['inY'], controlsSize['inX'] + controlsSize['width'], controlsSize['inY'] +2,0, 0, colors.red)
- table.insert(texts, {controlsSize['inX']+8, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+1, 'AUTO-CONTROL', colors.white, colors.black})
- table.insert(texts, {controlsSize['inX']+5, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+3, 'MIN', colors.lightBlue, colors.black})
- table.insert(texts, {controlsSize['inX']+5, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, minPowerRod..'%', colors.lightBlue, colors.black})
- table.insert(texts, {controlsSize['inX']+13, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, '--', colors.white, colors.black})
- table.insert(texts, {controlsSize['inX']+20, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+3, 'MAX', colors.purple, colors.black})
- table.insert(texts, {controlsSize['inX']+20, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, maxPowerRod..'%', colors.purple, colors.black})
- mon.setTextColor(colors.white)
- setButton("low-10","-10", modifyRods, controlsSize['inX'], controlsSize['inY'] +(controlsSize['sectionHeight']*2)+2, controlsSize['inX'] + math.floor(controlsSize['width']/2) -1, controlsSize['inY'] +(controlsSize['sectionHeight']*2)+4, "min", -10, colors.lightBlue)
- setButton("high-10","-10", modifyRods, controlsSize['inX'] + math.floor(controlsSize['width']/2) +2, controlsSize['inY'] +(controlsSize['sectionHeight']*2)+2, controlsSize['inX'] + controlsSize['width'], controlsSize['inY'] +(controlsSize['sectionHeight']*2)+4, "max", -10, colors.purple)
- setButton("low+10","+10", modifyRods, controlsSize['inX'], controlsSize['inY'] +(controlsSize['sectionHeight']*3)+2, controlsSize['inX'] + math.floor(controlsSize['width']/2) -1, controlsSize['inY'] +(controlsSize['sectionHeight']*3)+4, "min", 10, colors.lightBlue)
- setButton("high+10","+10", modifyRods, controlsSize['inX'] + math.floor(controlsSize['width']/2) +2, controlsSize['inY'] +(controlsSize['sectionHeight']*3)+2, controlsSize['inX'] + controlsSize['width'], controlsSize['inY'] +(controlsSize['sectionHeight']*3)+4, "max", 10, colors.purple)
- numbersSize['startX'] = infosSize['endX'] + margin + 1
- numbersSize['startY'] = controlsSize['endY'] + margin + 1
- numbersSize['endX'] = w-margin
- numbersSize['endY'] = h-margin
- numbersSize['height'] = numbersSize['endY']-numbersSize['startY']-(margin)-1
- numbersSize['width'] = numbersSize['endX']-numbersSize['startX']-(margin*2)-2
- numbersSize['inX'] = numbersSize['startX'] + margin +1
- numbersSize['inY'] = numbersSize['startY'] + margin
- table.insert(boxes, {numbersSize['startX'] , numbersSize['startY'], numbersSize['endX'], numbersSize['endY'], colors.gray})
- name = "NUMBERS"
- table.insert(lines, {numbersSize['startX'] + margin , numbersSize['startY'], numbersSize['startX'] + (margin*2) + #name+1, numbersSize['startY'], colors.black})
- table.insert(texts, {numbersSize['startX'] + (margin*2), numbersSize['startY'], name, colors.white, colors.black})
- refresh = true
- while refresh do
- parallel.waitForAny(refreshSingleReactor,clickEvent)
- end
- end
- function getAllStats()
- local stats = {}
- local reactor = reactors[1]
- if VERSION == "NEW" then
- if reactor.mbIsConnected() == true and reactor.mbIsAssembled() == true then
- local reactorEnergyStats = reactor.getEnergyStats()
- local reactorFuelStats = reactor.getFuelStats()
- stats["reactorRodsLevel"] = reactor.getControlRodsLevels()
- stats["rfTotal"] = reactorEnergyStats["energyStored"]
- stats["rfPerTick"] = math.ceil(reactorEnergyStats["energyProducedLastTick"])
- stats["rodLevel"] = stats["reactorRodsLevel"][0]
- stats["fuelPerTick"] = round(reactorFuelStats["fuelConsumedLastTick"], 2)
- end
- else
- stats["rfTotal"] = reactor.getEnergyStored()
- stats["rfPerTick"] = math.floor(reactor.getEnergyProducedLastTick())
- stats["rodLevel"] = math.floor(reactor.getControlRodLevel(0))
- stats["fuelPerTick"] = reactor.getFuelConsumedLastTick()
- end
- return stats
- end
- function refreshSingleReactor()
- local rfPerTick = 0
- local rfTotal = 0
- local rfTotalMax = 10000000
- local reactor = reactors[1]
- local allStats = getAllStats()
- rfTotal = allStats["rfTotal"]
- rfPerTick = allStats["rfPerTick"]
- rodLevel = allStats["rodLevel"]
- fuelPerTick = allStats["fuelPerTick"]
- local i = 0
- local infotoAdd = 'RF PER TICK : '
- if currentRfTick ~= rfPerTick then
- currentRfTick = rfPerTick
- if rfPerTick > rfPerTickMax then
- rfPerTickMax = rfPerTick
- end
- table.insert(lines, {numbersSize['inX'] , numbersSize['inY'],numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'], colors.black})
- table.insert(texts, {numbersSize['inX'], numbersSize['inY'], infotoAdd .. rfPerTick .. " RF", colors.white, colors.black})
- table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + infosSize['width'], infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.lightGray})
- width = math.floor((infosSize['width'] / rfPerTickMax)*rfPerTick)
- table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + width, infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.green})
- end
- i = 1
- infotoAdd = 'ENERGY STORED : '
- if currentRfTotal ~= rfTotal then
- currentRfTotal = rfTotal
- table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + infosSize['width'], infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.lightGray})
- width = math.floor((infosSize['width'] / rfTotalMax)*rfTotal)
- table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + width, infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.green})
- table.insert(lines, {numbersSize['inX'] , numbersSize['inY'] +2 ,numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'] +2, colors.black})
- table.insert(texts, {numbersSize['inX'], numbersSize['inY']+ 2 , infotoAdd .. rfTotal .. " RF", colors.white, colors.black})
- end
- i = 2
- infotoAdd = 'CONTROL ROD LEVEL : '
- if currentRodLevel ~= rodLevel then
- currentRodLevel = rodLevel
- table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + infosSize['width'], infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.lightGray})
- width = math.floor((infosSize['width'] / 100)*rodLevel)
- table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + width, infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.green})
- table.insert(lines, {numbersSize['inX'] , numbersSize['inY']+4 ,numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'] +4, colors.black})
- table.insert(texts, {numbersSize['inX'], numbersSize['inY']+ 4 , infotoAdd .. rodLevel .. "%", colors.white, colors.black})
- end
- i = 3
- infotoAdd = 'FUEL USAGE : '
- if currentFuelConsumedLastTick ~= fuelPerTick then
- currentFuelConsumedLastTick = fuelPerTick
- table.insert(lines, {numbersSize['inX'] , numbersSize['inY']+6 ,numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'] +6, colors.black})
- table.insert(texts, {numbersSize['inX'], numbersSize['inY']+ 6 , infotoAdd .. format_num(tonumber(fuelPerTick),3) .. "mb/t", colors.white, colors.black})
- end
- mon.setTextColor(colors.white)
- adjustRodsLevel()
- draw()
- sleep(2)
- end
- function getInfoFromFile()
- if (fs.exists(index..".txt") == false) then
- file = io.open(index..".txt","w")
- file:write("0")
- file:write("\n")
- file:write("100")
- file:close()
- else
- file = fs.open(index..".txt","r")
- minPowerRod = tonumber(file.readLine())
- maxPowerRod = tonumber(file.readLine())
- file.close()
- end
- end
- function setInfoToFile()
- file = io.open(index..".txt","w")
- file:write(minPowerRod .. "\n" .. maxPowerRod)
- file:flush()
- file:close()
- end
- function comma_value(amount)
- local formatted = amount
- while true do
- formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
- if (k==0) then
- break
- end
- end
- return formatted
- end
- function round(val, decimal)
- if (decimal) then
- return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
- else
- return math.floor(val+0.5)
- end
- end
- function format_num(amount, decimal, prefix, neg_prefix)
- local str_amount, formatted, famount, remain
- decimal = decimal or 2 -- default 2 decimal places
- neg_prefix = neg_prefix or "-" -- default negative sign
- famount = math.abs(round(amount,decimal))
- famount = math.floor(famount)
- remain = round(math.abs(amount) - famount, decimal)
- formatted = comma_value(famount)
- if (decimal > 0) then
- remain = string.sub(tostring(remain),3)
- formatted = formatted .. "." .. remain ..
- string.rep("0", decimal - string.len(remain))
- end
- formatted = (prefix or "") .. formatted
- if (amount<0) then
- if (neg_prefix=="()") then
- formatted = "("..formatted ..")"
- else
- formatted = neg_prefix .. formatted
- end
- end
- return formatted
- end
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setTextScale(0.5)
- getInfoFromFile()
- addDrawBoxesSingleReactor()
Advertisement
Add Comment
Please, Sign In to add comment