Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local rp = "back" -- Location Reactor Redstone Port
- local rfp = "reactor_fluid_port_9" -- Location Reactor Fluid Port
- local nr = "nuclear_reactor_3" -- Location Reactor Access Hatch
- local IsActive = "PlaceHolder"
- local ml = "right" -- Location Modem
- local server = "rs3"
- term.clear()
- function PreCheckModem()
- print("function PreChecks modem check")
- isOpenRednet = rednet.isOpen(ml)
- if isOpenRednet == true then
- print("function PreChecks Rednet is open")
- elseif isOpenRednet == false then
- rednet.open(ml)
- isOpenRednet = rednet.isOpen(ml)
- if isOpenRednet == true then
- print("function PreChecks Rednet is open")
- else
- error("function PreChecks unable to open Rednet")
- end
- else
- error("function PreChecks unknown error")
- end
- print("function PreChecks modem seems ok")
- rednet.host("rctrl",server)
- end
- function PreCheckPerfs()
- print("Start peripheral checks")
- if not peripheral.isPresent(nr) then
- error("function PreCheckPerfs missing:"..nr)
- elseif not peripheral.isPresent(rfp) then
- error("function PreCheckPerfs missing:"..rfp)
- end
- print("All peripherals present")
- end
- function TurnOn()
- redstone.setOutput(rp, true)
- end
- function TurnOff()
- redstone.setOutput(rp, false)
- end
- function Status()
- IsActive = redstone.getOutput(rp)
- return IsActive
- end
- function WriteStatus()
- if IsActive==false then
- write("Reactor is inactive")
- elseif IsActive==true then
- write("Reactor is active")
- else
- write("Unknown reactor status")
- end
- end
- function LiquidTanks()
- tank = peripheral.wrap(rfp)
- EmptyCounter = 0
- while true do
- term.clear()
- term.setCursorPos(1,1)
- tankI = tank.getTankInfo()
- if tankI[2] == nil then
- EmptyCounter = EmptyCounter + 1
- else
- EmptyCounter = 0
- if tankI[1]["contents"]["name"] == "ic2coolant" then
- ic2c = tankI[1]
- elseif tankI[1]["contents"]["name"] == "ic2hotcoolant" then
- ic2hc = tankI[1]
- else
- error("Incorrect liquid in "..tankI[1]["contents"]["name"])
- end
- if tankI[2]["contents"]["name"] == "ic2coolant" then
- ic2c = tankI[2]
- elseif tankI[2]["contents"]["name"] == "ic2hotcoolant" then
- ic2hc = tankI[2]
- else
- error("Incorrect liquid in "..tankI[1]["contents"]["name"])
- end
- ic2cValueC = ic2c["contents"]["amount"]
- ic2hcValueC = ic2hc["contents"]["amount"]
- x = ic2cValueC / 10000 * 100
- --print("Coolant for :"..math.floor(x).."% full")
- if x < 50 then
- print("warning!! Coolant level below :"..math.floor(x).."% full")
- else
- print("Coolant level is :"..math.floor(x).."% full")
- end
- y = ic2hcValueC / 10000 * 100
- --print("Coolant for :"..math.floor(y).."% full")
- if y > 50 then
- print("warning!! Hot Coolant level above :"..math.floor(y).."% full")
- else
- print("Hot Coolant level is :"..math.floor(y).."% full")
- end
- sleep(0.5)
- end
- end
- end
- -- Let's start the program
- PreCheckModem()
- PreCheckPerfs()
- local ok, err = pcall(LiquidTanks)
- if not ok then
- TurnOff()
- end
- while true do
- term.clear()
- write("1=Turnon,2=TurnOff,3=Status,q=Quit,t=tank info")
- local answer = read()
- -- return answer
- if answer=="1" then
- TurnOn()
- Status()
- WriteStatus()
- elseif answer=="2" then
- TurnOff()
- Status()
- WriteStatus()
- elseif answer== "3" then
- Status()
- if IsActive==false then
- write("Reactor Inactive")
- elseif IsActive==true then
- write("Reactor active")
- else
- write("unknown status")
- end
- sleep(2)
- elseif answer=="q" then
- break
- elseif answer=="t" then
- LiquidTanks()
- sleep(2)
- else
- print("wrong input")
- end
- answer = nil
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement