Advertisement
serafim7

формируем список list.txt для обменника руды [OpenComputers]

Sep 11th, 2021 (edited)
1,593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.58 KB | None | 0 0
  1. -- формируем список list.txt для обменника руды by serafim
  2. -- https://i.imgur.com/hFpJm3Y.png
  3.  
  4. local com = require("component")
  5. local chest = com.isAvailable("chest") and com.chest or error("нет сундука")
  6.  
  7. local info,ore_dict,tact,index_2 = "","",true,0
  8. local file = io.open("/home/list.txt", "a")
  9. local size = chest.getInventorySize()
  10. local data = chest.getAllStacks(0)
  11.  
  12. local index_1 = 0
  13. for slot = 1,size do
  14.   if data[slot] then
  15.     index_1 = index_1 + 1
  16.   end
  17. end
  18.  
  19. for slot = 1,size do
  20.   if data[slot] then
  21.     index_2 = index_2 + 1
  22.     if tact then
  23.       local name = ""
  24.       if string.find(data[slot].id,"IC2") then
  25.         name = "IC2 "
  26.       elseif string.find(data[slot].id,"Thermal") then
  27.         name = "TE "
  28.       elseif string.find(data[slot].id,"Draconic") then
  29.         name = "DE "
  30.       end
  31.       info = '  {"2","'..name..data[slot].display_name..'","'..data[slot].id..'","'..data[slot].dmg..'","'
  32.     else
  33.       if data[slot].ore_dict then
  34.         for k, v in pairs(data[slot].ore_dict) do
  35.           ore_dict = k
  36.         end
  37.         info = info..data[slot].id..'","'..data[slot].dmg..'","'..data[slot].display_name..'","'..ore_dict
  38.       else
  39.         info = info..data[slot].id..'","'..data[slot].dmg..'","'..data[slot].display_name
  40.       end
  41.       if index_1 == index_2 then
  42.         info = info..'"}'
  43.       else
  44.         info = info..'"},'.."\n"
  45.       end
  46.       file:write(info)
  47.     end
  48.     tact = not tact
  49.   end
  50. end
  51. file:close()
  52.  
  53. --  os.execute("edit list.txt")
  54. --  os.execute("pastebin put list.txt")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement