Advertisement
Guest User

startup

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