Thor_s_Crafter

bloodDisplay

Jan 10th, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.08 KB | None | 0 0
  1. --===== Blood Magic Altar Display =====--
  2. --===== von Thor_s_Crafter =====--
  3.  
  4. local mon
  5. local monX, monY, monX2
  6. local a
  7. local ai
  8. local col
  9.  
  10. os.loadAPI("input")
  11.  
  12. local blood = 0
  13. local maxBlood = 0
  14. local bloodPer = 0
  15.  
  16. function getPeripherals()
  17.   mon = peripheral.find("monitor")
  18.   monX,monY = mon.getSize()
  19.   monX2 = math.floor(monX/2)
  20.   a = peripheral.find("tealtar")
  21. end
  22.  
  23. function getBlood()
  24.   ai = a.getTankInfo()[1]
  25.   if ai.contents == nil then
  26.     blood = 0
  27.   else
  28.     blood = ai.contents.amount
  29.   end
  30.   maxBlood = ai.capacity
  31.   bloodPer = math.floor(blood/maxBlood*100)
  32. end
  33.  
  34. function display()
  35.   term.setCursorPos(1,1)
  36.   print("Zeit : "..getTime().."h  ")
  37.   print("Life Essence: "..(input.formatNumber(blood)).."   ")
  38.   print("Max. Life Essence: "..input.formatNumber(maxBlood).."   ")
  39.   print("in Prozent: "..bloodPer.."%   ")
  40.  
  41.   mon.setCursorPos(1,1)
  42.   mon.setTextColor(colors.white)
  43.   mon.write("Life Essence ")
  44.  
  45.   local timeLength = string.len(getTime())
  46.   mon.setCursorPos(monX-timeLength-1,1)
  47.   mon.write(" "..getTime().."h")
  48.   mon.setCursorPos(1,2)
  49.  
  50.   for i=1, monX do mon.write("=") end
  51.  
  52.   mon.setCursorPos(1,4)
  53.   mon.write("Aktuell: "..(input.formatNumber(blood)).."      ")
  54.    
  55.   mon.setCursorPos(1,5)
  56.   mon.write("Maximal: "..(input.formatNumber(maxBlood)).."      ")
  57.  
  58.   mon.setCursorPos(monX2-10,7)
  59.   mon.write("|--------------------|")
  60.  
  61.   mon.setCursorPos(monX2-9,7)
  62.   selectCol()
  63.   mon.setTextColor(col)
  64.  
  65.   local part1 = bloodPer/5
  66.   for i=1,part1 do mon.write("=") end
  67.  
  68.   mon.setCursorPos(monX2-2,8)
  69.   mon.write(bloodPer.."%  ")
  70.  
  71. end
  72.  
  73. function selectCol()
  74.   if bloodPer >= 50 then col = 8192
  75.   elseif bloodPer < 50 and bloodPer >= 20 then col = 2
  76.   elseif bloodPer < 20 then col = 16384
  77.   end  
  78. end
  79.  
  80. function getTime()
  81.   local time = os.time()
  82.   local fTime = textutils.formatTime(time,true)
  83.   return tostring(fTime)
  84. end
  85.  
  86. getPeripherals()
  87.  
  88. term.setBackgroundColor(colors.gray)
  89. term.clear()
  90. mon.setBackgroundColor(colors.gray)
  91. mon.clear()
  92. while true do
  93.   getBlood()
  94.   display()
  95.   sleep(0.2)
  96. end
Advertisement
Add Comment
Please, Sign In to add comment