daily pastebin goal
31%
SHARE
TWEET

startup

a guest Jul 12th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. rednet.open("top")
  2. rednet.host("ECC","ECM2")
  3. local monitor = peripheral.wrap("left")
  4. monitor.setTextScale(0.5)
  5. local deltax = 0
  6. local deltaxo = 0
  7. local allCurEnergy = 0
  8. local allMaxEnergy = 0
  9.  
  10. function newline()
  11.  
  12.   local posX, pos = monitor.getCursorPos()
  13.   monitor.setCursorPos(1,pos + 1)
  14.  
  15. end
  16.  
  17. function realMaxEnergy(...)
  18.  
  19.   local args = ...
  20.  
  21.   if args == "Elite Energy Cube" then
  22.  
  23.     return 12800000
  24.    
  25.   elseif args == "Advanced Energy Cube" then
  26.  
  27.  
  28.     return 3200000
  29.    
  30.   elseif args == "Ultimate Energy Cube" then
  31.  
  32.     return 52000000
  33.   elseif args == "TE Energy Cell"   then
  34.  
  35.  
  36.     return
  37.  
  38.   else
  39.  
  40.     return 10
  41.    
  42.   end
  43.  
  44.  
  45. end
  46.  
  47.  
  48. function headline()
  49.  
  50.     term.clear()
  51.     term.setCursorPos(1,1)
  52.     monitor.clear()
  53.     monitor.setCursorPos(1,1)
  54.    
  55.   print[[    
  56.    
  57.     Energy Control Monitor    
  58.  
  59.   ]]
  60.  
  61.   monitor.setTextColor(colors.red)  
  62.  
  63.   monitor.write("==========================")
  64.   newline()
  65.   monitor.write("= Energy Control Monitor =")
  66.   newline()
  67.   monitor.write("==========================")
  68.   newline()
  69.  
  70.  
  71. end
  72.  
  73. function printCubeType(...)
  74.    
  75.     local EC_data = ...
  76.  
  77.     for i = 1, #EC_data,1 do
  78.  
  79.         local curEnergy = EC_data[i][1]
  80.         local maxEnergy = EC_data[i][2]
  81.      if maxEnergy and curEnergy then
  82.         local name = EC_data[i][3]
  83.         local percentage = (curEnergy / maxEnergy) * 100
  84.    
  85.      if not  EC_data[3] == "TE Energy Cell" then
  86.          
  87.          maxEnergy = realMaxEnergy(name)
  88.    
  89.      end
  90.         curEnergy = (percentage / 100) * maxEnergy
  91.    
  92.         percentage = math.ceil(percentage)
  93.         print(name..": "..tostring(percentage).."% " ..tostring(maxEnergy / 1000000).." MRF / "..tostring(curEnergy / 1000000).." MRF")
  94.         print(" ")
  95.  
  96.         monitor.setTextColor(colors.white)  
  97.         monitor.write(name..": "..tostring(percentage).."% "..tostring(maxEnergy/1000000).." MRF "..tostring(curEnergy/1000000).." MRF")
  98.    
  99.         newline()
  100.        
  101.    
  102.         allCurEnergy = allCurEnergy + curEnergy
  103.         allMaxEnergy = allMaxEnergy + maxEnergy
  104.     end
  105.         end
  106. end
  107.  
  108. while true do
  109.  
  110.   rednet.broadcast("request_EC_data","ECC")
  111.  
  112.   local time = os.clock() + 1
  113.  
  114.   local advCubes = {}
  115.   local elCubes = {}
  116.   local ultCubes = {}
  117.   local unknownCubes = {}
  118.  
  119.   while time > os.clock() do
  120.    
  121.     local SID, MES, PROT = rednet.receive("ECC",1)
  122.  
  123.    if MES then    
  124.  
  125.     if MES[3] == "Advanced Energy Cube"  then
  126.      
  127.         table.insert(advCubes,(#advCubes + 1),MES)
  128.      
  129.     elseif MES[3] == "Elite Energy Cube" then
  130.      
  131.          table.insert(elCubes,(#elCubes + 1),MES)
  132.  
  133.     elseif MES[3] == "Ultimate Energy Cube" then
  134.      
  135.         table.insert(ultCubes,(#ultCubes + 1),MES)
  136.    
  137.     else
  138.      
  139.         table.insert(unknownCubes,(#ultCubes + 1),MES)        
  140.      
  141.     end
  142.    
  143.   end
  144.   end  
  145.   headline()
  146.  
  147.   printCubeType(advCubes)
  148.   printCubeType(elCubes)
  149.   printCubeType(ultCubes)
  150.   printCubeType(unknownCubes)
  151.  
  152.  
  153.  
  154.  
  155.  
  156.   local postFix = " RF"
  157.   local ACEA = allCurEnergy
  158.   if allCurEnergy > 1000000000000 then
  159.  
  160.      allCurEnergy = allCurEnergy / 1000000000000
  161.      postFix = " TerraRF"
  162.      
  163.   elseif allCurEnergy > 1000000000 then
  164.  
  165.     allCurEnergy = allCurEnergy / 1000000000
  166.     postFix = " GigaRF"
  167.    
  168.   elseif allCurEnergy / 1000000 then
  169.  
  170.     allCurEnergy = allCurEnergy / 1000000
  171.     postFix = " MegaRF"
  172.    
  173.   elseif allCurEnergy > 1000 then
  174.    
  175.     allCurEnergy = allCurEnergy / 1000
  176.    
  177.     postFix = " KiloRF"
  178.    
  179.   end
  180.  
  181.   postFix2 = " RF"
  182.   AMEA = allMaxEnergy
  183.  
  184.   if allMaxEnergy < 10000000 then
  185.  
  186.     allMaxEnergy = allMaxEnergy / 1000000
  187.    
  188.     postFix2 = " MegaRF"  
  189.  
  190.   elseif allMaxEnergy < 1000 then
  191.  
  192.     allMaxEnergy = allMaxEnergy / 1000
  193.     postFix2 = " KiloRF"
  194.    
  195.   elseif allMaxEnergy > 1000000000 then
  196.    
  197.     allMaxEnergy = allMaxEnergy / 1000000000
  198.     postFix2 = " GigaRF"  
  199.   end
  200.  
  201.   monitor.setTextColor(colors.red)
  202.   newline()  
  203.   local x =  string.sub(tostring(allCurEnergy),1,5)
  204.   print("Current overall Energy Amount:")
  205.   print(x..postFix.."  ~  "..((ACEA - deltaxo)/1000).." KiloRF".."/sec")
  206.  
  207.   monitor.write("Current overall Energy Amount:")
  208.   newline()
  209. --  monitor.write(x..postFix)
  210.   monitor.write(x..postFix.."  ~  "..((ACEA - deltaxo)/1000).." KiloRF".."/sec")
  211.   newline()
  212.  
  213.   newline()
  214.  
  215.   local EA = ACEA - deltaxo
  216.   if EA < 0 then
  217.    
  218.    local secs = ACEA  / EA
  219.      
  220.     monitor.write("Approximately depleted in "..(secs * -1).. " Seconds!")  
  221.    
  222.   elseif EA == 0 then
  223.  
  224.     monitor.write("Energylevel stable!")
  225.    
  226.   else
  227.    
  228.     local diff = ACEA - AMEA
  229.     local secs = diff / EA
  230.    
  231.       monitor.write("Approximately full in "..secs.." Seconds!")  
  232.    
  233.   end
  234.  
  235.   deltax = tonumber(x)
  236.   deltaxo = tonumber(ACEA)
  237.  
  238.   newline()
  239.   x = string.sub(tostring(allMaxEnergy),1,5)  
  240.   monitor.write("Maximum overall Capacity:")
  241.   newline()
  242.   monitor.write(x..postFix2)
  243.   newline()
  244.  
  245.  
  246. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top