Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --BigReactor Info Control
- --automatic search in network
- --for max 4 Reactors
- local hw = {}
- local hwB = {}
- local change_type
- --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 reactores and turbines
- function search()
- local periList = peripheral.getNames()
- for i = 1, #periList do
- if peripheral.getType(periList[i]) == "BigReactors-Reactor" then
- table.insert(hw,periList[i])
- end
- end
- local periList = peripheral.getNames()
- for i = 1, #periList do
- if peripheral.getType(periList[i]) == "BigReactors-Turbine" then
- table.insert(hwB,periList[i])
- end
- end
- end
- --draw screen
- function draw_screen()
- mon.setTextColor(1)
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setCursorPos(2,1)
- mon.setTextColor(colors.blue)
- num = #hw
- numB = #hwB
- mon.write("Reactor Control Screen")
- mon.setCursorPos(2,2)
- mon.write("Found "..num.." Reactors and "..numB.." Turbines")
- mon.setCursorPos(50,1)
- mon.setBackgroundColor(colors.red)
- mon.setTextColor(colors.black)
- mon.write("X")
- line = 3
- for i = 1, #hw do
- mon.setCursorPos(2,line)
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.red)
- mon.write("Reactor Port:"..hw[i])
- mon.setTextColor(colors.black)
- reactor = peripheral.wrap(hw[i])
- line = line + 1
- mon.setCursorPos(2,line)
- stat = reactor.getActive()
- if stat == false then
- mon.setBackgroundColor(colors.green)
- mon.write("Turn On")
- else
- mon.setBackgroundColor(colors.red)
- mon.write("Turn Off")
- end
- line = line + 1
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.green)
- mon.setCursorPos(2,line)
- mon.write("Set Rod:")
- mon.write(reactor.getControlRodLevel(0),"%")
- mon.write("%")
- mon.setBackgroundColor(colors.red)
- mon.setTextColor(colors.black)
- mon.setCursorPos(20,line)
- mon.write("0%")
- mon.setCursorPos(24,line)
- mon.write("50%")
- mon.setCursorPos(29,line)
- mon.write("100%")
- line = line + 2
- end
- change_type = line
- for i = 1, #hwB do
- mon.setCursorPos(2,line)
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.red)
- mon.write("Reactor Port:"..hwB[i])
- mon.setTextColor(colors.black)
- turbine = peripheral.wrap(hwB[i])
- line = line + 1
- mon.setCursorPos(2,line)
- stat = turbine.getActive()
- if stat == false then
- mon.setBackgroundColor(colors.green)
- mon.write("Turn On")
- else
- mon.setBackgroundColor(colors.red)
- mon.write("Turn Off")
- end
- line = line + 2
- end
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.white)
- touch()
- end
- --touch
- 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 y == 4 then
- ix = false
- if y > change_type then
- if (y - change_type) == 1 then
- num = 1
- end
- if (y - change_type) > 5 then
- num = 2
- end
- if (y - change_type) > 10 then
- num = 3
- end
- if (y - change_type) > 15 then
- num = 4
- end
- if hwB[num] ~= nil then
- turbine = peripheral.wrap(hwB[num])
- stat = turbine.getActive()
- if stat == false then
- turbine.setActive(true)
- else
- turbine.setActive(false)
- end
- end
- else
- num = 1
- if hw[num] ~= nil then
- reactor = peripheral.wrap(hw[num])
- stat = reactor.getActive()
- if stat == false then
- reactor.setActive(true)
- else
- reactor.setActive(false)
- end
- end
- end
- draw_screen()
- end
- if y == 8 then
- ix = false
- if y > change_type then
- if (y - change_type) == 1 then
- num = 1
- end
- if (y - change_type) > 5 then
- num = 2
- end
- if (y - change_type) > 10 then
- num = 3
- end
- if (y - change_type) > 15 then
- num = 4
- end
- if hwB[num] ~= nil then
- turbine = peripheral.wrap(hwB[num])
- stat = turbine.getActive()
- if stat == false then
- turbine.setActive(true)
- else
- turbine.setActive(false)
- end
- end
- else
- num = 2
- if hw[num] ~= nil then
- reactor = peripheral.wrap(hw[num])
- stat = reactor.getActive()
- if stat == false then
- reactor.setActive(true)
- else
- reactor.setActive(false)
- end
- end
- end
- draw_screen()
- end
- if y == 12 then
- ix = false
- if y > change_type then
- if (y - change_type) == 1 then
- num = 1
- end
- if (y - change_type) > 5 then
- num = 2
- end
- if (y - change_type) > 10 then
- num = 3
- end
- if (y - change_type) > 15 then
- num = 4
- end
- if hwB[num] ~= nil then
- turbine = peripheral.wrap(hwB[num])
- stat = turbine.getActive()
- if stat == false then
- turbine.setActive(true)
- else
- turbine.setActive(false)
- end
- end
- else
- num = 3
- if hw[num] ~= nil then
- reactor = peripheral.wrap(hw[num])
- stat = reactor.getActive()
- if stat == false then
- reactor.setActive(true)
- else
- reactor.setActive(false)
- end
- end
- end
- draw_screen()
- end
- if y == 16 then
- ix = false
- if y > change_type then
- if (y - change_type) == 1 then
- num = 1
- end
- if (y - change_type) > 5 then
- num = 2
- end
- if (y - change_type) > 10 then
- num = 3
- end
- if (y - change_type) > 15 then
- num = 4
- end
- if hwB[num] ~= nil then
- turbine = peripheral.wrap(hwB[num])
- stat = turbine.getActive()
- if stat == false then
- turbine.setActive(true)
- else
- turbine.setActive(false)
- end
- end
- else
- num = 4
- if hw[num] ~= nil then
- reactor = peripheral.wrap(hw[num])
- stat = reactor.getActive()
- if stat == false then
- reactor.setActive(true)
- else
- reactor.setActive(false)
- end
- end
- end
- draw_screen()
- end
- if y == 5 and x > 19 and x < 24 then
- ix = false
- num = 1
- if hw[num] ~= nil then
- reactor = peripheral.wrap(hw[num])
- reactor.setAllControlRodLevels(0)
- end
- draw_screen()
- end
- if y == 5 and x > 23 and x < 29 then
- ix = false
- num = 1
- if hw[num] ~= nil then
- reactor = peripheral.wrap(hw[num])
- reactor.setAllControlRodLevels(50)
- end
- draw_screen()
- end
- if y == 5 and x > 28 and x < 33 then
- ix = false
- num = 1
- if hw[num] ~= nil then
- reactor = peripheral.wrap(hw[num])
- reactor.setAllControlRodLevels(100)
- end
- draw_screen()
- end
- if y == 9 and x > 19 and x < 24 then
- ix = false
- num = 2
- if hw[num] ~= nil then
- reactor = peripheral.wrap(hw[num])
- reactor.setAllControlRodLevels(0)
- end
- draw_screen()
- end
- if y == 9 and x > 23 and x < 29 then
- ix = false
- num = 2
- if hw[num] ~= nil then
- reactor = peripheral.wrap(hw[num])
- reactor.setAllControlRodLevels(50)
- end
- draw_screen()
- end
- if y == 9 and x > 28 and x < 33 then
- ix = false
- num = 2
- if hw[num] ~= nil then
- reactor = peripheral.wrap(hw[num])
- reactor.setAllControlRodLevels(100)
- end
- draw_screen()
- end
- if y == 13 and x > 19 and x < 24 then
- ix = false
- num = 3
- if hw[num] ~= nil then
- reactor = peripheral.wrap(hw[num])
- reactor.setAllControlRodLevels(0)
- end
- draw_screen()
- end
- if y == 13 and x > 23 and x < 29 then
- ix = false
- num = 3
- if hw[num] ~= nil then
- reactor = peripheral.wrap(hw[num])
- reactor.setAllControlRodLevels(50)
- end
- draw_screen()
- end
- if y == 13 and x > 28 and x < 33 then
- ix = false
- num = 3
- if hw[num] ~= nil then
- reactor = peripheral.wrap(hw[num])
- reactor.setAllControlRodLevels(100)
- end
- draw_screen()
- end
- if y == 17 and x > 19 and x < 24 then
- ix = false
- num = 4
- if hw[num] ~= nil then
- reactor = peripheral.wrap(hw[num])
- reactor.setAllControlRodLevels(0)
- end
- draw_screen()
- end
- if y == 17 and x > 23 and x < 29 then
- ix = false
- num = 4
- if hw[num] ~= nil then
- reactor = peripheral.wrap(hw[num])
- reactor.setAllControlRodLevels(50)
- end
- draw_screen()
- end
- if y == 17 and x > 28 and x < 33 then
- ix = false
- num = 4
- if hw[num] ~= nil then
- reactor = peripheral.wrap(hw[num])
- reactor.setAllControlRodLevels(100)
- end
- draw_screen()
- end
- end
- end
- end
- --prog start
- set_monitor()
- search()
- draw_screen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement