Advertisement
moomoomoo309

getInfo

Jan 25th, 2015
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.47 KB | None | 0 0
  1. filePath="Info"
  2.  
  3. local function removeAll(str,char)
  4.   if #char~=1 then
  5.     return nil
  6.   end
  7.   for i=1,#str do
  8.     if string.sub(str,i,i)==char then
  9.       str=string.sub(str,1,i-1)..string.sub(str,i+1)
  10.     end
  11.   end
  12.   return str
  13. end
  14.  
  15. local function findPeripheral(type)
  16.   local Peripherals=peripheral.getNames()
  17.   wildcardBeginning=string.sub(type,1,1)=="*"
  18.   wildcardEnd=string.sub(type,#type)=="*"
  19.   for i=1,#Peripherals do
  20.     index1,index2=string.find(peripheral.getType(Peripherals[i]),removeAll(type,"*"))
  21.     if wildcardBeginning and wildcardEnd and index1 then
  22.       return Peripherals[i]
  23.     elseif wildcardBeginning then
  24.       if index2==#peripheral.getType(Peripherals[i]) then
  25.         return Peripherals[i]
  26.       end
  27.     elseif wildcardEnd then
  28.       if index1==1 then
  29.         return Peripherals[i]
  30.       end
  31.     elseif peripheral.getType(Peripherals[i])==type then
  32.       return Peripherals[i]
  33.     end
  34.   end
  35. end
  36.  
  37. local Items=peripheral.call(findPeripheral("LogisticsPipes*"),"getAvailableItems")
  38. f=fs.open(filePath,"w")
  39. for k,v in pairs(Items) do
  40.   id=v.getValue1()
  41.   f.write("ID: "..id.getId().."\n")
  42.   f.write("Unlocalized Name: "..id.getName().."\n")
  43.   f.write("Mod Name: "..id.getModName().."\n")
  44.   f.write("Meta: "..id.getData().."/"..id.getUndamaged().getData().."\n")
  45.   f.write("Count: "..m.getItemAmount(id).."\n\n")
  46. end
  47. f.close()  
  48. --[[
  49. Sample Output:
  50. ID: 542
  51. Unlocalized Name: Copper Ore
  52. Mod Name: IC2
  53. Meta: 0/0
  54. Count: 50251
  55. ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement