iconmaster

powergui

Jul 14th, 2013
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.85 KB | None | 0 0
  1. gui = peripheral.wrap("top")
  2. modem = peripheral.wrap("bottom")
  3. cells = modem.getNamesRemote()
  4. lastTotal = 0
  5. maxPower = 600000*(#cells)
  6. gui.clear()
  7. box = gui.addBox(95,25,50,14,0xffffff,.2)
  8. label = gui.addText(100,30,"",0x000000)
  9.  
  10. function round(n)
  11.     return math.floor(n*10)/10
  12. end
  13.  
  14. while true do
  15.     sleep(1)
  16.     total = 0
  17.     for i,v in ipairs(cells) do
  18.         total = total + modem.callRemote(v,"getEnergyStored")
  19.     end
  20.    
  21.     powerNet = round((total - lastTotal) / 20)
  22.     powerPercent = round(total / maxPower * 100)
  23.    
  24.     text = "POWER: " .. total .. " (" .. powerPercent .. "%) NET: " .. powerNet
  25.     label.setText(text)
  26.     box.setWidth(gui.getStringWidth(text)+10)
  27.     lastTotal = total
  28.    
  29.     --if #(gui.getAllIds()) > 2 then
  30.     --  gui.clear()
  31.     --  box = gui.addBox(95,25,gui.getStringWidth(text)+10,14,0xffffff,.2)
  32.     --  label = gui.addText(100,30,text,0x000000)
  33.     --end
  34. end
Advertisement
Add Comment
Please, Sign In to add comment