Advertisement
TomTheBeast95

Untitled

Sep 23rd, 2015
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.08 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.     local lastReactor = 1;
  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.       if (peripheral.wrap("BigReactors-Reactor_" .. (i - 1)) == nil) then
  36.        
  37.       else
  38.         reactors[lastReactor] = peripheral.wrap("BigReactors-Reactor_" .. (i - 1))
  39.         lastReactor = lastReactor + 1
  40.     end
  41.   end
  42.  
  43.     local reactorsOnline = 0
  44.    
  45.     for i, reactor in ipairs(reactors) do
  46.         if (reactor.getActive()) then  
  47.         reactorsOnline = reactorsOnline + 1
  48.         end
  49.         totalFuelHeat = totalFuelHeat + reactor.getFuelTemperature()
  50.         totalCaseHeat = totalCaseHeat + reactor.getCasingTemperature()
  51.         tELT = tELT + reactor.getEnergyProducedLastTick()
  52.         totalFR = totalFR + reactor.getFuelReactivity()
  53.         if (powerPercent < 90) then
  54.             reactor.setActive(true)
  55.         else
  56.             reactor.setActive(false)
  57.         end
  58.     end
  59.  
  60.   local m = peripheral.wrap("monitor_5")
  61.   local avgFuelHeat = (totalFuelHeat / reactorsOnline)
  62.   local avgCaseHeat = (totalCaseHeat / reactorsOnline)
  63.   local elt = tELT
  64.   local avgFR = (totalFR / reactorsOnline)
  65.  
  66.   m.clear()
  67.   m.setTextScale(2)
  68.  
  69.   --Online Status
  70.   m.setCursorPos(1,1)  
  71.   m.setTextColor(colors.white)
  72.   m.write("Online: ")
  73.   if (reactorsOnline < 1) then
  74.   m.setTextColor(colors.red)
  75.   else
  76.   m.setTextColor(colors.lime)
  77.   end
  78.   m.write(comma_value(reactorsOnline))
  79.  
  80.     --Energy/t
  81.   m.setCursorPos(1,2)
  82.   m.setTextColor(colors.white)
  83.   m.write("Energy Produced last Tick: ")
  84.   if (elt < 5000) then
  85.   m.setTextColor(colors.red)
  86.   else
  87.   m.setTextColor(colors.lime)
  88.   end
  89.   m.write(comma_value(math.floor(elt)) .. " RF/t")
  90.  
  91.   --Average Fuel Temp
  92.   m.setCursorPos(1,3)
  93.   m.setTextColor(colors.white)
  94.   m.write("Average Fuel Temp: ")
  95.   if (avgFuelHeat > 2000) then
  96.   m.setTextColor(colors.red)
  97.   else
  98.   m.setTextColor(colors.lime)
  99.   end
  100.   m.write(comma_value(math.floor(avgFuelHeat)) .. " C")
  101.  
  102.   --Average Casing Temp
  103.   m.setCursorPos(1,4)
  104.   m.setTextColor(colors.white)
  105.   m.write("Average Casing Temp: ")
  106.   if (avgCaseHeat > 2000) then
  107.   m.setTextColor(colors.red)
  108.   else
  109.   m.setTextColor(colors.lime)
  110.   end
  111.   m.write(comma_value(math.floor(avgCaseHeat)) .. " C")
  112.  
  113.   --fuelReactity
  114.   m.setCursorPos(1,5)
  115.   m.setTextColor(colors.white)
  116.   m.write("Average Fuel Reactivity: ")
  117.   if (avgFR < 250) then
  118.   m.setTextColor(colors.red)
  119.   else
  120.   m.setTextColor(colors.lime)
  121.   end
  122.   m.write(comma_value(math.floor(avgFR)) .. "%")
  123.  
  124.   --power percent
  125.   m.setCursorPos(1,7)
  126.   m.setTextColor(colors.white)
  127.   m.write("Current Energy: ")
  128.   if (powerPercent < 25) then
  129.   m.setTextColor(colors.red)
  130.   elseif (powerPercent >= 25 and powerPercent < 50) then
  131.   m.setTextColor(colors.orange)
  132.   elseif (powerPercent >= 50 and powerPercent < 75) then
  133.   m.setTextColor(colors.yellow)
  134.   else
  135.   m.setTextColor(colors.lime)
  136.   end
  137.   m.write(comma_value(math.floor(energyCore.getEnergyStored())).." RF, "..math.floor(powerPercent).."%")
  138.  
  139.  
  140.   sleep(1)
  141. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement