SteamPunk_Devil

Tank

Jan 12th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.76 KB | None | 0 0
  1. while true do
  2.     sleep(.1)
  3.  
  4.     local PeriList = peripheral.getNames()
  5.     local TankList = {}
  6.     local OtherPeriList = {}
  7.    
  8.     for i = 1, #PeriList do
  9.         if string.match(PeriList[i],"rcirontankvalvetile") or string.match(PeriList[i],"rcsteeltankvalvetile") then
  10.             TankList[#TankList + 1] = PeriList[i]
  11.         else
  12.             OtherPeriList[#OtherPeriList + 1] = PeriList[i]
  13.         end
  14.     end
  15.  
  16.     local Tank1 = peripheral.wrap(TankList[1])
  17.     local Tank2 = peripheral.wrap(TankList[2])
  18.     local Tank3 = peripheral.wrap(TankList[3])
  19.     local Tank4 = peripheral.wrap(TankList[4])
  20.      
  21.  
  22.     local DoubleArray1 = Tank1.getTankInfo("unknown")  
  23.     local SingleArray1 = DoubleArray1[1]
  24.  
  25.     local DoubleArray2 = Tank2.getTankInfo("unknown")  
  26.     local SingleArray2 = DoubleArray2[1]
  27.  
  28.     local DoubleArray3 = Tank3.getTankInfo("unknown")  
  29.     local SingleArray3 = DoubleArray3[1]
  30.  
  31.     local DoubleArray4 = Tank4.getTankInfo("unknown")  
  32.     local SingleArray4 = DoubleArray4[1]
  33.  
  34.     local percent1 = Percentage(SingleArray1["amount"], SingleArray1["capacity"])
  35.     local percent2 = Percentage(SingleArray2["amount"], SingleArray2["capacity"])
  36.     local percent3 = Percentage(SingleArray3["amount"], SingleArray3["capacity"])
  37.     local percent4 = Percentage(SingleArray4["amount"], SingleArray4["capacity"])
  38.  
  39.     rednet.open("top")
  40.     rednet.broadcast("Tank,"..SingleArray1["name"]..","..percent1..","..SingleArray2["name"]..","..percent2..","..SingleArray3["name"]..","..percent3..","..SingleArray4["name"]..","..percent4,"Monitor")
  41.     rednet.close()
  42. end
  43.  
  44. function Percentage(current,total)
  45.  
  46.         local No1 = current
  47.         local No2 = total
  48.         local Percent = (current / total) * 100
  49.  
  50.         return Round(Percent, 0)
  51. end
  52.  
  53. function Round(num, idp)
  54.   local mult = 10^(idp or 0)
  55.   return math.floor(num * mult + 0.5) / mult
  56. end
Advertisement
Add Comment
Please, Sign In to add comment