FeanorWasWrong

tankStats.lua

Mar 9th, 2019 (edited)
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.98 KB | None | 0 0
  1. --Author: Richard Worring                                   --
  2. --Date: 17.06.2019 
  3. --Modified Last: 24.01.2021                                     --
  4.                                                             --
  5. --URL: pastebin get SLthTL2V TankStats.lua -f                   --
  6. ----------------------------------------------------------
  7.  
  8. local term = require"term"
  9. local component = require"component"
  10. local sides = require"sides"
  11.  
  12. local gpu = component.gpu
  13. local tank = component.tank_controller
  14.  
  15.  
  16. gpu.setResolution(120, 40)
  17. local w, h = gpu.getResolution()
  18.  
  19. gpu.is_palette = true
  20.  
  21. local ARRoldAmount = {}
  22. for i = 0,5 do
  23.     ARRoldAmount[i] = 0
  24. end
  25.  
  26.  
  27. gpu.setBackground(1, true)
  28. term.clear()
  29.  
  30. --Get stats of tanks
  31.     while true do
  32.     i = 5
  33.         for sides = 0,5 do
  34.            
  35.             if type(tank.getFluidInTank(sides)) == "table" then
  36.                 tanks = {}             
  37.                 for a,b in ipairs(tank.getFluidInTank(sides))
  38.                 do
  39.                     tanks[a] = {}
  40.                     tanks[a].name = b.name
  41.                     tanks[a].label = b.label
  42.                     tanks[a].unit = b.unit
  43.                     tanks[a].level = b.amount
  44.                     tanks[a].capacity = b.capacity
  45.                     vTLvl = b.amount / b.capacity
  46.                     vDeltaTLvl = (b.amount - ARRoldAmount[sides])*10  -- *10 because the os sleeps for 0.1 seconds
  47.                     gpu.fill(6, i, w, h/18, " ")
  48.                     gpu.fill(6, i+1, w, h/18, " ")
  49.                     if b.label == nil then
  50.                         gpu.set(6, i+1, "Tank on side "..sides.." empty.")
  51.                     elseif b.amount <= (b.capacity * 0.05) then
  52.                         gpu.set(6, i+1, ""..b.label.." tank on side "..sides.." below 5%.")
  53.                     else
  54.                         if b.label == "Lubricant" then
  55.                             gpu.setBackground(0xFFDB40)
  56.                             gpu.setForeground(1, true)
  57.                         elseif b.label == "Jet Fuel" then
  58.                             gpu.setBackground(0xFF2480)
  59.                             gpu.setForeground(15, true)
  60.                         elseif b.label == "Water" then
  61.                             gpu.setBackground(0x0000FF)
  62.                             gpu.setForeground(15, true)
  63.                         else
  64.                             gpu.setBackground(15, true)
  65.                             gpu.setForeground(1, true)
  66.                         end
  67.                         --Display the bar
  68.                         gpu.fill(5, i+1, ((w - 5) * vTLvl), h/18, " ")
  69.                         --Display the delta of the fuel
  70.                         if b.amount <= (b.capacity * 0.3) then
  71.                             gpu.setBackground(1, true)
  72.                             gpu.setForeground(15, true)
  73.                             gpu.set(((w * vTLvl) + 5), i+1, ""..vDeltaTLvl.."mB/Sec")
  74.                         else
  75.                             gpu.set((((w - 5) * vTLvl) * 0.5), i+1, ""..vDeltaTLvl.."mB/Sec")
  76.                         end
  77.                         gpu.setBackground(1, true)
  78.                         gpu.setForeground(15, true)
  79.                         gpu.set(6, i, ""..b.label)
  80.                         gpu.set((w - 25), i, ""..b.amount.."/"..b.capacity.."mB")
  81.                     end
  82.                     gpu.setBackground(1, true)
  83.                     gpu.setForeground(15, true)
  84.                     i = i + 5
  85.                     ARRoldAmount[sides] = b.amount
  86.                 end
  87.             else
  88.                 print("No Tank detected")
  89.             end
  90.         end
  91.         vDeltaTLvl = 0
  92.         os.sleep(0.1)
  93.     end
  94.    
  95.  
  96.  
  97.  
  98. --[[ChangeLog
  99. 23.01.2021 changed vOldAmount to vars[sides.."oldAmount"]
  100.     failed
  101. 23.01.2021 changed from vars to array for oldAmount
  102. 23.01.2021 changed low level message
  103. 23.01.2021 added if for b.label is empty
  104. 23.01.2021 changed the MB/Min to MB/Sec because the os sleeps for 2 seconds
  105. 23.01.2021 added a "clearline" row 52
  106. 24.01.2021 added a "clearlin" for the Labels
  107. ]]--
Add Comment
Please, Sign In to add comment