BillBodkin

Get

Sep 22nd, 2021 (edited)
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.05 KB | None | 0 0
  1. args = {...}
  2.  
  3. local storageComputerID = 18
  4. local chest = "enderstorage:ender_chest_6"
  5. local slot = 1
  6.  
  7. function Get(itemName, itemCount, chest, slot)
  8.     print("Getting " .. tostring(itemCount) .. " " .. chest .. " slot " .. tostring(slot))
  9.     rednet.send(storageComputerID, {
  10.         ["action"] = "get",
  11.         ["instructionRef"] = "outChestTopup",
  12.         ["chest"] = chest,
  13.         ["slot"] = slot,
  14.         ["name"] = itemName,
  15.         ["count"] = itemCount
  16.     }, "inv")
  17.     while true do
  18.         local id, msg = rednet.receive("invResp")
  19.         if id == storageComputerID then
  20.             if msg["status"] == "success" then
  21.                 print("Got " .. tostring(msg["moved"]) .. " " .. chest .. " slot " .. tostring(slot))
  22.                 return msg["moved"]
  23.             else
  24.                 print("NOT Got " .. chest .. " slot " .. tostring(slot) .. " - " .. msg["message"])
  25.                 return 0
  26.             end
  27.         end
  28.         sleep(0)
  29.     end
  30. end
  31.  
  32. if args[1] == nil or (args[2] ~= nil and tonumber(args[2]) == nil) then
  33.     print("Usage: get name <count>")
  34. else
  35.     local count = tonumber(args[2])
  36.     if count == nil then
  37.         count = 1
  38.     end
  39.     Get(args[1], count, chest, slot)
  40. end
Add Comment
Please, Sign In to add comment