Advertisement
BlackStar7713

TestNetherStarGen

Aug 30th, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.12 KB | None | 0 0
  1.  
  2. local modemside = "top"
  3.  
  4. local rednetside = "right"
  5.  
  6. local monitorside = "monitor_3"
  7.  
  8. local textsize = 1
  9.  
  10.  
  11. local storageUnits = {
  12.         {
  13.                  ["id"] = "cofh_thermalexpansion_energycell_26",
  14.                  ["name"] = "Cell1"
  15.         },
  16.           {
  17.                  ["id"] = "cofh_thermalexpansion_energycell_27",
  18.                  ["name"] = "Cell2"
  19.         },
  20.           {
  21.                  ["id"] = "cofh_thermalexpansion_energycell_28",
  22.                  ["name"] = "Cell3"
  23.         },
  24.           {
  25.                  ["id"] = "cofh_thermalexpansion_energycell_29",
  26.                  ["name"] = "Cell4"
  27.         },
  28.           {
  29.                  ["id"] = "cofh_thermalexpansion_energycell_30",
  30.                  ["name"] = "Cell5"
  31.         },
  32.           {
  33.                  ["id"] = "cofh_thermalexpansion_energycell_31",
  34.                  ["name"] = "Cell6"
  35.         },
  36.           {
  37.                  ["id"] = "cofh_thermalexpansion_energycell_32",
  38.                  ["name"] = "Cell7"
  39.         },
  40.           {
  41.                  ["id"] = "cofh_thermalexpansion_energycell_33",
  42.                  ["name"] = "Cell8"
  43.         },
  44.           {
  45.                  ["id"] = "cofh_thermalexpansion_energycell_34",
  46.                  ["name"] = "Cell9"
  47.         },
  48.           {
  49.                  ["id"] = "cofh_thermalexpansion_energycell_35",
  50.                  ["name"] = "Cell10"
  51.         },
  52.           {
  53.                  ["id"] = "cofh_thermalexpansion_energycell_36",
  54.                  ["name"] = "Cell11"
  55.         },
  56.           {
  57.                  ["id"] = "cofh_thermalexpansion_energycell_37",
  58.                  ["name"] = "Cell12"
  59.         }
  60.  
  61. }
  62.  
  63. local mon = peripheral.wrap(monitorside)
  64. local net = peripheral.wrap(modemside)
  65.  
  66.  
  67. mon.clear()  
  68. mon.setTextScale(textsize)
  69. mon.setTextColor(512)
  70. mon.setCursorPos(1,2)
  71. mon.write(" Energy Remaining:")
  72. mon.setCursorPos(1,10)
  73. mon.write("  Engine Status:")
  74. mon.setTextColor(2)
  75. rs.setBundledOutput(rednetside,0)
  76.  
  77. function comma_value(number)
  78.   local formatted = number
  79.   while true do  
  80.     formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
  81.     if (k==0) then
  82.       break
  83.     end
  84.   end
  85.   return formatted
  86. end
  87.  
  88. while true do
  89.  
  90.     capacity = 0
  91.     amount = 0
  92.        
  93.     local funcs={}
  94.     for i=#storageUnits,1,-1 do
  95.         funcs[i]=function()
  96.                 storageUnit = storageUnits[i]
  97.                 capacity = capacity + net.callRemote(storageUnit["id"], "getMaxEnergyStored", "unknown")
  98.                 amount = amount + net.callRemote(storageUnit["id"], "getEnergyStored", "unknown")
  99.         end
  100.     end
  101.     parallel.waitForAll(unpack(funcs))
  102.  
  103.     percentage = tonumber((amount / capacity) *100)
  104.     percentage = math.floor(percentage)
  105.        
  106.     if percentage<=75 then
  107.         mon.setTextColor(colors.red)
  108.         rs.setBundledOutput(rednetside, colors.red+colors.orange)
  109.         local remainingTime = 120
  110.             while remainingTime > 0 do
  111.                 local startTime = os.clock()
  112.                        
  113.                 mon.setCursorPos(3,11)
  114.                 mon.clearLine()
  115.                        
  116.                 local minute, second = tostring(math.floor(remainingTime/60)), tostring(math.floor(remainingTime%60))
  117.                 mon.write("ONLINE:  " ..minute.." : "..(#second==1 and "0" or "")..second.." remaining")
  118.        
  119.                 capacity = 0
  120.                 amount = 0
  121.        
  122.                 local funcs={}
  123.                 for i=#storageUnits,1,-1 do
  124.                     funcs[i]=function()
  125.                         storageUnit = storageUnits[i]
  126.                         capacity = capacity + net.callRemote(storageUnit["id"], "getMaxEnergyStored", "unknown")
  127.                         amount = amount + net.callRemote(storageUnit["id"], "getEnergyStored", "unknown")
  128.                     end
  129.                 end
  130.                 parallel.waitForAll(unpack(funcs))
  131.        
  132.                 percentage = string.match(tostring(percentage),'[^%.]+')
  133.                 mon.setCursorPos(8,4)
  134.                 mon.clearLine()
  135.                 mon.setTextColor(2)
  136.                 mon.write(percentage .. "%")
  137.                 mon.setCursorPos(1,6)
  138.                 mon.clearLine()
  139.                 mon.setTextColor(512)
  140.                 mon.write("  Energy: ")
  141.                 mon.setTextColor(2)
  142.                 mon.write(comma_value(amount) .. " RF")
  143.                 mon.setCursorPos(1,7)
  144.                 mon.clearLine()
  145.                 mon.setTextColor(512)
  146.                 mon.write("Capacity: ")
  147.                 mon.setTextColor(2)
  148.                 mon.write(comma_value(capacity) .." RF")
  149.        
  150.                 capacity = 0
  151.                 amount = 0
  152.        
  153.                 local funcs={}
  154.                 for i=#storageUnits,1,-1 do
  155.                     funcs[i]=function()
  156.                         storageUnit = storageUnits[i]
  157.                         capacity = capacity + net.callRemote(storageUnit["id"], "getMaxEnergyStored", "unknown")
  158.                         amount = amount + net.callRemote(storageUnit["id"], "getEnergyStored", "unknown")
  159.                     end
  160.                 end
  161.                 parallel.waitForAll(unpack(funcs))
  162.    
  163.                 percentage = tonumber((amount / capacity) *100)
  164.                 percentage = math.floor(percentage)
  165.        
  166.                 percentage = string.match(tostring(percentage),'[^%.]+')
  167.                 mon.setCursorPos(8,4)
  168.                 mon.clearLine()
  169.                 mon.setTextColor(2)
  170.                 mon.write(percentage .. "%")
  171.                 mon.setCursorPos(1,6)
  172.                 mon.clearLine()
  173.                 mon.setTextColor(512)
  174.                 mon.write("  Energy: ")
  175.                 mon.setTextColor(2)
  176.                 mon.write(comma_value(amount) .. " RF")
  177.                 mon.setCursorPos(1,7)
  178.                 mon.clearLine()
  179.                 mon.setTextColor(512)
  180.                 mon.write("Capacity: ")
  181.                 mon.setTextColor(2)
  182.                 mon.write(comma_value(capacity) .." RF")
  183.                
  184.             if(remainingTime==120) then rs.setBundledOutput(rednetside, colors.red) end
  185.             remainingTime = remainingTime - os.clock() + startTime
  186.             end
  187.         rs.setBundledOutput(rednetside,0)
  188.         mon.setTextColor(colors.lime)
  189.         mon.setCursorPos(5,11)
  190.         mon.clearLine()
  191.         mon.write("OFFLINE")
  192.     end
  193.        
  194.     percentage = string.match(tostring(percentage),'[^%.]+')
  195.     mon.setCursorPos(8,4)
  196.     mon.clearLine()
  197.     mon.setTextColor(2)
  198.     mon.write(percentage .. "%")
  199.     mon.setCursorPos(1,6)
  200.     mon.clearLine()
  201.     mon.setTextColor(512)
  202.     mon.write("  Energy: ")
  203.     mon.setTextColor(2)
  204.     mon.write(comma_value(amount) .." RF")
  205.     mon.setCursorPos(1,7)
  206.     mon.clearLine()
  207.     mon.setTextColor(512)
  208.     mon.write("Capacity: ")
  209.     mon.setTextColor(2)
  210.     mon.write(comma_value(capacity) .." RF")
  211.     mon.setCursorPos(5,11)
  212.     mon.setTextColor(colors.lime)
  213.     mon.clearLine()
  214.     mon.write("OFFLINE")
  215. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement