Advertisement
tiaggo11

energy_surveilance

Feb 22nd, 2021
1,181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local component = require("component")
  2. local term = require("term")
  3. local redstone = component.redstone
  4. local screen = component.proxy("ce5b8829-90c2-4022-9c69-8f4d5783c70b")
  5. local gpu = component.proxy("7f0687d2-c629-4270-a8fb-c20d8d12d5b3")
  6. local modem = component.modem
  7. local sides = require("sides")
  8. local thread = require("thread")
  9. gpu.bind(screen.address)
  10. gpu.setResolution(13,3)
  11. gpu.fill(1,1,13,3,' ')
  12.  
  13. local cubes = {}
  14. local persecond = 0
  15. modem.open(1)
  16. local send_off = true
  17.  
  18. function secondcalc()
  19.   os.sleep(5)
  20.   while true do
  21.   local probeone = 0
  22.   local probetwo = 0
  23.   for x = 1,#cubes do
  24.     probeone = probeone + cubes[x].getEnergy()
  25.   end
  26.   os.sleep(1)
  27.   for x= 1,#cubes do
  28.     probetwo = probetwo + cubes[x].getEnergy()
  29.   end
  30.  
  31.   local probe = probetwo-probeone
  32.   persecond = probe
  33.   end
  34. end  
  35.  
  36. local t = thread.create(secondcalc)
  37.  
  38. function energy()
  39.  
  40. while true do
  41.   cubes = {}
  42.  
  43.   for address, name in component.list("cube", false) do
  44.     table.insert(cubes, component.proxy(address))
  45.   end
  46.  
  47.   local length = tonumber(#cubes)
  48.  
  49.   gpu.setForeground(0xFFFFFF)
  50.   gpu.set(1,1,string.format("%d Cubes:", length))
  51.   local max_energy = 0
  52.   local total_energy = 0
  53.  
  54.   for x=1,length do
  55.     max_energy = max_energy + cubes[x].getMaxEnergy()
  56.     total_energy = total_energy + cubes[x].getEnergy()
  57.   end
  58.  
  59.  
  60.   local percent = total_energy/max_energy*100
  61.  
  62.   if percent > 90.0 and send_off == false then
  63.     modem.broadcast(1, "off")
  64.     send_off=true
  65.   elseif percent < 50.0 and send_off == true then
  66.     modem.broadcast(1,"on")
  67.     send_off = false
  68.   end
  69.  
  70.   if percent < 50.0 and percent > 20.0 then
  71.     gpu.setForeground(0xFFB600)
  72.   elseif percent < 20.0 then
  73.     gpu.setForeground(0xCC2400)
  74.   else
  75.     gpu.setForeground(0x33B600)
  76.   end  
  77.  
  78.   gpu.fill(1,2,13,2,' ')
  79.   if not(percent< 70.0 and percent > 68.99 ) then  
  80.     gpu.set(1,2,string.format('%.2f %%', percent))
  81.   else
  82.     gpu.set(1,2,"HEHE BOÄ")
  83.   end
  84.   if redstone.getInput()[3] == 15.0 then
  85.     gpu.set(1,3,string.format('%.0f kRF/t', persecond/1000))
  86.   else
  87.     gpu.set(1,3,string.format('%.2f MRF', total_energy/1000000))
  88.   end
  89.  
  90.   term.clear()
  91.   term.write(string.format("Ze Energy:\n"))
  92.   term.write(string.format('%.2f %%\n',percent))
  93.   term.write(string.format('%.0f/%.0f RF\n',total_energy,max_energy))
  94.   term.write(string.format('%.2f RF/t', persecond))
  95.   os.sleep(0.1)
  96.  
  97. end
  98. end
  99.  
  100.  
  101. while not(pcall(energy)) do
  102.   gpu.fill(1,1,13,2,' ')
  103.   gpu.setForeground(0xFF0000)
  104.   gpu.set(1,1,"Not")
  105.   gpu.set(1,2,"Monitoring")
  106.   term.clear()
  107.   term.write("Not Monitoring. Restart imminent")
  108.   for x=1,5 do
  109.     gpu.set(x,3,".")
  110.     os.sleep(1)
  111.   end
  112. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement