Advertisement
Crysys

BigReactor-Monitor

May 26th, 2015
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.91 KB | None | 0 0
  1. while true do --Start while loop
  2.  
  3.   term.clear()
  4.   term.setCursorPos(1,1)
  5.   term.setTextColor(colors.red)
  6.   print("TERMINAL LOCKED")
  7.   term.setCursorPos(1,3)
  8.   term.setTextColor(colors.white)
  9.   print("Output redirected to monitor...")
  10.  
  11. --[[ Variables for Handlers ]]--
  12.  
  13.   local pList = peripheral.getNames()
  14.   local i, name
  15.  
  16. --[[ Functions for peripherals ]]--
  17.  
  18.   --Get the name of the Reactor
  19.  
  20.   function getReactorHandle()
  21.     for i, name in pairs(pList) do
  22.       if peripheral.getType(name) == "BigReactors-Reactor" then
  23.         return peripheral.wrap(name)
  24.       end --End if for getType
  25.     end --End for, for pList
  26.   end --End function for getReactorHandle
  27.  
  28.   --Get the name of the monitor
  29.  
  30.   function getMonitorHandle()
  31.     for i, name in pairs(pList) do
  32.       if peripheral.getType(name) == "monitor" then
  33.         return peripheral.wrap(name)
  34.       end --End if for getType
  35.     end --End for, for pList
  36.   end --End function for getMonitorHandle
  37.  
  38. --[[ Variables for Peripherals ]]--
  39.  
  40.   local reactor = getReactorHandle() --Reactor name
  41.   local mon = getMonitorHandle() --Monitor name
  42.  
  43. --[[ Variables for API calls ]]--
  44.  
  45.   local rStatus = reactor.getActive()
  46.   local rStored = reactor.getEnergyStored()
  47.   local rIBMax = 10000000 --Internal power buffer size is static
  48.   local rStoredMath = math.floor(rStored / rIBMax * 100)
  49.   local rPerTick = math.floor(reactor.getEnergyProducedLastTick())
  50.   local rFuel = reactor.getFuelAmount()
  51.   local rFuelMax = reactor.getFuelAmountMax()
  52.   local rFuelMath = math.floor(rFuel / rFuelMax * 100)
  53.   local rWaste = reactor.getWasteAmount()
  54.   local rCRLevel = reactor.getControlRodLevel(0)
  55.  
  56. --[[ Function to add commas to numbers ]]--
  57.  
  58.   function commas (num)
  59.     assert (type (num) == "number" or
  60.     type (num) == "string")
  61.    
  62.     local result = ""
  63.  
  64.     --[[
  65.       Split numbers intro 3 parts e.g -1234.545e22
  66.       Sign = +/-
  67.       Before = 1234
  68.       After = .545e22
  69.     --]]
  70.  
  71.     local sign, before, after =
  72.       string.match (tostring (num), "^([%+%-]?)(%d*)(%.?.*)$")
  73.  
  74.     --Pull numbers from the end in groups of 3, adding a comma before each group
  75.  
  76.     while string.len (before) > 3 do
  77.       result = "," .. string.sub (before, -3, -1) .. result
  78.       before = string.sub (before, 1, -4) --Remove the last 3 digits
  79.     end --End while loop for Commas function
  80.  
  81.     --[[
  82.         Gives us the original sign
  83.         any leftover digits (numbers not able to be put in groups of 3)
  84.         commas
  85.         anything after the decimal (if applicable)
  86.     --]]
  87.  
  88.     return sign .. before .. result .. after
  89.   end --End function for Commas
  90.  
  91.   mon.clear() --Clear the monitor
  92.  
  93.   mon.setCursorPos(12,1)
  94.   mon.write("REACTOR")
  95.  
  96. --[[ Status ]]--
  97.  
  98.   mon.setCursorPos(1,3)
  99.   mon.setTextColor(colors.white)
  100.   mon.write("Status: ")
  101.  
  102.   --Check if the reactor is on or off
  103.  
  104.   if rStatus == true then
  105.     mon.setTextColor(colors.lime)
  106.     mon.write("Online")
  107.   elseif rStatus == false then
  108.     mon.setTextColor(colors.red)
  109.     mon.write("Offline")
  110.   end --End if for Status
  111.  
  112. --[[ RF/T ]]--
  113.  
  114.   mon.setCursorPos(1,4)
  115.   mon.setTextColor(colors.white)
  116.   mon.write("RF/T: ")
  117.  
  118.   --Check if the reactor is producing RF  
  119.    
  120.   if rPerTick > 0 then
  121.     mon.setTextColor(colors.lime)
  122.     mon.write(commas(tostring(rPerTick)))
  123.   elseif rPerTick == 0 then
  124.     mon.setTextColor(colors.red)
  125.     mon.write(commas(tostring(rPerTick)))
  126.   end --End if for RF/T
  127.  
  128. --[[ RF Stored ]]--
  129.  
  130.   mon.setCursorPos(1,5)
  131.   mon.setTextColor(colors.white)
  132.   mon.write("RF Stored: ")
  133.  
  134.   --Check the amount of RF in the reactor  
  135.    
  136.   if rStoredMath >= 75 and rStoredMath <= 100 then
  137.     mon.setTextColor(colors.lime)
  138.     mon.write(commas(rStored))
  139.   elseif rStoredMath >= 50 and rStoredMath <= 74 then
  140.     mon.setTextColor(colors.yellow)
  141.     mon.write(commas(rStored))
  142.   elseif rStoredMath >= 25 and rStoredMath <= 49 then
  143.     mon.setTextColor(colors.orange)
  144.     mon.write(commas(rStored))
  145.   elseif rStoredMath >= 0 and rStoredMath <= 24 then
  146.     mon.setTextColor(colors.red)
  147.     mon.write(commas(rStored))
  148.   end  --End if for RF Stored
  149.  
  150. --[[ RF % Filled ]]--
  151.  
  152.   mon.setCursorPos(1,6)
  153.   mon.setTextColor(colors.white)
  154.   mon.write("Fill: ","")
  155.  
  156.   --Check the fill % of the Reactor Battery
  157.  
  158.   if rStoredMath >= 75 and rStoredMath <= 100 then
  159.     mon.setTextColor(colors.lime)
  160.     mon.write(tostring((rStoredMath)))
  161.   elseif rStoredMath >= 50 and rStoredMath <= 74 then
  162.     mon.setTextColor(colors.yellow)
  163.     mon.write(tostring((rStoredMath)))
  164.   elseif rStoredMath >= 49 and rStoredMath <= 25 then
  165.     mon.setTextColor(colors.orange)
  166.     mon.write(tostring((rStoredMath)))
  167.   elseif rStoredMath >= 0 and rStoredMath <= 24 then
  168.     mon.setTextColor(colors.red)
  169.     mon.write(tostring((rStoredMath)))
  170.   end --End if for RF % Filled
  171.  
  172.   mon.setTextColor(colors.white)
  173.   mon.write("%")
  174.  
  175. --[[ Fuel ]]--
  176.  
  177.   mon.setCursorPos(1,7)
  178.   mon.setTextColor(colors.white)
  179.   mon.write("Fuel: ", "")
  180.  
  181.   --Check the fuel level in the reactor
  182.  
  183.   if rFuelMath >= 75 and rFuelMath <= 100 then
  184.     mon.setTextColor(colors.lime)
  185.     mon.write(commas(rFuel))
  186.   elseif rFuelMath >= 50 and rFuelMath <= 74 then
  187.     mon.setTextColor(colors.yellow)
  188.     mon.write(commas(rFuel))
  189.   elseif rFuelMath >= 25 and rFuelMath <= 49 then
  190.     mon.setTextColor(colors.orange)
  191.     mon.write(commas(rFuel))
  192.   elseif rFuelMath >= 0 and rFuelMath <= 24 then
  193.     mon.setTextColor(colors.red)
  194.     mon.write(commas(rFuel))
  195.   end --End if for Fuel Amount
  196.  
  197.   mon.setTextColor(colors.white)
  198.   mon.write("mB")
  199.  
  200. --[[ Waste ]]--
  201.  
  202.   mon.setCursorPos(1,8)
  203.   mon.setTextColor(colors.white)
  204.   mon.write("Waste: ")
  205.   mon.write(commas(rWaste))
  206.   mon.write("mB")
  207.  
  208. --[[ Fuel Rod Level ]]--
  209.  
  210.   mon.setCursorPos(1,9)
  211.   mon.setTextColor(colors.white)
  212.   mon.write("Rod Level: ")
  213.   mon.write(tostring(rCRLevel))
  214.            
  215.   sleep(1) --Wait timer, 1 second
  216.  
  217. end --End while loop for program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement