Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Work in Progress
- --Desc: A Modem program which attempts to send items from a connected inventory in the network to a different connected inventory in the network
- --By: hornedcommando
- function input()
- while true do
- write("from?\n")
- fromInv = peripheral.wrap(read())
- write("to?\n")
- toInv = peripheral.wrap(read())
- write("item? (Press Enter to specify none, if no item is specified all types will be sent)\n")
- --TODO: probably needs an item map, don't want to have to type out the full item name, should be colloquial like "coal" or "iron"
- item = read()
- write("amount? (Press Enter to specify none, if no amount is specified all will be sent\n")
- amount = tonumber(read())
- break
- end
- end
- function send(from, to, item, amount)
- --Check if from and to are valid peripherals
- if not peripheral.isPresent(from) then
- print("Error: No peripheral found on side " .. from)
- return
- end
- if not peripheral.isPresent(to) then
- print("Error: No peripheral found on side " .. to)
- return
- end
- --Check if from has an inventory
- local fromInv = peripheral.wrap(from)
- if not fromInv or not fromInv.list then
- print("Error: No inventory found on side " .. from)
- return
- end
- --Check if to has an inventory
- local toInv = peripheral.wrap(to)
- if not toInv or not toInv.list then
- print("Error: No inventory found on side " .. to)
- return
- end
- --Check if the item exists in from
- local itemSlot
- for slot, itemData in pairs(fromInv.list()) do
- if itemData.name == item then
- itemSlot = slot
- break
- end
- end
- if not itemSlot then
- print("Error: Item " .. item .. " not found in " .. from)
- return
- end
- --Check if there are enough items in from
- local itemCount = fromInv.getItemCount(itemSlot)
- if itemCount < amount then
- print("Error: Not enough " .. item .. " in " .. from)
- return
- end
- -- Push items from from to to
- fromInv.pushItems(peripheral.getName(to), itemSlot, amount)
- print("Sent " .. amount .. " " .. item .. " from " .. from .. " to " .. to)
- end
- input()
- send(fromInv, toInv, item, amount)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement