Advertisement
montana_1

clear Inventory

Nov 2nd, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.02 KB | None | 0 0
  1. function split(inputstr, sep)
  2.     if(inputstr == nil or inputstr == "") then
  3.                 return nil
  4.         end
  5.         if sep == nil then
  6.                 sep = ","
  7.         end
  8.         local t={} ; i=1
  9.         for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  10.                 t[i] = str
  11.                 i = i + 1
  12.         end
  13.         return t
  14. end
  15.  
  16. function clrInv(table)
  17.     for i = 1, 16 do -- loop through the slots
  18.         turtle.select(i)
  19.         local x = turtle.getItemDetail(i)
  20.         if(x ~= nil) then
  21.             local istr = string.sub(x.name,string.find(x.name,":",0)+1)
  22.             for key,value in pairs(table) do
  23.                 if(istr == value[1] and value[4] == "1") then
  24.                     turtle.drop()
  25.                 end
  26.             end
  27.         end
  28.     end
  29.     turtle.select(1)
  30. end
  31.  
  32.  
  33. if(fs.exists("listed")) then
  34.     ifile = fs.open("listed","r")
  35.     xlist = {}
  36.     x = split(ifile.readLine(),',')
  37.     while(x ~= nil and x ~= "") do
  38.         table.insert(xlist, x)
  39.         x = split(ifile.readLine(),',')
  40.     end
  41. else
  42.     print("Listed file does not exist, cannot clear inventory")
  43. end
  44.  
  45. clrInv(xlist)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement