Advertisement
Wassaa

oreAdd

Jan 9th, 2014
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.62 KB | None | 0 0
  1. addLoc = peripheral.wrap("top")
  2. local ores = {"15:0","14:0", "2001:0"}
  3.  
  4. if not fs.exists("/ores") then
  5.         print ("creating ores file")
  6.         local f = io.open("/ores", "w")
  7.         f:write(textutils.serialize(ores))
  8.         f:close()
  9. end
  10.  
  11. function copyToDisk()
  12.     if fs.exists("/disk") then
  13.         local f = io.open("/disk/ores", "w")
  14.         f:write(textutils.serialize(ores))
  15.         f:close()
  16.     end
  17. end
  18.  
  19. function getOresFile()
  20.     local f = io.open("/ores", "r")
  21.     local data = f:read("*l")
  22.     ores = textutils.unserialize(data)
  23.     f:close()
  24.     copyToDisk()
  25.    
  26. end
  27.  
  28. function isOre(ore)
  29.     for k,v in pairs(ores) do
  30.       if (ore == v) then
  31.         return true
  32.       end
  33.     end
  34.     return false
  35. end
  36.  
  37.  
  38. function addOre()
  39.    local rawOre = addLoc.getStackInSlot(1)
  40.     if rawOre ~= nil then
  41.         iName = rawOre["name"]
  42.         local oreAdd = tostring(rawOre["id"])..":"..tostring(rawOre["dmg"])
  43.         --list.append(ores, oreAdd)
  44.         if isOre(oreAdd) then
  45.             print(rawOre["name"].." is already in the filter")
  46.         elseif string.find(iName, "Ore") == nil and string.find(iName, "ore") == nil then
  47.             print ("this is not an Ore")
  48.         else
  49.             fs.delete("/ores")
  50.             local leng = table.getn(ores) + 1
  51.             ores[leng] = oreAdd
  52.             local f = io.open("/ores", "w")
  53.             f:write(textutils.serialize(ores))
  54.             f:close()
  55.             getOresFile()
  56.             print("Added "..iName)
  57.         end
  58.     else
  59.         print("there is nothing in the first slot of the chest")
  60.     end
  61.    
  62. end
  63. getOresFile()
  64. addOre()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement