Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = {...}
- modem = peripheral.wrap("top")
- chest = peripheral.wrap("right")
- replyGlobal = 1
- modemport = 3
- function main()
- me = peripheral.wrap("back")
- if args[1] == "1" then
- searchSimple(args[2], 1)
- elseif args[1] == "2" then
- searchLong(args[2], 1)
- else
- modem.open(modemport)
- while true do
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- replyGlobal = replyChannel
- if string.sub(message, 0, 4) == "send" then
- status, errormessage = pcall(sendItem, message)
- elseif string.sub(message, 0, 5) == "clear" then
- status, errormessage = pcall(clearItems)
- end
- if status then
- modem.transmit(replyGlobal, modemport, "Done")
- else
- modem.transmit(replyGlobal, modemport, errormessage)
- modem.transmit(replyGlobal, modemport, "Done")
- end
- end
- end
- end
- function searchSimple(input, amount)
- lowerinput = string.lower(input)
- allitems = me.listAvailableItems()
- for key, proptable in pairs(allitems) do
- name = string.lower(proptable.name)
- if string.match(name, lowerinput) then
- items = me.findItems(proptable.name.."@"..proptable.damage)
- for itemnum,item in pairs(items) do
- itemmeta = item.getMetadata()
- if(itemmeta.count > 0) then
- item.export("right", amount)
- modem.transmit(replyGlobal, modemport, "Item " .. itemmeta.displayName .. " found")
- else
- modem.transmit(replyGlobal, modemport, "Item " .. itemmeta.displayName .. " found but none available")
- end
- end
- end
- end
- end
- function searchLong(input, amount)
- lowerinput = string.lower(input)
- allitems = me.listAvailableItems()
- for key, proptable in pairs(allitems) do
- item = me.findItem(proptable)
- itemmeta = item.getMetadata()
- name = string.lower(itemmeta.displayName)
- if string.match(name, lowerinput) then
- if(itemmeta.count > 0) then
- item.export("right", amount)
- else
- print("Item " .. itemmeta.displayName .. " found but none available")
- end
- end
- end
- end
- function justWords(str)
- local t = {}
- local function helper(word)
- table.insert(t, word)
- return ""
- end
- if not str:gsub("%w+", helper):find"%S" then
- return t
- end
- end
- function recombineName(table, index)
- searched = ""
- for k,v in pairs(table) do
- if k == index then
- searched = v
- end
- if k > index then
- searched = searched .. " " .. v
- end
- end
- return searched
- end
- function sendItem(message)
- chattable = justWords(message)
- word1 = chattable[2]
- if tonumber(word1) ~= nil then
- amount = tonumber(word1)
- item = recombineName(chattable, 3)
- else
- amount = 1
- item = recombineName(chattable, 2)
- end
- searchSimple(item, amount)
- end
- function clearItems()
- for i = 1, 54 do
- chest.pushItems("north", i)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement