bigtwisty

BatteryUser

Apr 17th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. --name BatteryUser
  2. --version 1.0a
  3. local version = "1.0a"
  4.  
  5. local side = {}
  6. side.batbox = 0
  7. side.chest = 4
  8. local batteryId = {}
  9. batteryId.full = 38041
  10. batteryId.empty = 5272
  11.  
  12. local inventory = {}
  13. inventory.batbox = "Empty"
  14. inventory.chest = false
  15. inventory.chestFull = 0
  16. inventory.chestEmpty = 0
  17.  
  18. local function output(str)
  19. term.clear()
  20. term.setCursorPos(1,1)
  21. print(string.format("BattUsr (v%s)",version))
  22. print("By BigTwisty")
  23. print(str)
  24. end
  25.  
  26. local sorter = peripheral.wrap("back")
  27.  
  28. --local monitor = peripheral.wrap("top")
  29. --term.redirect(monitor)
  30. --monitor.setTextScale(0.5)
  31.  
  32. while true do
  33. inventory.batbox = "Not Found..."
  34. x = sorter.list(side.batbox)
  35. if x ~= nil then
  36. inventory.batbox = "Empty"
  37. for id,qty in pairs(x) do
  38. if id == batteryId.full then
  39. inventory.batbox = "Full"
  40. else
  41. inventory.batbox = "Discharging"
  42. end
  43. end
  44. end
  45.  
  46. inventory.chestFull = 0
  47. inventory.chestEmpty = 0
  48.  
  49. x = sorter.list(side.chest)
  50. if x == nil then
  51. inventory.chest = false
  52. else
  53. inventory.chest = true
  54. for id,qty in pairs(x) do
  55. if id == batteryId.full then
  56. inventory.chestFull = inventory.chestFull + qty
  57. elseif id == batteryId.empty then
  58. inventory.chestEmpty = inventory.chestEmpty + qty
  59. end
  60. end
  61. end
  62.  
  63.  
  64. output(string.format("\n-- Status:\nBatbox: %s",
  65. inventory.batbox))
  66. write(string.format("-- Inventory:\nCharged: %d\nEmpty: %d\n",
  67. inventory.chestFull,
  68. inventory.chestEmpty))
  69.  
  70. if inventory.batbox == "Discharging" then
  71. sorter.extract(side.batbox, batteryId.empty, side.chest, 1)
  72. elseif inventory.batbox == "Empty" then
  73. sorter.extract(side.chest, batteryId.full, side.batbox, 1)
  74. end
  75.  
  76. os.sleep(0.3)
  77.  
  78. end
Advertisement
Add Comment
Please, Sign In to add comment