Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear()
- local battery
- local Tankinfos
- local TankCapacity
- local batteryCapacity
- local batteryLevel
- local batteyLevelPercent
- local reachedKick = false
- local savefile = "Backup.txt"
- local firststart
- local bundledcabel = 0
- local isInSettingmode = false
- local input
- function EditFile(text, action, file)
- local h
- if action == write then
- h = fs.open(file, fs.exists(file) and "w")
- h.write(text)
- elseif action == read then
- h = fs.open(file, "r")
- filecontent = h.readAll()
- return filecontent
- end
- h.close()
- end
- function converttofile(array)
- local Datatofile = textutils.serialize(array)
- EditFile(Datatofile,write,savefile)
- end
- function converttotable()
- local Datafromfile = EditFile("", read,savefile)
- local array = textutils.unserialize(Datafromfile)
- return array
- end
- if fs.exists(savefile) then
- firststart = false
- else
- fs.open(savefile, "w")
- firststart = true
- fs.open(savefile, "w").close()
- end
- function startedfirst()
- term.clear()
- term.setCursorPos(1,1)
- print("How many reactors do you have/plan to have?(max. 16) ")
- local numberofreactors = tonumber(io.read())
- if numberofreactors > 16 then
- term.clear()
- term.setBackgroundColor(colors.red)
- print("Number is to High!")
- sleep(1)
- startedfirst()
- end
- local Reactors = {}
- local percentstart = 55
- local percentincrease = math.ceil(55 / numberofreactors)
- local overwrite = false
- for n = 1, numberofreactors do
- Reactors[n] = {percentstart,overwrite}
- percentstart = percentstart - percentincrease
- end
- converttofile(Reactors)
- end
- if firststart then
- startedfirst()
- else
- -- local newTabID = multishell.launch({},"editor",)
- -- multishell.setTitle(newTabID, Editor)
- end
- function getValues()
- battery = peripheral.find("mfsu")
- Tank = peripheral.find("thermalexpansion_tank")
- local array = Tank.getTankInfo()
- TankCapacity = array[1].capacity
- batteryCapacity = battery.getEUCapacity()
- batteryLevel = battery.getEUStored()
- batteryLevelPercent = batteryLevel / batteryCapacity
- if array[1].contents == nil then
- TankLevel = 0
- else
- TankLevel = array[1].contents.amount
- end
- end
- function ReactorControl()
- if TankLevel < TankCapacity - 10000 then
- local reactors = converttotable()
- local percentvalues = {}
- if TankLevel > 50000 then
- rs.setOutput("left",true)
- elseif TankLevel < 10000 then
- rs.setOutput("left",false)
- end
- bundledcabel = 0
- for n = 1, #reactors do
- local percent = reactors[n][1]
- if batteryLevelPercent * 100 >= 100 then
- bundledcabel = 0
- elseif batteryLevelPercent * 100 < percent then
- bundledcabel = bundledcabel + (2^n)/2
- elseif reactors[n][2] == true then
- bundledcabel = bundledcabel + (2^n)/2
- end
- end
- redstone.setBundledOutput("right",bundledcabel)
- term.setBackgroundColor(colors.blue)
- term.clear()
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.orange)
- textutils.tabulate(colors.blue, {"Energy","Tank"}, colors.white,{batteryLevel.." of "..batteryCapacity,TankLevel.." of "..TankCapacity})
- term.setTextColor(colors.white)
- sleep(0.5)
- end
- end
- function input()
- input = io.read()
- if input == "s" then
- isInSettingmode = true
- end
- sleep(0,5)
- end
- function settingMenu()
- local reactors = converttotable()
- local reactorstatus
- term.clear()
- term.setCursorPos(1,1)
- for n = 1, #reactors do
- if reactors[n][1] then
- reactorstatus = "on"
- else
- reactorstatus = "off"
- end
- print("Reactor "..n..": "..reactorstatus)
- end
- term.clear()
- end
- while true do
- getValues()
- ReactorControl()
- sleep(0.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment