Advertisement
Guest User

startup

a guest
Apr 18th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.16 KB | None | 0 0
  1. modem = peripheral.wrap("left")
  2. modem.open(2)
  3. interface = peripheral.wrap("front")
  4. list = interface.listAvailableItems()
  5. list2 = {}
  6. inputString = {}
  7. input = {}
  8. tempList = {}
  9.  
  10. while (1) do
  11.     a, b, c, d, message, e = os.pullEvent("modem_message")
  12.    
  13.     print("Searching...")
  14.    
  15.     inputString = message[1]
  16.     input = {}
  17.     tempList = {}
  18.     list2 = {}
  19.     for word in inputString:gmatch("%w+") do
  20.         table.insert(input, word)
  21.     end
  22.    
  23.     for i in pairs(input) do
  24.         for x = os.getComputerLabel(),table.getn(list),message[2] do
  25.             tempList = interface.findItems(list[x]["name"])
  26.             for j in pairs(tempList) do
  27.                 temp = tempList[j].getMetadata()["displayName"]
  28.                 if (string.match(string.lower(temp),string.lower(input[i]))) then
  29.                     if (list2[list[x]["name"].."="..temp] == nil) then
  30.                         list2[list[x]["name"].."="..temp] = 0
  31.                     end
  32.                     list2[list[x]["name"].."="..temp] = list2[list[x]["name"].."="..temp] + (1/table.getn(tempList))
  33.                 end
  34.             end
  35.         end
  36.     end
  37.    
  38.     maxInd = nil
  39.     max = 0
  40.    
  41.     for y in pairs(list2) do
  42.         if (list2[y] > max) then
  43.             max = list2[y]
  44.             maxInd = y
  45.         end
  46.     end
  47.    
  48.     a = 0
  49.     temp = ""
  50.     returnList = {}
  51.    
  52.     if (max > 0) then
  53.         for y in pairs(list2) do
  54.             if (list2[y] == max) then
  55.                 temp = ""
  56.                 a = string.find(y, "=")
  57.                 temp = interface.findItems(string.sub(y, 1, a-1))
  58.                 temp2 = string.sub(y, a+1)
  59.                 for x in pairs(temp) do
  60.                     item = temp[x].getMetadata()["displayName"]
  61.                     if (item == temp2) then
  62.                         table.insert(returnList, item.." ("..temp[x].getMetadata()["count"]..")")
  63.                         print(item.." ("..temp[x].getMetadata()["count"]..")")
  64.                     end
  65.                 end
  66.             end
  67.         end
  68.         modem.transmit(3,2,returnList)
  69.     else
  70.         print("No items found")
  71.         modem.transmit(3,2,{})
  72.     end
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement