Advertisement
Guest User

Untitled

a guest
Oct 20th, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. args={...}
  2. output="back"
  3. turnOnLevel=25
  4. --find and wrap the cell
  5. function getPeripheral(thing)
  6. local Sides = {
  7. "left","right",
  8. "top","bottom",
  9. "front","back",
  10. }
  11.  
  12. for i,v in pairs(Sides) do
  13. if (peripheral.isPresent(v) and peripheral.getType(v) == thing) then
  14. print("'"..thing.."' found on side '"..v.."'.")
  15. return peripheral.wrap(v), v
  16. end
  17. end
  18.  
  19. print("ERROR: '"..thing.."' not found!")
  20. return nil, nil
  21. end
  22. --calculate % energy level
  23. function calculateLevel(currentEnergy, maxEnergy)
  24. local level=0
  25. local fraction=0
  26. fraction=currentEnergy/maxEnergy
  27. level=fraction*100
  28. return level
  29. end
  30. ---MAIN--
  31. charging=false
  32. redstone.setOutput(output,false)
  33. cell=getPeripheral("cofh_thermalexpansion_energycell")
  34. maxEnergy=cell.getMaxEnergyStored("back")
  35. currentEnergy=cell.getEnergyStored("back")
  36. term.clear()
  37. term.setCursorPos(1,1)
  38. print ("Current energy:- "..currentEnergy.."RF")
  39. print ("Max energy:- "..maxEnergy.."RF")
  40. if (args[1] == nil) then
  41. print ("No arguments set, using default low power:- 25%, redstone signal:- back.")
  42. print ("Use [cellmanager help] for more info.")
  43. output="back"
  44. turnOnLevel=25
  45. elseif (args[1] == "help") then
  46. print ("Cellmanger help:- Use cellmanager <xxxx> <yyyy>.")
  47. print ("")
  48. print ("xxxx=redstone output side on computer for RF generator 'left','right','top','bottom','front','back'. Default is back side.")
  49. print ("")
  50. print ("yyyy=low charge percentage to start charging at (no percent sign). Default 25%.")
  51. print ("")
  52. print ("Add cellmanger to computer startup file to restart cellmanger on server restart.")
  53. else
  54. output = args[2]
  55. turnOnLevel = tonumber(args[2])
  56. if (turnOnLevel == nil or turnOnLevel <=-1 or turnOnLevel >= 101) then
  57. print ("Invalid low power setting, using default, 25%.")
  58. turnOnLevel=25
  59. else
  60. print("Low power set to "..turnOnLevel.."%")
  61. end
  62. side = args[1]
  63. if string.match(side, "back") then
  64. print ("Redstone signal on back.")
  65. output=side
  66. elseif string.match(side, "left") then
  67. print ("Redstone signal on left.")
  68. output=side
  69. elseif string.match(side, "right") then
  70. print ("Redstone signal on right.")
  71. output=side
  72. elseif string.match(side, "front") then
  73. print ("Redstone signal on front.")
  74. output=side
  75. elseif string.match(side, "top") then
  76. print ("Redstone signal on top.")
  77. output=side
  78. elseif string.match(side, "bottom") then
  79. print ("Redstone signal on bottom.")
  80. output=side
  81. else
  82. print ("Redstone side incorrectly set, check your spelling, only 'left','right','top','bottom','front','back' permitted. Using default, back")
  83. output="back"
  84. end
  85. end
  86. print("")
  87. getLevelX,getLevelY = term.getCursorPos()
  88. while true do
  89. currentEnergy=cell.getEnergyStored("back")
  90. currentLevel=calculateLevel(currentEnergy,maxEnergy)
  91. term.setCursorPos(1,getLevelY)
  92. term.clearLine()
  93. print("Current energy is "..currentLevel)
  94. if (currentLevel <= turnOnLevel and charging == false) then
  95. redstone.setOutput(output,true)
  96. charging=true
  97. term.setCursorPos(1,getLevelY+1)
  98. term.clearLine()
  99. print("Cell low power, starting charge")
  100. elseif (currentLevel >= 99 and charging==true) then
  101. redstone.setOutput(output,false)
  102. charging=false
  103. term.setCursorPos(1,getLevelY+1)
  104. term.clearLine()
  105. print("Cell full, stopping charge")
  106. end
  107. sleep(2)
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement