Crysys icon

BigReactor-Monitor

Crysys | PRO | 05/26/15 05:41:14 AM UTC | 0 ⭐ | 544 👁️ | Never ⏰ | []
Lua |

5.91 KB

|

None

|

0 👍

/

0 👎

while true do --Start while loop
 
  term.clear()
  term.setCursorPos(1,1)
  term.setTextColor(colors.red)
  print("TERMINAL LOCKED")
  term.setCursorPos(1,3)
  term.setTextColor(colors.white)
  print("Output redirected to monitor...")
 
--[[ Variables for Handlers ]]--
 
  local pList = peripheral.getNames()
  local i, name
 
--[[ Functions for peripherals ]]--
 
  --Get the name of the Reactor
 
  function getReactorHandle()
    for i, name in pairs(pList) do
      if peripheral.getType(name) == "BigReactors-Reactor" then
        return peripheral.wrap(name)
      end --End if for getType
    end --End for, for pList
  end --End function for getReactorHandle
 
  --Get the name of the monitor
 
  function getMonitorHandle()
    for i, name in pairs(pList) do
      if peripheral.getType(name) == "monitor" then
        return peripheral.wrap(name)
      end --End if for getType
    end --End for, for pList
  end --End function for getMonitorHandle
 
--[[ Variables for Peripherals ]]--
 
  local reactor = getReactorHandle() --Reactor name
  local mon = getMonitorHandle() --Monitor name
 
--[[ Variables for API calls ]]--
 
  local rStatus = reactor.getActive()
  local rStored = reactor.getEnergyStored()
  local rIBMax = 10000000 --Internal power buffer size is static
  local rStoredMath = math.floor(rStored / rIBMax * 100)
  local rPerTick = math.floor(reactor.getEnergyProducedLastTick())
  local rFuel = reactor.getFuelAmount()
  local rFuelMax = reactor.getFuelAmountMax()
  local rFuelMath = math.floor(rFuel / rFuelMax * 100)
  local rWaste = reactor.getWasteAmount()
  local rCRLevel = reactor.getControlRodLevel(0)
  
--[[ Function to add commas to numbers ]]--
 
  function commas (num)
    assert (type (num) == "number" or
    type (num) == "string")
    
    local result = ""
 
    --[[
      Split numbers intro 3 parts e.g -1234.545e22
      Sign = +/-
      Before = 1234
      After = .545e22
    --]]
 
    local sign, before, after =
      string.match (tostring (num), "^([%+%-]?)(%d*)(%.?.*)$")
 
    --Pull numbers from the end in groups of 3, adding a comma before each group
 
    while string.len (before) > 3 do
      result = "," .. string.sub (before, -3, -1) .. result
      before = string.sub (before, 1, -4) --Remove the last 3 digits
    end --End while loop for Commas function
 
    --[[
        Gives us the original sign
        any leftover digits (numbers not able to be put in groups of 3)
        commas
        anything after the decimal (if applicable)
    --]]
 
    return sign .. before .. result .. after
  end --End function for Commas
 
  mon.clear() --Clear the monitor
  
  mon.setCursorPos(12,1)
  mon.write("REACTOR")
 
--[[ Status ]]--
 
  mon.setCursorPos(1,3)
  mon.setTextColor(colors.white)
  mon.write("Status: ")
 
  --Check if the reactor is on or off
  
  if rStatus == true then
    mon.setTextColor(colors.lime)
    mon.write("Online")
  elseif rStatus == false then
    mon.setTextColor(colors.red)
    mon.write("Offline")
  end --End if for Status
 
--[[ RF/T ]]--
 
  mon.setCursorPos(1,4)
  mon.setTextColor(colors.white)
  mon.write("RF/T: ")
 
  --Check if the reactor is producing RF  
    
  if rPerTick > 0 then
    mon.setTextColor(colors.lime)
    mon.write(commas(tostring(rPerTick)))
  elseif rPerTick == 0 then
    mon.setTextColor(colors.red)
    mon.write(commas(tostring(rPerTick)))
  end --End if for RF/T
 
--[[ RF Stored ]]--
 
  mon.setCursorPos(1,5)
  mon.setTextColor(colors.white)
  mon.write("RF Stored: ")
 
  --Check the amount of RF in the reactor  
    
  if rStoredMath >= 75 and rStoredMath <= 100 then
    mon.setTextColor(colors.lime)
    mon.write(commas(rStored))
  elseif rStoredMath >= 50 and rStoredMath <= 74 then
    mon.setTextColor(colors.yellow)
    mon.write(commas(rStored))
  elseif rStoredMath >= 25 and rStoredMath <= 49 then
    mon.setTextColor(colors.orange)
    mon.write(commas(rStored))
  elseif rStoredMath >= 0 and rStoredMath <= 24 then
    mon.setTextColor(colors.red)
    mon.write(commas(rStored))
  end  --End if for RF Stored
 
--[[ RF % Filled ]]--
 
  mon.setCursorPos(1,6)
  mon.setTextColor(colors.white)
  mon.write("Fill: ","")
 
  --Check the fill % of the Reactor Battery
 
  if rStoredMath >= 75 and rStoredMath <= 100 then
    mon.setTextColor(colors.lime)
    mon.write(tostring((rStoredMath)))
  elseif rStoredMath >= 50 and rStoredMath <= 74 then
    mon.setTextColor(colors.yellow)
    mon.write(tostring((rStoredMath)))
  elseif rStoredMath >= 49 and rStoredMath <= 25 then
    mon.setTextColor(colors.orange)
    mon.write(tostring((rStoredMath)))
  elseif rStoredMath >= 0 and rStoredMath <= 24 then
    mon.setTextColor(colors.red)
    mon.write(tostring((rStoredMath)))
  end --End if for RF % Filled
 
  mon.setTextColor(colors.white)
  mon.write("%")
  
--[[ Fuel ]]--
 
  mon.setCursorPos(1,7)
  mon.setTextColor(colors.white)
  mon.write("Fuel: ", "")
 
  --Check the fuel level in the reactor
 
  if rFuelMath >= 75 and rFuelMath <= 100 then
    mon.setTextColor(colors.lime)
    mon.write(commas(rFuel))
  elseif rFuelMath >= 50 and rFuelMath <= 74 then
    mon.setTextColor(colors.yellow)
    mon.write(commas(rFuel))
  elseif rFuelMath >= 25 and rFuelMath <= 49 then
    mon.setTextColor(colors.orange)
    mon.write(commas(rFuel))
  elseif rFuelMath >= 0 and rFuelMath <= 24 then
    mon.setTextColor(colors.red)
    mon.write(commas(rFuel))
  end --End if for Fuel Amount
 
  mon.setTextColor(colors.white)
  mon.write("mB")
  
--[[ Waste ]]--
 
  mon.setCursorPos(1,8)
  mon.setTextColor(colors.white)
  mon.write("Waste: ")
  mon.write(commas(rWaste))
  mon.write("mB")
 
--[[ Fuel Rod Level ]]--
 
  mon.setCursorPos(1,9)
  mon.setTextColor(colors.white)
  mon.write("Rod Level: ")
  mon.write(tostring(rCRLevel))
            
  sleep(1) --Wait timer, 1 second
 
end --End while loop for program

Comments