Advertisement
j3d247

Fluid Monitor

Mar 1st, 2014
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.83 KB | None | 0 0
  1. local warn = 20 --Set Warning Level of Fluids at this percentage
  2. local d = peripheral.wrap("monitor_0")
  3. local gap = 2
  4. local background = colors.white
  5. local foreground = colors.green
  6. local tanks = {}
  7. local fluids = {}
  8. d.setTextScale(1)
  9. d.setBackgroundColor(colors.black)
  10. for _, name in pairs(peripheral.getNames()) do
  11.     if peripheral.getType(name) == "rcirontankvalvetile" then
  12.         table.insert(tanks, name)
  13.     elseif peripheral.getType(name) == "rcsteeltankvalvetile" then
  14.         table.insert(tanks, name)
  15.     end
  16. end
  17.  
  18. function cwrite(text)
  19.   local w, h = d.getSize()
  20.   local x, y = d.getCursorPos()
  21.   --x = math.max(math.floor((w/2) - (#text / 2)), 0)
  22.   term.setCursorPos(x,y)
  23.   print(text)
  24.   --term.setCursorPos(x,y+1)
  25. end
  26.  
  27. function getinfo()
  28.     for k,v in pairs(tanks) do
  29.         tank = peripheral.wrap(v)
  30.         info = tank.getTankInfo(v)
  31.         for k,fluid in pairs(info) do
  32.             if fluid["rawName"] == nil then
  33.             else
  34.                 if fluid["capacity"] > 1000 then
  35.                     tankcap = fluid["capacity"]
  36.                 end
  37.                 tankamt = fluid["amount"]
  38.                 name = fluid["name"]
  39.                 if name == "honey" then
  40.                     name = "Honey"
  41.                 elseif name == "bioethanol" then
  42.                     name = "Ethanol"
  43.                 elseif name == "liquiddna" then
  44.                     name = "BNA"
  45.                 elseif string.sub(name, -7) == ".molten" then
  46.                     name = string.upper(string.sub(name,0,1))..string.sub(name,2,-8)
  47.                 end
  48.                 fluids[name] = {["cap"] = tankcap, ["amt"] = tankamt}
  49.             end
  50.         end
  51.     end
  52. end
  53. while true do
  54. term.clear()
  55. d.clear()
  56. term.setCursorPos(1,1)
  57. d.setCursorPos(2,1)
  58. maxx, maxy = d.getSize()
  59. local maxv = maxy-1
  60. getinfo()
  61. for key,val in pairs(fluids) do
  62.     currx, curry = d.getCursorPos()
  63.     d.setCursorPos(currx, maxv)
  64.     cap = val["cap"]
  65.     amt = val["amt"]
  66.     prcnt = amt/cap*100
  67.     prcnt = math.floor(prcnt)
  68.     if prcnt < warn then
  69.     term.setTextColor(colors.red)
  70.     else
  71.     term.setTextColor(colors.white)
  72.     end
  73.     print(key..": "..prcnt.."%")
  74.     term.setTextColor(colors.white)
  75.     term.redirect(d)
  76.         currval = math.ceil(((maxv)*prcnt)/100)
  77.         i = 1
  78.         while i == 1 do
  79.             d.setTextColor(colors.white)
  80.             currx, curry = d.getCursorPos()
  81.             str = tostring(prcnt.."%")
  82.             x = math.max(math.floor((#key/2) - (#str / 2) + currx), 0)
  83.             d.setCursorPos(x, curry)
  84.             d.write(prcnt.."%")
  85.             d.setCursorPos(currx, curry-1)
  86.             d.write(key..":")
  87.             d.setCursorPos(currx, curry-2)
  88.             i=i+2
  89.         end
  90.         while i < currval do
  91.             d.setBackgroundColor(foreground)
  92.             d.setTextColor(foreground)
  93.             currx, curry = d.getCursorPos()
  94.             d.write(key)
  95.             d.setCursorPos(currx, curry-1)
  96.             i=i+1
  97.         end
  98.         while i < maxv do
  99.             d.setBackgroundColor(background)
  100.             d.setTextColor(background)
  101.             currx, curry = d.getCursorPos()
  102.             d.write(key)
  103.             d.setCursorPos(currx, curry-1)
  104.             i=i+1
  105.         end
  106.     d.setBackgroundColor(colors.black)
  107.     currx, curry = d.getCursorPos()
  108.     d.setCursorPos(currx + #key + gap, maxv)
  109.     term.restore()
  110. end
  111. sleep(1.5)
  112. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement