Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shell.run("clear")
- dbcol = colors.black
- dtcol = colors.lime
- diskR = ""
- outp = "bottom"
- print("REACTOR CORE")
- function mbut(cx,cy,text,bcol,tcol)
- if bcol == nil then
- bcol = dbcol
- end
- if tcol == nil then
- tcol = dtcol
- end
- mon.setCursorPos(cx,cy)
- mon.setBackgroundColor(bcol)
- mon.setTextColor(tcol)
- mon.write(string.rep(" ",#text))
- mon.setCursorPos(cx,cy)
- mon.write(text)
- mon.setBackgroundColor(dbcol)
- mon.setTextColor(dtcol)
- end
- reactor_colors = {colors.yellow,colors.orange,colors.cyan,colors.purple,colors.pink,colors.magenta,colors.brown,colors.gray, colors.lightBlue, colors.white}
- function rows(ry)
- if ry == nil then
- mbut(2,y,"|")
- mbut(27,y,"|")
- mbut(52,y,"|")
- mbut(78,y,"|")
- else
- mbut(2,ry,"|")
- mbut(27,ry,"|")
- mbut(52,ry,"|")
- mbut(78,ry,"|")
- end
- end
- function line(ly)
- if ly == nil then
- mbut(2,y,"+")
- mbut(3,y,string.rep("-",74))
- mbut(27,y,"+")
- mbut(52,y,"+")
- mbut(78,y,"+")
- else
- mbut(2,ly,"+")
- mbut(3,ly,string.rep("-",74))
- mbut(27,ly,"+")
- mbut(52,ly,"+")
- mbut(78,ly,"+")
- end
- end
- function frame()
- for y = 1,37,1 do
- rows(y)
- end
- end
- state = false
- rs.setOutput(outp,false)
- machines = {}
- machines = peripheral.getNames()
- mon = ""
- reactors = {}
- for v, k in pairs(machines) do
- if string.find(k,"monitor") ~= nil then
- mon = peripheral.wrap(k)
- mon.setTextScale(0.5)
- mon.clear()
- end
- if string.find(k,"reactor") ~= nil then
- table.insert(reactors,k)
- end
- if string.find(k,"chest_diamond") ~= nil then
- chest = peripheral.wrap(k)
- chestAPI = k
- end
- if string.find(k,"drive") ~= nil then
- drive = peripheral.wrap(k)
- driveAPI = k
- function readDisk(state)
- if state == nil then
- diskR = fs.open("disk/akw.lua","r")
- if diskR == nil then
- create = fs.open("disk/akw.lua","w")
- create.write(false)
- create.close()
- end
- reading = diskR.readAll()
- diskR.close()
- return reading
- else
- diskR = fs.open("disk/"..state..".lua","r")
- if diskR == nil then
- create = fs.open("disk/"..state..".lua","w")
- create.write(false)
- create.close()
- end
- reading = diskR.readAll()
- diskR.close()
- return reading
- end
- end
- function saveDisk(text,state)
- if state == nil then
- disk = fs.open("disk/akw.lua","w")
- disk.write(text)
- disk.close()
- else
- if type(text) == "table" then
- disk = fs.open("disk/"..state..".lua","w")
- for a, b in pairs(text) do
- disk.writeLine(b)
- end
- disk.close()
- else
- disk = fs.open("disk/"..state..".lua","w")
- disk.write(text)
- disk.close()
- end
- end
- end
- end
- end
- while true do
- mbut(28,35," ")
- x = 2
- y = 2
- sum = 0
- reactorsStats = {}
- frame()
- line(1)
- line(5)
- line(19)
- line(33)
- line(37)
- mbut(52,34," ")
- mbut(52,35," ")
- mbut(52,36," ")
- y = 7
- saveDisk(reactors,"ids")
- for v,k in pairs(reactors) do
- mod = v % 3
- if mod == 0 then
- x = 54
- y = y - 14
- elseif mod == 1 then
- x = 4
- elseif mod == 2 then
- x = 29
- y = y - 14
- end
- reactor = peripheral.wrap(k)
- reactorAPI = k
- reactorCore = reactor.getReactorCore()
- data = reactorCore.getMetadata()
- stats = data["reactor"]
- reactor_status = stats.active
- reactor_heat = stats.heat
- reactor_eu = stats.euOutput
- reactor_maxHeat = stats.maxHeat
- eu = string.format("%d",reactor_eu)
- sum = sum + eu
- rows()
- col = 0
- if fs.exists("disk/akw.lua") == nil then
- state = false
- saveDisk(state)
- else
- state = readDisk()
- if state == nil then
- state = "false"
- saveDisk(state)
- end
- end
- if reactor_heat >= 2000 then
- state = false
- saveDisk(state)
- end
- print("[" .. v .. "] " .. state)
- mbut(4,3,"All Reactors: ")
- mbut(20,3,"|")
- if state == "true" then
- rs.setOutput(outp,true)
- mbut(18,3,"ON",colors.green)
- mbut(21,3,"OFF")
- elseif state == "false" or state == "nil" then
- rs.setOutput(outp,false)
- mbut(18,3,"ON")
- mbut(21,3,"OFF",colors.red)
- end
- saveReactor = textutils.serialize({k,x,y,reactor_status})
- if reactor_status == true then
- reactor_status = "ON"
- col = colors.green
- else
- reactor_status = "OFF"
- col = colors.red
- end
- mbut(x,y," ")
- rCol = reactor_colors[v]
- mbut(x,y,"REACTOR: " .. v,nil,rCol)
- saveDisk(saveReactor,k)
- y = y + 1
- rows()
- mbut(x,y," ")
- mbut(x,y,"ACTIVE: " .. reactor_status,nil,col)
- y = y + 1
- rows()
- mbut(x,y," ")
- mbut(x,y,"EU/T: " .. eu)
- y = y + 1
- mbut(x,y," ")
- mbut(x,y,"HEAT: " .. reactor_heat .. " / " .. reactor_maxHeat)
- y = y + 1
- mbut(x,y,"RODS STATUS:" )
- y = y + 1
- cells = {}
- for a,b in pairs(reactor.list()) do
- meta = reactor.getItemMeta(a)
- if string.find(meta.displayName,"Dual Uranium Cell") ~= nil then
- dama = meta.damage
- table.insert(cells,dama)
- end
- end
- if #cells < 8 then
- c = 8-#cells
- for ce = 1,c,1 do
- table.insert(cells,0)
- end
- end
- x2 = x
- y2 = y
- for a,b in pairs(cells) do
- mod = a % 2
- if mod == 1 then
- x2 = x
- y2 = y2 + 1
- else
- x2 = x2 + 8
- end
- dMax = 20
- d = b
- perc = 100/dMax * d
- sD = string.format("%3d",perc)
- rCol = reactor_colors[a]
- mbut(x2,y2,a .. ": " .. sD .. "%",nil,rCol)
- end
- y = y + 9
- end
- mbut(4,35," ")
- mbut(4,35,"Total EU/T: " .. sum, nil, colors.blue)
- y = y + 1
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment