Advertisement
Guest User

test

a guest
Apr 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.07 KB | None | 0 0
  1. --[[ NOTE
  2. // With automode on the code will try to keep
  3. // around 10% RF in its internal storage, it does this by regulating the control rod
  4. // after the demand OF rf, moving up slowly.
  5. --]]
  6.  
  7.  
  8. -- Wrapping and requireing essentials API's and components --
  9. component = require("component")
  10. reactor = component.br_reactor
  11. event = require("event")
  12. term = require("term")
  13. gpu = component.gpu
  14. event = require("event")
  15. keyboard = require("keyboard")
  16.  
  17. ------------------
  18.  
  19. -- Color table --
  20. colors = { black = 0x000000, white = 0xf8f8ff, blue = 0x0000ff, lightGray = 0xd9d9d9, red = 0xff0000,
  21. purple = 0x9b30ff, carrot = 0xffa500, magenta = 0xcd00cd, lightBlue = 0x87cefa, yellow = 0xffff00,
  22. lime = 0x32cd32, pink = 0xffc0cb, gray = 0x696969, brown = 0x8b4500, green = 0x006400, cyan = 0x008b8b,
  23. olive = 0x6b8e23, gold = 0x8b6914, orangered = 0xdb4e02, diamond = 0x0fa7c7,crimson = 0xaf002a,fuchsia = 0xfd3f92,
  24. folly = 0xff004f, frenchBlue = 0x0072bb, lilac = 0x86608e, flax = 0xeedc82, darkGray = 0x563c5c,
  25. englishGreen = 0x1b4d3e, eggplant = 0x614051, deepPink  = 0xff1493, ruby = 0x843f5b, orange = 0xf5c71a,
  26. lemon = 0xffd300, darkBlue = 0x002e63, bitterLime = 0xbfff00 }
  27. -------------------------
  28.  
  29. -- Settings for screen --
  30. gpu.setBackground(colors.black)
  31. gpu.setForeground(colors.orange)
  32. gpu.setResolution(50,10)
  33. term.clear()
  34. -------------------------
  35. --Vars --
  36. auto = false
  37. numm = 100
  38. --
  39. -- Functions --
  40.   function display()
  41.   if auto == false then  
  42.     if stat == true  then
  43.       gpu.set(19,2, "ON             ")
  44.     else
  45.       gpu.set(19,2, "OFF            ")
  46.     end
  47.   elseif auto == true then
  48.       gpu.set(19,2, "----         ")
  49.   end
  50.     gpu.set(1,1, "Reactor Info....: ")
  51.     gpu.set(1,2, "Reactor status..: ")
  52.     gpu.set(1,3, "RF Production...: ".. string.format("%.2f", reactor.getEnergyProducedLastTick()).." RF/T          ")
  53.     gpu.set(1,4, "RF Internal.....: ".. reactor.getEnergyStored() .."/"..reactor.getEnergyCapacity().."(".. math.floor((reactor.getEnergyStored()/reactor.getEnergyCapacity()*100)) .."%) RF          ")
  54.     gpu.set(1,5, "Fuel use........: ".. string.format("%.2f", reactor.getFuelConsumedLastTick()) .."mB")
  55.     gpu.setBackground(colors.white)
  56.     gpu.setForeground(colors.black)
  57.     gpu.set(2,6, " ON ")
  58.     --gpu.setBackground(colors.blue)
  59.     gpu.set(6,6, " OFF ")
  60.     --gpu.setBackground(colors.)
  61.     gpu.set(11,6, " Auto ")
  62.     gpu.setBackground(colors.black)
  63.     gpu.set(17,6,"      ")
  64.     gpu.setBackground(colors.black)
  65.     gpu.setForeground(colors.orange)
  66.   end
  67.  
  68. function buttonPress()
  69.   if x~=nil and y ~= nil then
  70.     if x >= 1 and x <= 4 and y == 6 then
  71.       if auto == false then
  72.         gpu.setBackground(colors.black)
  73.         gpu.set(2,6," ON ")
  74.         reactor.setAllControlRodLevels(0)
  75.         stat = true
  76.       end
  77.     elseif x >= 5 and x <= 9 and y == 6 then
  78.       if auto == false then
  79.       gpu.setBackground(colors.black)
  80.       gpu.set(5,6,"  OFF ")
  81.       reactor.setAllControlRodLevels(100)
  82.       stat=false
  83.       end
  84.     elseif x >= 11 and x <= 17 and y == 6 then
  85.       if auto == false then
  86.           auto = true
  87.       else
  88.           auto = false
  89.       end
  90.     end
  91.   end
  92. end
  93.  
  94. function autoMode()
  95.   if auto == true then
  96.    gpu.set(1,6, "         ")
  97.    gpu.set(9,6, "AUTO MODE ON")
  98.     if reactor.getEnergyStored() >= (reactor.getEnergyCapacity() / 100 * 10) then
  99.       reactor.setAllControlRodLevels(100)
  100.       stat = false
  101.       numm = 100
  102.     elseif reactor.getEnergyStored() <= (reactor.getEnergyCapacity()/100 * 10) then
  103.       startinit()
  104.       reactor.setAllControlRodLevels(numm)
  105.       stat = true
  106.     elseif reactor.getEnergyStored() <= (reactor.getEnergyCapacity()/100 * 2) then
  107.       reactor.setAllControlRodLevels(0)
  108.       stat = true
  109.     end
  110.  end
  111. end  
  112.  
  113. function startinit()
  114.   os.sleep(.3)
  115.   numm  = numm - 1
  116. end
  117. ------------------------
  118.  
  119. -- Main Loop --
  120. term.clear()
  121. while true do
  122.   display()
  123.   autoMode()
  124.   gpu.set(1,15, tostring(auto))
  125.   _,_,x,y = event.pull(1, "touch")    
  126.     buttonPress()
  127.     if keyboard.isKeyDown(keyboard.keys.w) and keyboard.isControlDown() then
  128.       term.clear()
  129.       w,h = gpu.maxResolution()
  130.       gpu.setResolution(w,h)
  131.       os.exit()
  132.     end
  133.   os.sleep(0.5)
  134. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement