Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function requesterDaemon()
- local ME = peripheral.wrap('right')
- local modem = peripheral.wrap('left')
- modem.open(41777)
- while true do
- local e,s,schan,rchan,message,rdist = os.pullEvent("modem_message")
- if schan == 41777 then
- local amount = tonumber(message[2])
- local good,i = pcall(function() return ME.findItem(message[1]) end)
- if good then
- local maxAmount = i.getMetadata().count
- if maxAmount > 0 then
- amount = math.min(amount,maxAmount)
- i.export('up',amount)
- modem.transmit(rchan,404,"Delivered "..message[2].." "..message[1])
- else
- local craftJob = i.craft(amount)
- if craftJob.status == "missing" then
- modem.transmit(rchan,404,"There was none of that item and no crafting job could be started; aborting.")
- else
- while not craftJob.isFinished() do
- coroutine.yield()
- end
- i.export('up',amount)
- modem.transmit(rchan,404,"Delay was due to crafting. Delivered "..message[2].." "..message[1])
- end
- end
- else
- modem.transmit(rchan,404,"No item with that name.")
- end
- print("Sent "..message[2].." "..message[1]..".")
- end
- end
- end
- parallel.waitForAny(requesterDaemon, function() shell.run("/rom/programs/shell") end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement