Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- reactor_pos = nil
- sides = {"top" , "bottom" , "front" , "left" , "right" , "back"}
- reactor_file = "reactor.txt"
- function clear()
- term.setBackgroundColor(colors.green)
- term.clear()
- return nil
- end
- function newline()
- local x, y = term.getCursorPos()
- term.setCursorPos(x, y + 1)
- end
- function setReactorPos()
- clear()
- term.setCursorPos(15, 7)
- term.write("Select reactor possition")
- term.setCursorPos(15, 8)
- term.write("1: Top, 2: Bot, 3: Front")
- term.setCursorPos(15, 9)
- term.write("4: Left, 5: Right, 6: Back")
- term.setCursorPos(15, 10)
- reactor_pos = tonumber(read())
- local file = fs.open(reactor_file, "w")
- file.write(reactor_pos)
- flie.close()
- end
- function DetectPeripheral(name)
- for i = 1, 6 do
- if peripheral.isPresent(sides[i]) and peripheral.getType(sides[i]) == name then
- return sides[i]
- end
- end
- return nil
- end
- function rednetControll()
- while true do
- wifi = DetectPeripheral("modem")
- rednet.open(wifi)
- a, b, c = rednet.receive()
- return b;
- end
- end
- function keyControll()
- while true do
- local sEvent, param = os.pullEvent("key")
- if sEvent == "key" then
- if param == "45" then
- if redstone.getOutput(reactor_pos) then
- return "stop"
- else
- return "start"
- end
- end
- end
- end
- end
- function Menu()
- clear()
- term.setCursorPos(19, 8)
- if redstone.getOutput(sides[reactor_pos]) then
- term.write("ALL WORKS!")
- else
- term.write("NOTHING WORKS!")
- end
- term.setCursorPos(15, 9)
- term.write("REACTOR IS ON "..sides[reactor_pos])
- term.setCursorPos(15, 10)
- term.write("PRESS X TO CHANGE")
- end
- --
- if not fs.exists(reactor_file) then
- setReactorPos()
- else
- local file = fs.open(reactor_file, "r")
- reactor_pos = sides[tonumber(fs.readAll())]
- file.close()
- end
- while true do
- command, id = parallel.waitForAny(rednetControll, keyControll, Menu)
- if command == "start" then
- redstone.setOutput(reactor_pos, 1)
- if not id == nil then
- rednet.send(id, true)
- end
- elseif command == "stop" then
- redstone.setOutput(reactor_pos, 0)
- if not id == nil then
- rednet.send(id, false)
- end
- elseif command == "state" then
- rednet.send(id, redstone.getOutput(reactor_pos))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment