DPG-mattcow12

energy HUD

Aug 2nd, 2013
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. local bridge = peripheral.wrap("left")
  2. local net = peripheral.wrap("back")
  3.  
  4. bridge.clear()
  5.  
  6. local width = 200
  7.  
  8. local storageUnitsA = {
  9. {
  10. ["id"] = "redstone_energy_cell_0",
  11. ["name"] = "cell 1"
  12. },
  13. {
  14. ["id"] = "redstone_energy_cell_1",
  15. ["name"] = "cell 2"
  16. },
  17. {
  18. ["id"] = "redstone_energy_cell_2",
  19. ["name"] = "cell 3"
  20. },
  21. {
  22. ["id"] = "batbox_0",
  23. ["name"] = "mfe 1"
  24. },
  25. {
  26. ["id"] = "batbox_1",
  27. ["name"] = "mfe 2"
  28. },
  29. {
  30. ["id"] = "batbox_2",
  31. ["name"] = "mfe 3"
  32. }
  33. }
  34.  
  35. local offset = 0
  36. for key, storageUnit in pairs(storageUnitsA) do
  37. pxOffset = offset * 20
  38. storageUnit["label"] = bridge.addText(4, 4 + pxOffset, storageUnit["name"], 0x000000)
  39. storageUnit["bar"] = bridge.addBox(4, 14 + pxOffset, 0, 5, 0xCC0000, 0.9)
  40. storageUnit["bar"].setZIndex(2)
  41. storageUnit["bg"] = bridge.addBox(4, 14 + pxOffset, width, 5, 0x000000, 0.5)
  42. offset = offset + 1
  43. end
  44.  
  45. while true do
  46. for i=#storageUnitsA,1,-1 do
  47. storageUnit = storageUnitsA[i]
  48. if net.isPresentRemote(storageUnit["id"]) then
  49. if net.getTypeRemote(storageUnit["id"]) == "redstone_energy_cell" then
  50. capacity = net.callRemote(storageUnit["id"], "getMaxEnergyStored")
  51. amount = net.callRemote(storageUnit["id"], "getEnergyStored")
  52. print(storageUnit["id"] .. " : " .. amount .. "/" .. capacity)
  53. elseif net.getTypeRemote(storageUnit["id"]) == "batbox" then
  54. capacity = net.callRemote(storageUnit["id"], "getCapacity")
  55. amount = net.callRemote(storageUnit["id"], "getStored")
  56. end
  57. elseif not net.isPresentRemote(storageUnit["id"]) then
  58. storageUnit["bar"].delete()
  59. storageUnit["bg"].delete()
  60. storageUnit["label"].delete()
  61. table.remove(storageUnitsA, i)
  62. end
  63. storageUnit["bar"].setWidth(width / capacity * amount)
  64. end
  65. sleep(0.5)
  66. end
Advertisement
Add Comment
Please, Sign In to add comment