Guest User

Energy status display / Engine control

a guest
Aug 1st, 2013
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. --[[
  2. Simple Energy storage display for redstone energy cells
  3. and on-demand engine control
  4. The engine control part is optional, don't connect a rednet
  5. cable if you only want to display energy storage.
  6.  
  7. by got_m1lk
  8. --]]
  9.  
  10. --Specify side of wired modem
  11. -- Valid: "left", "right", "front", "back", "top", "bottom"
  12. local modemside = "left"
  13.  
  14. --Specify side of rednet cable
  15. local rednetside = "bottom"
  16.  
  17. --Specify side of monitor
  18. --If the monitor is attached to the modem specify peripheral-ID instead.
  19. local monitorside = "top"
  20.  
  21. --Adjust the textscale if you have a bigger/smaller monitor
  22. --Increments of 0.5
  23. local textsize = 1
  24.  
  25. --Specify at what percentage the engines turn on
  26. local min = 25
  27.  
  28. --Specify at what percentage the engines turn off
  29. local max = 95
  30.  
  31. --Specify the peripheral-IDs of you redstone cells
  32. --Remove/add units from the table to fit it to the amount
  33. -- of cells you are using
  34. local storageUnits = {
  35. {
  36. ["id"] = "redstone_energy_cell_0",
  37. ["name"] = "Cell1"
  38. },
  39. {
  40. ["id"] = "redstone_energy_cell_1",
  41. ["name"] = "Cell2"
  42. },
  43. {
  44. ["id"] = "redstone_energy_cell_2",
  45. ["name"] = "Cell3"
  46. },
  47. {
  48. ["id"] = "redstone_energy_cell_3",
  49. ["name"] = "Cell4"
  50. }
  51.  
  52. }
  53.  
  54. local mon = peripheral.wrap(monitorside)
  55. local net = peripheral.wrap(modemside)
  56.  
  57.  
  58. mon.clear()
  59. mon.setTextScale(textsize)
  60. mon.setTextColor(512)
  61. mon.setCursorPos(1,2)
  62. mon.write(" Energy Remaining:")
  63. mon.setCursorPos(1,10)
  64. mon.write(" Engine Status:")
  65. mon.setTextColor(2)
  66. rs.setBundledOutput(rednetside,colors.black)
  67.  
  68. while true do
  69.  
  70. capacity = 0
  71. amount = 0
  72.  
  73. for i=#storageUnits,1,-1 do
  74. storageUnit = storageUnits[i]
  75. capacity = capacity + net.callRemote(storageUnit["id"], "getMaxEnergyStored")
  76. amount = amount + net.callRemote(storageUnit["id"], "getEnergyStored")
  77. end
  78.  
  79.  
  80. percentage = tonumber((amount / capacity) *100)
  81. percentage = math.floor(percentage)
  82.  
  83.  
  84. if percentage <= min then
  85. rs.setBundledOutput(rednetside,colors.white)
  86. end
  87.  
  88. if percentage >= max then
  89. rs.setBundledOutput(rednetside,colors.black)
  90. end
  91.  
  92.  
  93. percentage = string.match(tostring(percentage),'[^%.]+')
  94. mon.setCursorPos(8,4)
  95. mon.clearLine()
  96. mon.setTextColor(2)
  97. mon.write(percentage .. "%")
  98. mon.setCursorPos(1,6)
  99. mon.clearLine()
  100. mon.setTextColor(512)
  101. mon.write("Energy: ")
  102. mon.setTextColor(2)
  103. mon.write(string.match(tostring(amount),'[^%.]+') .. " MJ")
  104. mon.setCursorPos(1,7)
  105. mon.clearLine()
  106. mon.setTextColor(512)
  107. mon.write(" Size: ")
  108. mon.setTextColor(2)
  109. mon.write(string.match(tostring(capacity),'[^%.]+') .." MJ")
  110.  
  111. if rs.getBundledInput(rednetside) == colors.black then
  112. mon.setTextColor(colors.red)
  113. mon.setCursorPos(8,11)
  114. mon.write("OFF")
  115. elseif rs.getBundledInput(rednetside) == colors.white then
  116. mon.setTextColor(colors.lime)
  117. mon.setCursorPos(8,11)
  118. mon.write(" ON")
  119. end
  120.  
  121.  
  122. sleep(1)
  123. end
Advertisement
Add Comment
Please, Sign In to add comment