TomTheBeast95

Untitled

Sep 23rd, 2015
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.93 KB | None | 0 0
  1. while true do
  2.  
  3. function comma_value (num)
  4.   assert (type (num) == "number" or
  5.                   type (num) == "string")
  6.  
  7.   local result = ""
  8.                  -- split number into 3 parts, eg. -1234.545e22
  9.                  -- sign = + or -
  10.                  -- before = 1234
  11.                  -- after = .545e22
  12.   local sign, before, after =
  13.          string.match (tostring (num), "^([%+%-]?)(%d*)(%.?.*)$")
  14.                  -- pull out batches of 3 digits from the end, put a comma before them
  15.            while string.len (before) > 3 do
  16.                   result = "," .. string.sub (before, -3, -1) .. result
  17.                   before = string.sub (before, 1, -4)  -- remove last 3 digits
  18.            end -- while
  19.                   -- we want the original sign, any left-over digits, the comma part,
  20.                   -- and the stuff after the decimal point, if any
  21.                  return sign .. before .. result .. after
  22.            end -- function commas
  23.  
  24.     local reactorCount = 50;
  25.     local reactors = {}
  26.     local energyCore = peripheral.wrap("draconic_storage_1")
  27.     local powerPercent = (energyCore.getEnergyStored() / energyCore.getMaxEnergyStored()) * 100
  28.    
  29.     local totalFuelHeat = 0
  30.     local totalCaseHeat = 0
  31.     local tELT = 0
  32.     local totalFR = 0
  33.    
  34.   for i=1, reactorCount, 1 do
  35.   reactors[i] = peripheral.wrap("BigReactors-Reactor_" .. (i - 1))
  36.   end
  37.  
  38.     local reactorsOnline = 0
  39.    
  40.     for i, reactor in ipairs(reactors) do
  41.         if (reactor.getActive()) then  
  42.         reactorsOnline = reactorsOnline + 1
  43.         end
  44.         totalFuelHeat = totalFuelHeat + reactor.getFuelTemperature()
  45.         totalCaseHeat = totalCaseHeat + reactor.getCasingTemperature()
  46.         tELT = tELT + reactor.getEnergyProducedLastTick()
  47.         totalFR = totalFR + reactor.getFuelReactivity()
  48.         if (powerPercent < 90) then
  49.             reactor.setActive(true)
  50.         else
  51.             reactor.setActive(false)
  52.         end
  53.     end
  54.  
  55.   local m = peripheral.wrap("monitor_5")
  56.   local avgFuelHeat = (totalFuelHeat / reactorsOnline)
  57.   local avgCaseHeat = (totalCaseHeat / reactorsOnline)
  58.   local elt = tELT
  59.   local avgFR = (totalFR / reactorsOnline)
  60.  
  61.   m.clear()
  62.   m.setTextScale(2)
  63.  
  64.   --Online Status
  65.   m.setCursorPos(1,1)  
  66.   m.setTextColor(colors.white)
  67.   m.write("Online: ")
  68.   if (reactorsOnline < 1) then
  69.   m.setTextColor(colors.red)
  70.   else
  71.   m.setTextColor(colors.lime)
  72.   end
  73.   m.write(comma_value(reactorsOnline))
  74.  
  75.     --Energy/t
  76.   m.setCursorPos(1,2)
  77.   m.setTextColor(colors.white)
  78.   m.write("Energy Produced last Tick: ")
  79.   if (elt < 5000) then
  80.   m.setTextColor(colors.red)
  81.   else
  82.   m.setTextColor(colors.lime)
  83.   end
  84.   m.write(comma_value(math.floor(elt)) .. " RF/t")
  85.  
  86.   --Average Fuel Temp
  87.   m.setCursorPos(1,3)
  88.   m.setTextColor(colors.white)
  89.   m.write("Average Fuel Temp: ")
  90.   if (avgFuelHeat > 2000) then
  91.   m.setTextColor(colors.red)
  92.   else
  93.   m.setTextColor(colors.lime)
  94.   end
  95.   m.write(comma_value(math.floor(avgFuelHeat)) .. " C")
  96.  
  97.   --Average Casing Temp
  98.   m.setCursorPos(1,4)
  99.   m.setTextColor(colors.white)
  100.   m.write("Average Casing Temp: ")
  101.   if (avgCaseHeat > 2000) then
  102.   m.setTextColor(colors.red)
  103.   else
  104.   m.setTextColor(colors.lime)
  105.   end
  106.   m.write(comma_value(math.floor(avgCaseHeat)) .. " C")
  107.  
  108.   --fuelReactity
  109.   m.setCursorPos(1,5)
  110.   m.setTextColor(colors.white)
  111.   m.write("Average Fuel Reactivity: ")
  112.   if (avgFR < 250) then
  113.   m.setTextColor(colors.red)
  114.   else
  115.   m.setTextColor(colors.lime)
  116.   end
  117.   m.write(comma_value(math.floor(avgFR)) .. "%")
  118.  
  119.   --power percent
  120.   m.setCursorPos(1,7)
  121.   m.setTextColor(colors.white)
  122.   m.write("Current Energy: ")
  123.   if (powerPercent < 25) then
  124.   m.setTextColor(colors.red)
  125.   elseif (powerPercent >= 25 and powerPercent < 50) then
  126.   m.setTextColor(colors.orange)
  127.   elseif (powerPercent >= 50 and powerPercent < 75) then
  128.   m.setTextColor(colors.yellow)
  129.   else
  130.   m.setTextColor(colors.lime)
  131.   end
  132.   m.write(comma_value(math.floor(energyCore.getEnergyStored())).." RF, "..math.floor(powerPercent).."%")
  133.  
  134.  
  135.   sleep(1)
  136. end
Advertisement
Add Comment
Please, Sign In to add comment