Advertisement
Pankola

Monitor Induction Matrix

Jul 26th, 2022 (edited)
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.83 KB | None | 0 0
  1. mat = peripheral.find("inductionPort")
  2. mon = peripheral.find("monitor")
  3. monX,monY = mon.getSize()
  4.  
  5. --Func math.round & textcenter
  6. function math.round(num, dec)
  7.     local mult = 10^(dec or 2)
  8.     return math.floor(num * mult + 0.5) / mult
  9. end
  10. function centerT(text,line,backColor,txtColor)
  11.     mon.setBackgroundColor(backColor)
  12.     mon.setTextColor(txtColor)
  13.     length = (string.len(text))
  14.     dif= math.round(monX-length)
  15.     x = math.round(dif/2)
  16.     mon.setCursorPos(x+1, line)
  17.     mon.write(text)
  18. end
  19.  
  20. --Import & Def value
  21. function value()
  22.     Energy = mat.getEnergy()
  23.     MaxEnergy = mat.getMaxEnergy()
  24.     EnergyPer = math.round(mat.getEnergyFilledPercentage()*100)
  25.     LastInput = mat.getLastInput()
  26.     LastOutput = mat.getLastOutput()
  27.     TransferCap = mat.getTransferCap()
  28.     IO = math.floor(mat.getLastInput() - mat.getLastOutput())
  29.     Cell = mat.getInstalledCells()
  30.     Provider = mat.getInstalledProviders()
  31. end
  32.  
  33. --Func write
  34. function writeMon()
  35.     mon.setBackgroundColor(colors.black)
  36.     mon.clear()
  37.     mon.setCursorPos(1,1)
  38.  
  39.     if Energy >= 1000 and Energy < 1000000 then
  40.         title = "Energie: "..math.round((Energy/2.5)/1000).." / "..math.round((MaxEnergy/2.5)/1000).." kFe"
  41.         centerT(title, 3, colors.black, colors.blue)
  42.     elseif Energy >= 1000000 and Energy < 1000000000 then
  43.         title = "Energie: "..math.round((Energy/2.5)/1000000).." / "..math.round((MaxEnergy/2.5)/1000000).." MFe"
  44.         centerT(title, 3, colors.black, colors.blue)
  45.     elseif Energy >= 1000000000 then
  46.         title = "Energie: "..math.round((Energy/2.5)/1000000000).." / "..math.round((MaxEnergy/2.5)/1000000000).." GFe"
  47.         centerT(title, 3, colors.black, colors.blue)
  48.     end
  49.     if LastInput >= 0 and LastInput < 1000 then
  50.         title = "Input: "..math.round(LastInput/2.5).." / "..math.round(TransferCap/2.5).." Fe"
  51.         centerT(title, 5, colors.black, colors.green)
  52.     elseif LastInput >= 1000 and LastInput < 1000000 then
  53.         title = "Input: "..math.round((LastInput/2.5)/1000).." / "..math.round((TransferCap/2.5)/1000).." kFe"
  54.         centerT(title, 5, colors.black, colors.green)
  55.     elseif LastInput >= 1000000 and LastInput < 1000000000 then
  56.         title = "Input: "..math.round((LastInput/2.5)/1000000).." / "..math.round((TransferCap/2.5)/1000000).." MFe"
  57.         centerT(title, 5, colors.black, colors.green)
  58.     elseif LastInput >= 1000000000 then
  59.         title = "Input: "..math.round((LastInput/2.5)/1000000000).." / "..math.round((TransferCap/2.5)/1000000000).." GFe"
  60.         centerT(title, 5, colors.black, colors.green)
  61.     end
  62.  
  63.     if LastOutput >= 0 and LastOutput < 1000 then
  64.         title = "Output: "..math.round(LastOutput/2.5).." / "..math.round(TransferCap/2.5).." Fe"
  65.         centerT(title, 7, colors.black, colors.red)
  66.     elseif LastOutput >= 1000 and LastOutput < 1000000 then
  67.         title = "Output: "..math.round((LastOutput/2.5)/1000).." / "..math.round((TransferCap/2.5)/1000).." kFe"
  68.         centerT(title, 7, colors.black, colors.red)
  69.     elseif LastOutput >= 1000000 and LastOutput < 1000000000 then
  70.         title = "Output: "..math.round((LastOutput/2.5)/1000000).." / "..math.round((TransferCap/2.5)/1000000).." MFe"
  71.         centerT(title, 7, colors.black, colors.red)
  72.     elseif LastOutput >= 1000000000 then
  73.         title = "Output: "..math.round((LastOutput/2.5)/1000000000).." / "..math.round((TransferCap/2.5)/1000000000).." GFe"
  74.         centerT(title, 7, colors.black, colors.red)
  75.     end
  76.  
  77.     if IO >= 0 and IO < 1000 then
  78.         title = "IO: "..math.round(IO/2.5).." Fe/t"
  79.         centerT(title, 9, colors.black, colors.orange)
  80.     elseif IO >= 1000 and IO < 1000000 then
  81.         title = "IO: "..math.round((IO/2.5)/1000).." kFe/t"
  82.         centerT(title, 9, colors.black, colors.orange)
  83.     elseif IO >= 1000000 and IO < 1000000000 then
  84.         title = "IO: "..math.round((IO/2.5)/1000000).." MFe/t"
  85.         centerT(title, 9, colors.black, colors.orange)
  86.     elseif IO >= 1000000000 then
  87.         title = "IO: "..math.round((IO/2.5)/1000000000).." GFe/t"
  88.         centerT(title, 9, colors.black, colors.orange)
  89.     else
  90.         title = "IO: "..math.floor(IO/2.5).." Fe/t"
  91.         centerT(title, 9, colors.black, colors.orange)
  92.     end
  93.     title = "Energie: "..EnergyPer.." %"
  94.     centerT(title, 13, colors.black, colors.blue)
  95.     title = "Cells : "..Cell
  96.     centerT(title, 17, colors.black, colors.white)
  97.     title = "Providers : "..Provider
  98.     centerT(title, 18, colors.black, colors.white)
  99. end
  100.  
  101. --Func bar
  102. function drawBar()
  103.     bar = math.round(((Energy/MaxEnergy)*(monX-2))+0.5)
  104.     mon.setCursorPos(2,monY-4)
  105.     mon.setBackgroundColor(colors.red)
  106.     mon.write(string.rep(" ", monX-2))
  107.     mon.setCursorPos(2,monY-4)
  108.     mon.setBackgroundColor(colors.green)
  109.     mon.write(string.rep(" ", bar))
  110. end
  111.  
  112. while true do
  113. value()
  114. writeMon()
  115. drawBar()
  116.  
  117. sleep(0.1)
  118. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement