Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Some usefull commands
- getFuelAmount
- getFuelAmountMax
- getFuelConsumedLastTick
- getActive
- getCaseingTemperature
- getControlRodLevel
- getEnergyCapacity
- getEnergyProducedLastTick
- GetEnergyStored
- setAllControlRodLevels
- --]]
- --[[ NOTE
- // With automode on the code will try to keep
- // around 10% RF in its internal storage, it does this by regulating the control rod
- // after the demand OF rf, moving up slowly. due note that the 10% is changeable in the var
- // "targetP"
- --]]
- -- Wrapping and requireing essentials API's and components --
- component = require("component")
- reactor = component.br_reactor
- event = require("event")
- term = require("term")
- gpu = component.gpu
- event = require("event")
- keyboard = require("keyboard")
- ------------------
- -- Color table --
- colors = { black = 0x000000, white = 0xf8f8ff, blue = 0x0000ff, lightGray = 0xd9d9d9, red = 0xff0000,
- purple = 0x9b30ff, carrot = 0xffa500, magenta = 0xcd00cd, lightBlue = 0x87cefa, yellow = 0xffff00,
- lime = 0x32cd32, pink = 0xffc0cb, gray = 0x696969, brown = 0x8b4500, green = 0x006400, cyan = 0x008b8b,
- olive = 0x6b8e23, gold = 0x8b6914, orangered = 0xdb4e02, diamond = 0x0fa7c7,crimson = 0xaf002a,fuchsia = 0xfd3f92,
- folly = 0xff004f, frenchBlue = 0x0072bb, lilac = 0x86608e, flax = 0xeedc82, darkGray = 0x563c5c,
- englishGreen = 0x1b4d3e, eggplant = 0x614051, deepPink = 0xff1493, ruby = 0x843f5b, orange = 0xf5c71a,
- lemon = 0xffd300, darkBlue = 0x002e63, bitterLime = 0xbfff00 }
- -------------------------
- --Vars --
- auto = false
- numm = 100
- targetP = 30 -- This is the target percentage the computer will strive for to keep in the reactor
- Border_bg = colors.englishGreen
- Default_bg = colors.lightGray
- text_col = colors.black
- --
- -- Settings for screen --
- gpu.setResolution(60,20)
- -------------------------
- -- Functions --
- function guiBorders(x,y,len,height,str)
- gpu.setBackground(Border_bg)
- gpu.fill(x,y,len,height,str)
- gpu.setBackground(Default_bg)
- end
- function GUI()
- gpu.setBackground(Default_bg)
- w, h = gpu.getResolution()
- guiBorders(1,1,w,1," ")
- for i = 1,h do
- guiBorders(1,i,1,1," ")
- guiBorders(w,i,1,1," ")
- end
- guiBorders(1,h,w,1," ")
- gpu.setForeground(text_col)
- end
- function Center(y,text)
- w, h = gpu.getResolution()
- term.setCursor((w-string.len(text))/2+1, y)
- term.write(text)
- end
- function display()
- RP = math.floor((reactor.getEnergyStored()/reactor.getEnergyCapacity()*100))
- if auto == false then
- if stat == true then
- Center(4, " ON ")
- else
- Center(4, "OFF ")
- end
- elseif auto == true then
- Center(4, "AUTO")
- end
- Center(2, "----Reactor Info---- ")
- gpu.set(3,3, "Mode............: ")
- --Function buttonPress
- gpu.set(3,6, "RF Production...: ")
- Center(7, string.format("%.2f", reactor.getEnergyProducedLastTick()).." RF/T ")
- gpu.set(3,9, "RF Internal.....: ")
- Center(10, reactor.getEnergyStored() .."/"..reactor.getEnergyCapacity().."(".. RP .."%) RF ")
- gpu.set(3,12, "Fuel use........: ")
- Center(13, string.format("%.2f", reactor.getFuelConsumedLastTick()) .."mB")
- Center(16,"Mode Selection")
- gpu.setBackground(colors.white)
- gpu.setForeground(text_col)
- gpu.set(15,17, " ON ")
- gpu.set(25,17, " OFF ")
- gpu.set(35,17, " Auto ")
- gpu.setBackground(Default_bg)
- gpu.set(17,7," ")
- gpu.setBackground(Default_bg)
- gpu.setForeground(text_col)
- end
- function buttonPress()
- if x~=nil and y ~= nil then
- if x >= 14 and x <= 17 and y == 17 then
- if auto == false then
- reactor.setAllControlRodLevels(0)
- stat = true
- end
- elseif x >= 24 and x <= 30 and y == 17 then
- if auto == false then
- reactor.setAllControlRodLevels(100)
- stat=false
- end
- elseif x >= 34 and x <= 36 and y == 17 then
- if auto == false then
- auto = true
- else
- auto = false
- end
- end
- end
- end
- function autoMode()
- if auto == true then
- if reactor.getEnergyStored() >= (reactor.getEnergyCapacity() / 100)*tonumber(targetP) then
- reactor.setAllControlRodLevels(100)
- stat = false
- numm = 100
- elseif reactor.getEnergyStored() <= (reactor.getEnergyCapacity() / 100)*tonumber(targetP) then
- startinit()
- reactor.setAllControlRodLevels(numm)
- stat = true
- end
- end
- end
- function startinit()
- os.sleep(.3)
- numm = numm - 5
- end
- ------------------------
- -- Main Loop --
- gpu.setBackground(Default_bg)
- term.clear()
- while true do
- GUI()
- display()
- autoMode()
- _,_,x,y = event.pull(1, "touch")
- buttonPress()
- if keyboard.isKeyDown(keyboard.keys.w) and keyboard.isControlDown() then
- term.clear()
- w,h = gpu.maxResolution()
- gpu.setResolution(w,h)
- os.exit()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement