irnotbeowulf

item exchanger

May 6th, 2021
637
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. mon = peripheral.find("monitor")
  2. player = peripheral.find("playerDetector")
  3. router = peripheral.find("modularrouters:item_router")
  4. storage = peripheral.find("rsBridge")
  5. barrel = peripheral.find("metalbarrels:diamond_tile")
  6. barrelName = "metalbarrels:diamond_tile_0"
  7. routerName = "modularrouters:item_router_0"
  8.  
  9.  
  10. local function eject(seconds)
  11.   rs.setAnalogOutput("right", 5)
  12.   sleep(seconds)
  13.   rs.setAnalogOutput("right", 0)
  14. end
  15.  
  16. while true do
  17. payment = router.getItemDetail(1)
  18. price = barrel.getItemDetail(1)
  19. product = barrel.getItemDetail(3)
  20.  
  21. if payment then
  22.   if payment.name == price.name then
  23.     if payment.count >= price.count then
  24.       local quantity = math.floor(payment.count / price.count)
  25.      
  26.       payment.count = (price.count * quantity)
  27.       product.count = (quantity * product.count)
  28.       storage.importItemFromChest(payment, routerName)
  29.      
  30.       rs.setAnalogOutput("right",5)
  31.  
  32.       storage.exportItemToChest(product, routerName)
  33.       rs.setAnalogOutput("right",0)
  34.       rs.setAnalogOutput("right",5)
  35.       sleep(5)
  36.       rs.setAnalogOutput("right",0)
  37.     end
  38.   else
  39.     eject()  
  40.   end
  41. end
  42. end
RAW Paste Data