Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- screen = peripheral.wrap("monitor_55")
- screen.setTextScale(1.5)
- r = peripheral.wrap("back")
- r.chargeReactor()
- local m = peripheral.wrap("monitor_54") --Monitor wrapping
- m.setTextScale(1)
- local bState = true --Variables for storing state of button
- local bState1 = true
- --Toggle
- function drawButton(state,pos,mo) --arguments : State: true/false, pos:{x,y}, mo:monitor index in m
- local mon = m --get monitor to be used
- local txt = "" --ON/OFF text to be used later, declared here so accessable in entire function
- mon.setCursorPos(pos[1],pos[2]) --setting cursorPos to pos argument
- if state then
- mon.setBackgroundColor(colors.green) --if state is true, set background to green and txt to ON
- txt = "ON"
- else
- mon.setBackgroundColor(colors.red) --if state is false, set background to red and txt to OFF
- txt = "OFF"
- end
- mon.write(string.rep(" ",5)) --draw " " with background colour set before
- mon.setCursorPos(pos[1]+1,pos[2]) --Go back to pos and move right by 1
- mon.write(txt) --write txt so it is centered
- end
- while true do
- screen.clear()
- screen.setCursorPos(1,1)
- screen.setTextColor(colors.white)
- info = r.getReactorInfo()
- -- Reactor Main Status
- status = info["status"]
- screen.write("Draconic Reactor Status: ")
- if status == "online" then
- screen.setTextColor(colors.green)
- screen.write("Online")
- elseif (status == "stopping") then
- screen.setTextColor(colors.lime)
- screen.write("Stopping")
- elseif (status == "charging") then
- screen.setTextColor(colors.lightBlue)
- screen.write("Charging")
- elseif (status == "charged") then
- screen.setTextColor(colors.blue)
- screen.write("Charged")
- r.activateReactor()
- elseif (status == "offline") then
- screen.setTextColor(colors.red)
- screen.write("Offline")
- end
- -- Reactor Output
- screen.setCursorPos(1,2)
- screen.setTextColor(colors.white)
- gen = info["generationRate"]
- screen.write("Gross Energy: ")
- screen.setTextColor(colors.green)
- screen.write(gen.. " RF/t")
- -- Reactor Temperature
- screen.setCursorPos(1,3)
- temp = info["temperature"]
- screen.setTextColor(colors.white)
- screen.write("Temperature: ")
- if (temp <= 6000) then
- screen.setTextColor(colors.blue)
- screen.write(temp)
- elseif (temp >= 7000) then
- screen.setTextColor(colors.red)
- screen.write(temp)
- else
- screen.setTextColor(colors.yellow)
- screen.write(temp.. " C.")
- end
- -- Containment Field Strength
- screen.setCursorPos(1,4)
- screen.setTextColor(colors.white)
- field = info["fieldStrength"]
- fieldi = info["fieldDrainRate"]
- screen.write("Field Strength: ")
- maxField = info["maxFieldStrength"]
- screen.setTextColor(colors.green)
- local fieldr = math.ceil(((field/maxField)*10000)-0.49999)/100
- screen.write(fieldr.. "%")
- -- Energy Saturation
- screen.setCursorPos(1,5)
- screen.setTextColor(colors.white)
- maxSat = info["maxEnergySaturation"]
- sat = info["energySaturation"]
- screen.write("Energy Saturation: ")
- screen.setTextColor(colors.green)
- local satr = math.ceil(((sat/maxSat)*10000)-0.49999)/100
- screen.write(satr.." % ")
- -- Fuel Conversion rate/ Consumed
- screen.setCursorPos(1,6)
- screen.setTextColor(colors.white)
- fuel = info["fuelConversion"]
- fuelRate = info["fuelConversionRate"]
- maxFuel = info["maxFuelConversion"]
- screen.write("Fuel Converted: ")
- screen.setTextColor(colors.green)
- local rate = math.ceil(((fuel/maxFuel)*10000)-0.4999)/100
- screen.write(rate.. " % ")
- -- Net Output
- screen.setCursorPos(1,7)
- screen.setTextColor(colors.white)
- screen.write("Current Output: ")
- screen.setTextColor(colors.green)
- local out = (gen-fieldi)
- screen.write(out.. " Rf/t")
- -- Reactor Emergency Code
- local d = (field/maxField)
- local e = (sat/maxSat)
- --if ((status == "charging" and d = 0) or status == "stopping") then redstone.setAnalogOutput("right", 9)
- local red = math.ceil(((1-d)*15))
- redstone.setAnalogOutput("right", red)
- sleep(0.1)
- -- Redstone Input for Shutdown
- if redstone.getInput("left") == true then
- r.stopReactor()
- end
- if (status == "online" and (d <= 0.10 or e <= 0.10)) then
- r.stopReactor()
- screen.clear()
- screen.setCursorPos(1,1)
- screen.setTextColor(colors.red)
- screen.setTextScale(2)
- screen.write("Commencing Emergency!")
- screen.setCursorPos(1,3)
- screen.write("Shutting down...")
- sleep(8)
- screen.setTextScale(1.5)
- end
- m.setBackgroundColor(colors.black) --Clearing monitor
- m.clear()
- drawButton(bState,{1,1},1) --Draw buttons using function above at different places, with state set to
- os.startTimer(0.25) --start 0.25 second timer, so script listens for monitor touch event for 0.25 seconds before
- while true do --updating buttons again
- evt = {os.pullEvent()} --Loop pulling events until "timer" or "monitor_touch" event is found
- if evt[1] == "timer" then
- break --If timer event found, break out of the while true loop on line 31
- elseif evt[1] == "monitor_touch" then
- local monT = evt[2] --if monitor touch event found, set variables to monitor name, x and y
- local x = evt[3]
- local y = evt[4]
- if monT == "monitor_54" then --if monitor found is on top face
- if x>=2 and x<=6 and y==3 then --if x and y found are within the coloured box of the button
- bState = not bState --set bState to oposite of what it current is (true to false, false to true)
- if bState then
- r.activateReactor()
- else
- r.stopReactor()
- end
- break --break out of loop to update buttons instantly
- elseif x>=2 and x<=6 and y==4 then --same thing for other button
- bState1 = not bState1
- break
- end
- end --A million end's
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement