Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Mekanism Reactor / Energy Storage Info and Control (New Cytek Map)
- --automatic search in network
- local hw = {}
- local reactor
- local storage
- local B_reactor = 0
- local B_production = 0
- local B_load = 0
- local B_chest = 0
- local cable_side = "X"
- --load API
- shell.run("delete caAPI")
- shell.run("pastebin get EDLdR1nF caAPI")
- os.loadAPI("caAPI")
- --set monitor
- function set_monitor()
- local monitor_number = caAPI.get_hardware("monitor")
- local found = fs.exists("config/monitor.cfg")
- if found == true then
- file = fs.open("config/monitor.cfg","r")
- local fileData = {}
- local line = file.readLine()
- repeat
- table.insert(fileData,line)
- line = file.readLine()
- until line == nil
- file.close()
- monitor_number = fileData[1]
- end
- mon = peripheral.wrap(monitor_number)
- end
- --search mekanism maschine
- function search()
- local periList = peripheral.getNames()
- for i = 1, #periList do
- if peripheral.getType(periList[i]) == "mekanism_machine" then
- table.insert(hw,periList[i])
- end
- end
- end
- -- format number for print
- function format(num)
- out = tostring(math.floor(num)).." J"
- if num > 1000000000000 then
- num = num / 1000000000000
- out = tostring(math.floor(num)).." TJ"
- end
- if num > 1000000000 then
- num = num / 1000000000
- out = tostring(math.floor(num)).." GJ"
- end
- if num > 1000000 then
- num = num / 1000000
- out = tostring(math.floor(num)).." MJ"
- end
- if num > 1000 then
- num = num / 1000
- out = tostring(math.floor(num)).." KJ"
- end
- return out
- end
- -- search cable()
- function input_cable_side()
- local found = fs.exists("config.cfg")
- if found == false then
- mon.setTextColor(colors.white)
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setCursorPos(1,1)
- mon.write("Input side of BundledCable")
- input = read()
- cable_side = input
- local file = fs.open("config.cfg","w")
- file.writeLine(cable_side)
- file.close()
- else
- file = fs.open("config.cfg","r")
- local fileData = {}
- local line = file.readLine()
- repeat
- table.insert(fileData,line)
- line = file.readLine()
- until line == nil
- file.close()
- cable_side = fileData[1]
- end
- end
- -- set cable
- function set_cable()
- color_set_1 = colors.black
- if B_reactor == 1 then
- color_set_1 = color_set_1 + colors.white
- end
- if B_production == 1 then
- color_set_1 = color_set_1 + colors.orange
- end
- if B_load == 1 then
- color_set_1 = color_set_1 + colors.magenta
- end
- if B_chest == 1 then
- color_set_1 = color_set_1 + colors.yellow
- end
- shell.run("delete backup.db")
- local file = fs.open("backup.db","w")
- file.writeLine(tostring(B_reactor))
- file.writeLine(tostring(B_production))
- file.writeLine(tostring(B_load))
- file.close()
- sleep(1)
- rs.setBundledOutput(cable_side,color_set_1)
- end
- --draw screen
- function draw_screen()
- mon.setTextColor(colors.black)
- mon.setBackgroundColor(colors.white)
- mon.clear()
- mon.setCursorPos(1,1)
- mon.setTextColor(colors.white)
- mon.setBackgroundColor(colors.blue)
- mon.write("Mekanism Maschines Found "..tostring(#hw).." Maschines ")
- mon.setCursorPos(50,1)
- mon.setTextColor(colors.black)
- mon.setBackgroundColor(colors.red)
- mon.write("X")
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(35,3)
- mon.write("CableSide: "..cable_side)
- for i = 1, #hw do
- hwC = peripheral.wrap(hw[i])
- nameC = hwC.getInventoryName()
- if nameC == "Induction Matrix" then
- storage = peripheral.wrap(hw[i])
- end
- if nameC == "tile.Reactor.name.name" then
- reactor = peripheral.wrap(hw[i])
- end
- end
- storageN = storage.getInventoryName()
- reactorN = "Reactor"
- mon.setTextColor(colors.black)
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(2,2)
- mon.write(storageN)
- maxE = storage.getMaxEnergyStored()
- isE = storage.getEnergyStored()
- input = storage.getInput()
- output = storage.getOutput()
- precent = math.floor(100 * isE / maxE)
- maxF = format(maxE)
- isF = format(isE)
- inF = format(input)
- outF = format(output)
- mon.setCursorPos(2,4)
- mon.write("Max:"..maxF)
- mon.setCursorPos(2,5)
- mon.write("Is: "..isF.." "..tostring(precent).."%")
- mon.setCursorPos(2,6)
- mon.write("In: "..inF)
- mon.setCursorPos(2,7)
- mon.write("Out:"..outF)
- start_x = 4
- max_lines = 19
- lines = math.floor(precent * max_lines / 100)
- yx = 28
- for lix = 1, lines do
- if lix > 6 then
- mon.setBackgroundColor(colors.green)
- elseif lix > 3 then
- mon.setBackgroundColor(colors.yellow)
- else
- mon.setBackgroundColor(colors.red)
- end
- mon.setCursorPos(start_x,(yx-lix))
- mon.write(" ")
- end
- mon.setBackgroundColor(colors.white)
- yy = 8
- start_x = 3
- for li = 1, 19 do
- mon.setCursorPos(start_x,(yy+li))
- mon.write("|")
- mon.setCursorPos((start_x+7),(yy+li))
- mon.write("|")
- end
- mon.setCursorPos(25,2)
- mon.write(reactorN)
- maxR = reactor.getMaxEnergyStored()
- isR = reactor.getEnergyStored()
- precentR = math.floor(100 * isR / maxR)
- maxFR = format(maxR)
- isFR = format(isR)
- mon.setCursorPos(25,4)
- mon.write("Max:"..maxFR)
- mon.setCursorPos(25,5)
- mon.write("Is: "..isFR.." "..tostring(precentR).."%")
- start_x = 27
- max_lines = 19
- lines = math.floor(precentR * max_lines / 100)
- yx = 28
- for lix = 1, lines do
- if lix > 6 then
- mon.setBackgroundColor(colors.green)
- elseif lix > 3 then
- mon.setBackgroundColor(colors.yellow)
- else
- mon.setBackgroundColor(colors.red)
- end
- mon.setCursorPos(start_x,(yx-lix))
- mon.write(" ")
- end
- mon.setBackgroundColor(colors.white)
- yy = 8
- start_x = 26
- for li = 1, 19 do
- mon.setCursorPos(start_x,(yy+li))
- mon.write("|")
- mon.setCursorPos((start_x+7),(yy+li))
- mon.write("|")
- end
- color = colors.red
- if B_reactor == 0 then
- color = colors.green
- end
- mon.setBackgroundColor(color)
- mon.setCursorPos(35,9)
- mon.write(" ")
- mon.setCursorPos(35,10)
- mon.write(" Reactor/Laser ")
- mon.setCursorPos(35,11)
- mon.write(" On / Off ")
- mon.setCursorPos(35,12)
- mon.write(" ")
- color = colors.red
- if B_production == 0 then
- color = colors.green
- end
- mon.setBackgroundColor(color)
- mon.setCursorPos(35,14)
- mon.write(" ")
- mon.setCursorPos(35,15)
- mon.write(" DT Fuel Produc")
- mon.setCursorPos(35,16)
- mon.write(" On / Off ")
- mon.setCursorPos(35,17)
- mon.write(" ")
- color = colors.red
- if B_load == 0 then
- color = colors.green
- end
- mon.setBackgroundColor(color)
- mon.setCursorPos(35,19)
- mon.write(" ")
- mon.setCursorPos(35,20)
- mon.write(" Load Laser ")
- mon.setCursorPos(35,21)
- mon.write(" On / Off ")
- mon.setCursorPos(35,22)
- mon.write(" ")
- color = colors.yellow
- mon.setBackgroundColor(color)
- mon.setCursorPos(35,24)
- mon.write(" ")
- mon.setCursorPos(35,25)
- mon.write(" Refresh ")
- mon.setCursorPos(35,26)
- mon.write(" ")
- mon.setBackgroundColor(colors.green)
- mon.setCursorPos(11,14)
- mon.write(" ")
- mon.setCursorPos(11,15)
- mon.write(" Automatic ")
- mon.setCursorPos(11,16)
- mon.write(" Start ")
- mon.setCursorPos(11,17)
- mon.write(" ")
- mon.setBackgroundColor(colors.red)
- mon.setCursorPos(11,19)
- mon.write(" ")
- mon.setCursorPos(11,20)
- mon.write(" Automatic ")
- mon.setCursorPos(11,21)
- mon.write(" Stop ")
- mon.setCursorPos(11,22)
- mon.write(" ")
- touch()
- end
- function touch()
- local ix = true
- while ix == true do
- event, side, x, y = os.pullEvent()
- if event == "monitor_touch" then
- if x == 50 and y == 1 then
- ix = false
- shell.run("clear")
- end
- if x > 34 and x < 50 and y == 24 or y == 25 or y == 26 then
- ix = false
- draw_screen()
- end
- if x > 10 and x < 26 and y > 13 and y < 18 then
- ix = false
- B_load = 1
- set_cable()
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(11,24)
- mon.write("Load Laser")
- mon.setCursorPos(11,25)
- mon.write("Please wait..")
- sleep(3)
- B_production = 1
- set_cable()
- mon.setCursorPos(11,25)
- mon.write("Fuel production")
- for i=300,1,-1 do
- mon.setCursorPos(11,26)
- mon.write(tostring(i).." seconds left")
- sleep(1)
- end
- B_chest = 1
- set_cable()
- sleep(2)
- B_chest = 0
- B_reactor = 1
- set_cable()
- mon.setCursorPos(11,26)
- mon.write("Start Reactor")
- sleep(3)
- draw_screen()
- end
- if x > 10 and x < 26 and y > 18 and y < 23 then
- ix = false
- B_reactor = 0
- B_production = 0
- B_load = 0
- set_cable()
- draw_screen()
- end
- if x > 34 and x < 50 and y == 9 or y == 10 or y == 11 or y == 12 then
- ix = false
- if B_reactor == 0 then
- B_reactor = 1
- else
- B_reactor = 0
- end
- set_cable()
- draw_screen()
- end
- if x > 34 and x < 50 and y == 14 or y == 15 or y == 16 or y == 17 then
- ix = false
- if B_production == 0 then
- B_production = 1
- else
- B_production = 0
- end
- set_cable()
- draw_screen()
- end
- if x > 34 and x < 50 and y == 19 or y == 20 or y == 21 or y == 22 then
- ix = false
- if B_load == 0 then
- B_load = 1
- else
- B_load = 0
- end
- set_cable()
- draw_screen()
- end
- end
- end
- end
- --start program
- set_monitor()
- input_cable_side()
- search()
- local found = fs.exists("backup.db")
- if found == true then
- print("load backup")
- file = fs.open("backup.db","r")
- local fileData = {}
- local line = file.readLine()
- repeat
- table.insert(fileData,line)
- line = file.readLine()
- until line == nil
- file.close()
- B_reactor = tonumber(fileData[1])
- B_production = tonumber(fileData[2])
- B_load = tonumber(fileData[3])
- if B_reactor == 1 and B_production == 1 and B_load == 1 then
- B_reactor = 0
- set_cable()
- mon.setTextColor(colors.white)
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setCursorPos(1,1)
- mon.setTextColor(colors.white)
- mon.write("Please wait, load Laser for Reactor reboot")
- for i=300,1,-1 do
- mon.setCursorPos(1,2)
- mon.write(tostring(i).." seconds left")
- sleep(1)
- end
- B_chest = 1
- set_cable()
- sleep(2)
- B_chest = 0
- B_reactor = 1
- set_cable()
- sleep(1)
- end
- set_cable()
- end
- draw_screen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement