Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- modem = peripheral.wrap("left")
- modem.open(2)
- interface = peripheral.wrap("front")
- list = interface.listAvailableItems()
- list2 = {}
- inputString = {}
- input = {}
- tempList = {}
- while (1) do
- a, b, c, d, message, e = os.pullEvent("modem_message")
- print("Searching...")
- inputString = message[1]
- input = {}
- tempList = {}
- list2 = {}
- for word in inputString:gmatch("%w+") do
- table.insert(input, word)
- end
- for i in pairs(input) do
- for x = os.getComputerLabel(),table.getn(list),message[2] do
- tempList = interface.findItems(list[x]["name"])
- for j in pairs(tempList) do
- temp = tempList[j].getMetadata()["displayName"]
- if (string.match(string.lower(temp),string.lower(input[i]))) then
- if (list2[list[x]["name"].."="..temp] == nil) then
- list2[list[x]["name"].."="..temp] = 0
- end
- list2[list[x]["name"].."="..temp] = list2[list[x]["name"].."="..temp] + (1/table.getn(tempList))
- end
- end
- end
- end
- maxInd = nil
- max = 0
- for y in pairs(list2) do
- if (list2[y] > max) then
- max = list2[y]
- maxInd = y
- end
- end
- a = 0
- temp = ""
- returnList = {}
- if (max > 0) then
- for y in pairs(list2) do
- if (list2[y] == max) then
- temp = ""
- a = string.find(y, "=")
- temp = interface.findItems(string.sub(y, 1, a-1))
- temp2 = string.sub(y, a+1)
- for x in pairs(temp) do
- item = temp[x].getMetadata()["displayName"]
- if (item == temp2) then
- table.insert(returnList, item.." ("..temp[x].getMetadata()["count"]..")")
- print(item.." ("..temp[x].getMetadata()["count"]..")")
- end
- end
- end
- end
- modem.transmit(3,2,returnList)
- else
- print("No items found")
- modem.transmit(3,2,{})
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement