Advertisement
Putnam

computercraft item wireless sender

Nov 10th, 2020 (edited)
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.58 KB | None | 0 0
  1. function requesterDaemon()
  2.     local ME = peripheral.wrap('right')
  3.     local modem = peripheral.wrap('left')
  4.     modem.open(41777)
  5.     while true do
  6.         local e,s,schan,rchan,message,rdist = os.pullEvent("modem_message")
  7.         if schan == 41777 then
  8.             local amount = tonumber(message[2])
  9.             local good,i = pcall(function() return ME.findItem(message[1]) end)
  10.             if good then
  11.                 local maxAmount = i.getMetadata().count
  12.                 if maxAmount > 0 then
  13.                     amount = math.min(amount,maxAmount)
  14.                     i.export('up',amount)
  15.                     modem.transmit(rchan,404,"Delivered "..message[2].." "..message[1])
  16.                 else
  17.                     local craftJob = i.craft(amount)
  18.                     if craftJob.status == "missing" then
  19.                         modem.transmit(rchan,404,"There was none of that item and no crafting job could be started; aborting.")
  20.                     else
  21.                         while not craftJob.isFinished() do
  22.                             coroutine.yield()
  23.                         end
  24.                         i.export('up',amount)
  25.                         modem.transmit(rchan,404,"Delay was due to crafting. Delivered "..message[2].." "..message[1])
  26.                     end
  27.                 end
  28.             else
  29.                 modem.transmit(rchan,404,"No item with that name.")
  30.             end
  31.             print("Sent "..message[2].." "..message[1]..".")
  32.         end
  33.     end
  34. end
  35.  
  36. parallel.waitForAny(requesterDaemon, function() shell.run("/rom/programs/shell") end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement