Advertisement
BlueMond

glassFind

Jan 29th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.15 KB | None | 0 0
  1. local storage = peripheral.wrap("right")
  2. local glass = peripheral.wrap("left")
  3.  
  4. --not mine
  5. function mysplit(inputstr, sep)
  6.         if sep == nil then
  7.                 sep = "%s"
  8.         end
  9.         local t={} ; i=1
  10.         for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  11.                 t[i] = str
  12.                 i = i + 1
  13.         end
  14.         return t
  15. end
  16.  
  17.  
  18.  
  19. function find(search)
  20.     local all = storage.getAvailableItems()
  21.     local count = 10
  22.     glass.clear()
  23.    
  24.     for num, item in pairs(all) do
  25.         local fing = item.fingerprint
  26.         local num = item.size
  27.         local id = fing.id
  28.        
  29.         local idTable = mysplit(id, ":")
  30.         local sTable = mysplit(search, ":")
  31.    
  32.         if sTable[1] == "all" then
  33.             if string.find(idTable[2], sTable[2]) then
  34.                 glass.addText(1, count, idTable[2]..": "..num)
  35.                 count = count + 10
  36.             end
  37.         else
  38.             if string.find(idTable[1], sTable[1]) and string.find(idTable[2], sTable[2]) then
  39.                 glass.addText(1, count, idTable[2]..": "..num)
  40.                 count = count + 10
  41.             end
  42.         end
  43.     end
  44.    
  45.     glass.sync()
  46. end
  47.  
  48. while true do
  49.     local event, player, side, command = os.pullEvent("glasses_chat_command")
  50.    
  51.     find(command)
  52. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement