Advertisement
osmarks

powerbar

Jan 13th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.70 KB | None | 0 0
  1. local lamps = {}
  2. for _, n in pairs(peripheral.getNames()) do
  3.     local num = tonumber(n:match "colorful_lamp_(%d+)")
  4.     if num then lamps[num] = peripheral.wrap(n) end
  5. end
  6. local numlamps = #lamps
  7.  
  8. local cell = peripheral.find "rftoolspower:cell3"
  9.  
  10. local function get_level()
  11.     return cell.getRFStored() / cell.getRFCapacity()
  12. end
  13.  
  14. while true do
  15.     local lvl = get_level()
  16.     local on_color = 31744
  17.     local off_color = 0
  18.     if lvl > 0.2 then
  19.         on_color = 32736
  20.     end
  21.     if lvl > 0.5 then
  22.         on_color = 992
  23.     end
  24.     for index, periph in pairs(lamps) do
  25.         local place = index / numlamps
  26.         if place < lvl then
  27.             periph.setLampColor(on_color)
  28.         else
  29.             periph.setLampColor(off_color)
  30.         end
  31.     end
  32.     sleep(1)
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement