Advertisement
RabaGhast

newFluidTankMonitor

Oct 21st, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.81 KB | None | 0 0
  1. local tank = peripheral.wrap("front")
  2. local amount
  3. local warning = 0.5
  4. local sleepTime = 5
  5.  
  6.  
  7.  
  8. function getTank(tank)
  9.   local tableInfo = tank.getTankInfo("unknown")
  10.   fluidAmount = nil
  11.   fluidCapacity = tableInfo[1].capacity
  12.   local contents = tableInfo[1].contents  
  13.   if contents then
  14.     fluidAmount = contents.amount
  15.   end
  16.   return fluidAmount, fluidCapacity
  17. end
  18.  
  19. while true do
  20.   rs.setOutput("back", false)
  21.   local fluidAmount, fluidCapacity = getTank(tank)
  22.   amount = fluidAmount
  23.  
  24.   if fluidCapacity == nil then
  25.     print("FluidCapacity in tank is nil. Mabye no tank is found")
  26.   elseif fluidAmount == nil or fluidAmount == 0 then
  27.     rs.setOutput("back", true)
  28.   else
  29.     if fluidAmount / fluidCapacity <= warning then
  30.       rs.setOutput("back", true)
  31.     end
  32.   end
  33.   sleep(sleepTime)
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement