Advertisement
Arc13

TheWitch Dashboard

Oct 25th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.07 KB | None | 0 0
  1. local nStartTime = os.clock()
  2.  
  3. os.loadAPI("fmt")
  4. os.loadAPI("sevseg")
  5. os.loadAPI("countAPI")
  6.  
  7. term.redirect(peripheral.find("monitor"))
  8.  
  9. local pEntity = peripheral.find("EntityDetector")
  10.  
  11. term.setBackgroundColor(colors.lightGray)
  12. term.clear()
  13.  
  14. local monX, monY = term.getSize()
  15.  
  16. paintutils.drawLine(1, 1, monX, 1, colors.gray)
  17. term.setCursorPos(1, 1)
  18. term.write("TheWitch Dashboard")
  19.  
  20. paintutils.drawFilledBox(1, 2, 13, monY, colors.lightBlue)
  21.  
  22. term.setBackgroundColor(colors.lightGray)
  23. term.setTextColor(colors.gray)
  24.  
  25. term.setCursorPos(15, 3)
  26. term.write("Total")
  27.  
  28. term.setCursorPos(15, 6)
  29. term.write("Uptime")
  30.  
  31. term.setCursorPos(15, 9)
  32. term.write("Average")
  33.  
  34. term.setTextColor(colors.white)
  35.  
  36. local nWitchCount = 0
  37. local sWitchCount = ""
  38. local nTotalWitchCount = 0
  39. local nOldWitchCount = 0
  40. local nUptime = 0
  41. local nUptimeMin = 0
  42. local nAvgWitch = 0
  43.  
  44. local function round(val, decimal)
  45.   if (decimal) then
  46.     return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
  47.   else
  48.     return math.floor(val+0.5)
  49.   end
  50. end
  51.  
  52. local function main()
  53.   while true do
  54.     nOldWitchCount = nWitchCount
  55.  
  56.     nWitchCount = countAPI.getEntityCount(20, 3170, 68, 1188, "EntityWitch")
  57.     sWitchCount = string.format("%02d", nWitchCount)
  58.  
  59.     sevseg.drawSevenSeg(tonumber(sWitchCount:sub(1, 1)), 2, 3, 3)
  60.     sevseg.drawSevenSeg(tonumber(sWitchCount:sub(2, 2)), 9, 5, 2)
  61.  
  62.     if nWitchCount > nOldWitchCount then
  63.       nTotalWitchCount = nTotalWitchCount + (nWitchCount - nOldWitchCount)
  64.     end
  65.  
  66.     nAvgWitch = nTotalWitchCount / nUptimeMin
  67.  
  68.     term.setBackgroundColor(colors.lightGray)
  69.     term.setCursorPos(15, 4)
  70.     term.write(tostring(nTotalWitchCount))
  71.  
  72.     term.setCursorPos(15, 7)
  73.     term.write(fmt.formatSeconds(nUptime))
  74.  
  75.     term.setCursorPos(15, 10)
  76.     term.write(tostring(round(nAvgWitch, 2)).." witch/min        ")
  77.  
  78.     sleep(0.5)
  79.   end
  80. end
  81.  
  82. local function uptimer()
  83.   while true do
  84.     nUptime = os.clock() - nStartTime
  85.     nUptimeMin = math.floor(nUptime /  60) + 1
  86.  
  87.     sleep(0.3)
  88.   end
  89. end
  90.  
  91. parallel.waitForAll(main, uptimer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement