Advertisement
Dev_S

CC:T_AE_storage_turtle

Jun 6th, 2020
1,361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.90 KB | None | 0 0
  1. rednet.open("top")
  2. rednet.host("storage", tostring(os.getComputerID()))
  3.  
  4. while true do
  5.     -- wait for computer
  6.     print("awaiting request")
  7.     local from,id = rednet.receive("item_request_turtle")
  8.     print("request for "..id)
  9.     -- todo binary search / sorting?
  10.     for i = 1, 16 do
  11.         local item = turtle.getItemDetail(i)
  12.         -- found correct id
  13.         if (item ~= nil) and (item.name == id) then
  14.             -- send server amount
  15.             print("found ".. item.count .. " of " .. item.name)
  16.             rednet.send(from, item.count, "item_request_turtle")
  17.             -- get amount to extract from server
  18.             local from,count = rednet.receive("item_request_turtle")
  19.             -- drop items
  20.             turtle.select(i)
  21.             turtle.drop(count)
  22.         end
  23.     end
  24.     -- terminate request
  25.     rednet.send(from, 0, "item_request_turtle")
  26. end
  27.  
  28. rednet.close("top")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement