dragon81655

requester

Jul 20th, 2022
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. local arrayTable = require("array")
  2. local chests = require("chestList")
  3. function request(searched, output)
  4. term.clear()
  5. term.setCursorPos(1,1)
  6. local amount
  7. local its
  8. for i = 1, #searched do
  9. if(string.sub(searched, i,i) == " ") then
  10. amount = string.sub(searched, 1, i - 1)
  11. its = string.sub(searched, i+1,#searched)
  12. end
  13. end
  14. print("Count:" ..amount .. " Name: " .. its)
  15.  
  16. local toTake = arrayTable.new()
  17. local amountNeeded = amount
  18. local canStop = false
  19. for i = 0, chests.size - 1 do
  20. for slot, item in pairs(chests.list[i].list()) do
  21. if(item) then
  22. if(item.name == its) then
  23. print("Set")
  24. toTake.set({info = item ,slot = slot , chest = i})
  25. if(amountNeeded - item.count <= 0) then
  26. canStop = true
  27. break
  28. end
  29. amountNeeded = amountNeeded - amount
  30. end
  31. end
  32. end
  33. if(canStop == true) then break end
  34. end
  35. for index, item in pairs(toTake.list) do
  36. if(item.info.count - amount > 0) then
  37. output.pullItems(peripheral.getName(chests.list[tonumber(item.chest)]),tonumber(item.slot), tonumber(amount))
  38. break
  39. else
  40. output.pullItems(peripheral.getName(chests.list[tonumber(item.chest)]),tonumber(item.slot), tonumber(item.info.count))
  41. amount = amount - item.info.count
  42. end
  43. end
  44. end
  45. return request
Advertisement
Add Comment
Please, Sign In to add comment