Jayex_Designs

dispenseBack

Jun 15th, 2021 (edited)
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.93 KB | None | 0 0
  1. args = {...}
  2. if not args[1] then
  3.     error("Set the id of the server")
  4. end
  5. ServerId = tonumber(args[1])
  6. rednet.open("right")
  7.  
  8. function SuckUp(quantity)
  9.     while true do
  10.         if turtle.suckUp(quantity) then
  11.             local grabbedPotatoes = turtle.getItemCount()
  12.             turtle.dropDown()
  13.             if grabbedPotatoes == quantity then
  14.                 return
  15.             else
  16.                 quantity = quantity - grabbedPotatoes
  17.             end
  18.         end
  19.         print("Ran out of potatoes waiting...")
  20.         sleep(5)
  21.     end
  22. end
  23.  
  24. while true do
  25.     local id, message, protocol = rednet.receive()
  26.     if protocol == "givePotatoes" then
  27.         rednet.send(ServerId, message, "givePotatoes")
  28.         print("Giving away " .. message .. " potatoes")
  29.         for i = 1, math.floor(message / 64) do
  30.             SuckUp(64)
  31.         end
  32.  
  33.         SuckUp(message % 64)
  34.  
  35.         rednet.send(id, "done")
  36.     end
  37. end
Advertisement
Add Comment
Please, Sign In to add comment