Clem105

Tank Monitor

Jun 11th, 2014
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.71 KB | None | 0 0
  1. Tank = peripheral.wrap("back")
  2. --local m = peripheral.wrap("top")
  3. --term.redirect(m)
  4. Color1 = colors.white
  5. Color2 = colors.red
  6. Title = "Lava Tank"
  7. Data = {}
  8. Width = 5
  9. Height = 10
  10. x,y = term.getSize()
  11. term.clear()
  12. if Width > x then
  13.     print("Error : Width too large ")
  14.     os.shutdown()
  15. elseif Height >   y then
  16.     print("Error : Height too hight ")
  17. end
  18.  
  19. function Middle(SizeMax,Size)
  20.     return(math.floor((SizeMax/2)-(Size/2)))
  21. end
  22.  
  23. function FillData()
  24.     for k,v in pairs(Tank.getTanks("back")[1]) do
  25.         peripheral.call("top","write",k)
  26.         peripheral.call("top","write",v)
  27.         peripheral.call("top","write","\n")
  28.         Data[k] = v
  29.     end
  30. end
  31.  
  32. function getCord(Cord)
  33.     Xpos,Ypos = term.getCursorPos()
  34.     if Cord == "x" then
  35.         return Xpos
  36.     else
  37.         return Ypos
  38.     end
  39. end
  40. function Initialisation()
  41.     term.setCursorPos(Middle(x,Width),Middle(y,Height))
  42.     paintutils.drawLine(getCord("x"),getCord("y"),getCord("x"),getCord("y")+Height,Color1)
  43.     paintutils.drawLine(getCord("x"),getCord("y"),getCord("x")+Width,getCord("y"),Color1)
  44.     paintutils.drawLine(getCord("x")+Width,getCord("y")+Height,getCord("x"),getCord("y")+Height,Color1)
  45.     paintutils.drawLine(getCord("x")+Width,getCord("y")+Height,getCord("x"),getCord("y")+Width,Color1)
  46. end
  47.  
  48. while true do
  49.     term.clear()
  50.     Initialisation()
  51.     FillData()
  52.     term.setCursorPos(getCord("x")+1,getCord("y"))
  53.     for i = 1,(Data["amount"]/Data["capacity"])*Width do
  54.         paintutils.drawLine(getCord("x"),getCord("y")+i,getCord("x")+Width-2,getCord("y")+i,Color2)
  55.     end
  56.     term.setCursorPos(Middle(x,2*#Title),Middle(y,term.getCursorPos()[2]))
  57.     term.write(Title)
  58.     term.setCursorPos(getCord("x"),getCord("y")+5)
  59.     term.write(math.floor(Data["amount"]/Data["capacity"]*100).." %")
  60.     sleep(5)
  61. end
Advertisement
Add Comment
Please, Sign In to add comment