JaMaNi133

powerCounter

Jul 10th, 2021 (edited)
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.12 KB | None | 0 0
  1. local cap1 = peripheral.wrap("left")
  2. local cap2 = peripheral.wrap("right")
  3. dsp1 = peripheral.wrap("monitor_1")
  4. user1OutSIR = 0
  5. user2OutSIR = 0
  6. monitorVal1 = 0
  7. monitorVal2 = 0
  8.  
  9. local index = 0
  10.  
  11. while true do
  12.     dsp1.clear()
  13.     dsp1.setTextScale(0.5)
  14.     dsp1.setBackgroundColor(colors.gray)
  15.     dsp1.setCursorPos(1,1)
  16.     dsp1.write("Power Monitor  (pay in DRC/Draconium)")
  17.     dsp1.setBackgroundColor(colors.lightGray)
  18.     dsp1.setCursorPos(1,2)
  19.     dsp1.write("Price : 1 Draconium Dust / 20E6 RF        ")
  20.     dsp1.setBackgroundColor(colors.black)
  21.     if redstone.getInput("left") then
  22.         dsp1.setBackgroundColor(colors.lime)
  23.     else
  24.         dsp1.setBackgroundColor(colors.red)
  25.     end
  26.     dsp1.setCursorPos(1,4)
  27.     dsp1.write("User 01 Power Counter                                 ")
  28.     dsp1.setBackgroundColor(colors.black)
  29.     dsp1.setCursorPos(1,5)
  30.     dsp1.write("Count: ")
  31.     dsp1.write(math.floor(monitorVal1))
  32.     dsp1.write(" Rf (")
  33.     dsp1.write(math.floor(monitorVal1*10/20000000)/10)
  34.     dsp1.write(" DRC)")
  35.  
  36.     if redstone.getInput("right") then
  37.         dsp1.setBackgroundColor(colors.lime)
  38.     else
  39.         dsp1.setBackgroundColor(colors.red)
  40.     end
  41.     dsp1.setCursorPos(1,7)
  42.     dsp1.write("User 02 Power Counter                                 ")
  43.     dsp1.setBackgroundColor(colors.black)
  44.     dsp1.setCursorPos(1,8)
  45.     dsp1.write("Count: ")
  46.     dsp1.write(math.floor(monitorVal2))
  47.     dsp1.write(" Rf (")
  48.     dsp1.write(math.floor(monitorVal2*10/20000000)/10)
  49.     dsp1.write(" DRC)")
  50.  
  51.     user1OutSIR = user1OutSIR + cap1.getAverageOutputPerTick()
  52.     user2OutSIR = user2OutSIR + cap2.getAverageOutputPerTick()
  53.     index = index + 1
  54.     if index == 60 then
  55.         dataFile = fs.open("counterstat.txt","r")
  56.         datafromFile1 = dataFile.readLine()
  57.         datafromFile2 = dataFile.readLine()
  58.  
  59.         monitorVal1 = datafromFile1
  60.         monitorVal2 = datafromFile2
  61.         dataFile.close()
  62.         dataFile = fs.open("counterstat.txt","w")
  63.         datafromFile1 = tonumber(datafromFile1) + user1OutSIR
  64.         datafromFile2 = tonumber(datafromFile2) + user2OutSIR
  65.         dataFile.writeLine(datafromFile1)
  66.         dataFile.writeLine(datafromFile2)
  67.  
  68.         dataFile.flush()
  69.         dataFile.close()
  70.         index = 0
  71.         user1OutSIR = 0
  72.         user2OutSIR = 0
  73.     end
  74.     os.sleep(1/20)
  75. end
  76.  
Add Comment
Please, Sign In to add comment