Advertisement
GauHelldragon

ChargerHelper v0.2

Aug 29th, 2014
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.92 KB | None | 0 0
  1. local modem = peripheral.wrap("bottom")
  2. local charger = "batbox_1"
  3. local charger2 = "tile_thermalexpansion_machine_charger_name_2"
  4. local chest = peripheral.wrap("right")
  5. local cSize = chest.getInventorySize()
  6.  
  7. print("This computer monitors the batbox and chest connected to it")
  8. print("When a jetpack is in the chest and is not fully charged, it is pushed into batbox.")
  9. print("When an item is in the batbox and is fully charged, it is pushed into the chest")
  10.  
  11.  
  12. function isCharging()
  13.   local item = modem.callRemote(charger,"getStackInSlot",1)
  14.   if ( item == nil ) then
  15. --    print "no item"
  16.     return false
  17.   end
  18.   if ( item.dmg <= 1 ) then
  19. --    print "item is charged, pushing"
  20.     modem.callRemote(charger,"pushItem","north",1)  
  21.     os.sleep(1)
  22.     return false
  23.   end
  24. --  print "item is not charged"
  25.   return true
  26. end
  27.  
  28. function isCharging2()
  29.   local item = modem.callRemote(charger2,"getStackInSlot",1)
  30.   if ( item == nil ) then
  31.     return false
  32.   end
  33.   return true
  34.  
  35. end
  36.  
  37.  
  38. function isChargableItem(item)
  39.   if ( item == nil ) then return false end
  40.   if ( item.id == 30209 ) then --Jetpack
  41.     if ( item.dmg > 1 ) then return true end
  42.   end
  43.   return false
  44. end
  45.  
  46.  
  47. function isChargableItem2(item)
  48.   if ( item == nil ) then return false end
  49.   if ( item.id == 20759 ) then --Flux Sword
  50.     if ( item.energyStored < item.maxEnergyStored ) then return true end
  51.   end
  52.   return false
  53. end
  54.  
  55. function chargeItem()
  56.  
  57.   for slot = 1,cSize do
  58.     local item = chest.getStackInSlot(slot)
  59.     if ( item ~= nil and isChargableItem(item) ) then
  60.       chest.pushItem("south",slot)
  61.       os.sleep(1)
  62.       return
  63.     end
  64.     if ( item ~= nil and isChargableItem2(item )) then
  65.       chest.pushItem("west",slot)
  66.       os.sleep(1)
  67.       return     
  68.  
  69.     end
  70.   end  
  71. end
  72.  
  73. while true do
  74.  if ( isCharging() == false or isCharging2() == false ) then
  75.    chargeItem()
  76.  else
  77.    os.sleep(10)
  78.  end
  79.  os.sleep(5)
  80. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement