Willibilly19

Advanced Energy Reading

Apr 30th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.83 KB | None | 0 0
  1. --Change the side to correspond to the side of the Info Reader
  2. m = peripheral.wrap("right")
  3.  
  4. local energy = {}
  5. local names = {}
  6. local current = 0
  7. local max = 0
  8.  
  9. local function round(num, idp)
  10.   local mult = 10^(idp or 0)
  11.   return math.floor(num * mult + 0.5) / mult
  12. end
  13.  
  14. for i = 1,9 do
  15.   local id,state,title,data = m.get(i)
  16.   --comment out the "title = i" line if your cards have names
  17.   title = i
  18.   names[i] = title
  19.   energy[i] = data
  20. end
  21.  
  22.  
  23. for l = 1,#energy do
  24.   for i,j in pairs(energy[l]) do
  25.     if i == "energyL" then
  26.       print("Storage "..names[l]..": "..j)
  27.       current = current + j
  28.     elseif i == "maxStorageL" then
  29.       max = max + j
  30.     end
  31.    
  32.   end
  33. end
  34.  
  35. local percent = current/max*100
  36.  
  37. print("Total: "..tostring(current).." / "..tostring(max))
  38. print("Percentage Full: "..round(percent, 0).."%")
Advertisement
Add Comment
Please, Sign In to add comment