Advertisement
mrWhiskasss

test obvmen rud

Aug 12th, 2023 (edited)
2,718
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[обменник руды by serafim  pastebin.com/jaYhuD0k  update 04.10.21
  2.  
  3. пример сборки:
  4. https://i.imgur.com/bnqCk5a.png
  5. https://i.imgur.com/3SphwaG.png
  6.  
  7. требования:
  8. пк второго уровня (золотой)
  9. видеокарта второго уровня
  10. адаптер 2 штуки
  11. база данных первого уровня
  12. МЕ интерфейс
  13. сундук
  14.  
  15. --]]
  16.  
  17. local items = { -- множитель, название руды, забираем руду, dmg, отдаём слиток, dmg, название слитка, ore_dictionary
  18.     {"50","ИРИДИЙ","minecraft:iron_block","0","IC2:item.itemOreIridium" ,"0","ЖЕЛЕЗ. БЛОК" ,"Iron Ingot"},
  19.     {"8","НЕСТАБ.СЛИТ","Forestry:resourceStorage","1","ExtraUtilities:unstableingot","2","МЕДН. БЛОК" ,"Iron Ingot"}
  20.  
  21. }
  22.  
  23. local unicode = require("unicode")
  24. local com = require("component")
  25. local interface = com.isAvailable("me_interface") and com.me_interface or error("нет ме интерфейса")
  26. local db = com.isAvailable("database") and com.database or error("нет базы данных")
  27. local chest = com.isAvailable("crystal") and com.crystal or error("нет сундука crystal")
  28. local size = chest.getInventorySize()
  29. local gpu = com.gpu
  30. local w, h = gpu.getResolution()
  31. local net_count,line_count = 0,0
  32.  
  33. local function declension(number)
  34.     local dec = ""
  35.     local rest = number % 10
  36.     local str = string.sub(number,string.len(number)-1)
  37.     if str == "11" or str == "12" or str == "13" or str == "14" then
  38.         dec = " товаров"
  39.     elseif rest == 1 then
  40.         dec = " слиток"
  41.     elseif rest == 2 or rest == 3 or rest == 4 then
  42.         dec = " слитка"
  43.     else
  44.         dec = " товаров"
  45.     end
  46.     return number..dec
  47. end
  48.  
  49. local function center(coord,text,color)
  50.     gpu.setForeground(color)
  51.     gpu.set(math.floor(w/2-unicode.len(text)/2),coord,text)
  52. end
  53.  
  54. local function color_text(w,line,text,color)
  55.     gpu.setForeground(color)
  56.     gpu.set(w,line,text)
  57. end
  58.  
  59. local function print_items()
  60.     local line,size,fill = 3,0,true
  61.     local network = interface.getItemsInNetwork()
  62.     for ind = 1,#items do
  63.         for net = 1,#network do
  64.             if network[net].name == items[ind][5] then
  65.                 if network[net].damage == tonumber(items[ind][6]) then
  66.                     if network[net].size >= tonumber(items[ind][1]) then
  67.                         if #network ~= net_count then
  68.                             if fill then
  69.                                 gpu.fill(1,1,w,h," ")
  70.                                 fill = not fill
  71.                             end
  72.                             color_text(5,line,items[ind][2],0x00FF00)
  73.                             color_text(28,line,"1",0xFF00FF)
  74.                             color_text(30,line,"-->",0xFFFF00)
  75.                             color_text(34,line,"X "..items[ind][1],0xFF00FF)
  76.                             color_text(42,line,items[ind][7],0x00FF00)
  77.                             color_text(63,line,"доступно",0xFFFF00)
  78.                             color_text(73,line,tostring(network[net].size),0xFF00FF)
  79.                             color_text(3,line+1,string.rep("─",76),0xFFFFFF)
  80.                             size = size + network[net].size
  81.                         else
  82.                             size = size + network[net].size
  83.                             color_text(73,line,tostring(network[net].size.."   "),0xFF00FF)
  84.                         end
  85.                         line = line + 2
  86.                     end
  87.                 end
  88.             end
  89.         end
  90.     end
  91.     net_count = #network
  92.     if line == 3 or line ~= line_count then
  93.         net_count = 0
  94.     end
  95.     line_count = line
  96.     gpu.fill(1,1,w,1," ")
  97.     if size > 0 then
  98.         color_text(1,1,"    обменник за Блоки, кладите в 1 слот в сундуке, всего есть - "..declension(size),0xFFFF00)
  99.     else
  100.         gpu.fill(1,1,w,h," ")
  101.         center(h/2,"обменник  пуст",0xFF0000)
  102.     end
  103. end
  104.  
  105. local function pushItem(name,count,label)
  106.     db.clear(1)
  107.     interface.store(name,db.address,1)
  108.     interface.setInterfaceConfiguration(1,db.address,1,64)
  109.     local drop = 0
  110.     while true do
  111.         if drop == count then
  112.             interface.setInterfaceConfiguration(1,db.address,1,0)
  113.             net_count = 0
  114.             break
  115.         else
  116.             local dropcount = interface.pushItem("UP",1,count-drop)
  117.             drop = drop + dropcount
  118.             if dropcount == 0 then
  119.                 gpu.fill(1,1,w,h," ")
  120.                 center(h/2,"освободите место в сундуке",0xFF0000)
  121.                 center(h/2+2,"Ожидаю выдать "..label,0xFFFFFF)
  122.                 center(h/2+4,"всего "..count-drop,0xFFFFFF)
  123.                 os.sleep(1)
  124.             end
  125.         end
  126.     end
  127. end
  128.  
  129. local function exchange_ore_dict()
  130.     local ore_dict,item_count = "",false
  131.     local data = chest.getAllStacks(0)
  132.     for slot = 1,1 do
  133.         if data[slot] then
  134.             for ind = 1,#items do
  135.                 if data[slot].id == items[ind][3] then
  136.                     if data[slot].dmg == tonumber(items[ind][4]) then
  137.                         ore_dict = items[ind][8]
  138.                         break
  139.                     end
  140.                 end
  141.             end
  142.             local network = interface.getItemsInNetwork()
  143.             for ind2 = 1,#items do
  144.                 if ore_dict == items[ind2][8] then
  145.                     local ore = items[ind2][5]
  146.                     local dmg = items[ind2][6]
  147.                     local ore_name = items[ind2][2]
  148.                     for net = 1,#network do
  149.                         if network[net].name == ore then
  150.                             if network[net].damage == tonumber(dmg) then
  151.                                 if network[net].size >= tonumber(items[ind2][1]) then
  152.                                     if chest.getStackInSlot(1).qty >= tonumber(items[ind2][1]) and items[ind2][3] ==chest.getStackInSlot(1).id then
  153.                                         item_count = chest.pushItem("DOWN",1,items[ind2][1])
  154.                                         local drop_count = 1
  155.                                         local ingot_name = items[ind2][7]
  156.                                         gpu.fill(1,1,w,1," ")
  157.                                         center(1,"Меняю  "..item_count.."  "..ore_name.."  на  "..drop_count.."  "..ingot_name,0xFFFFFF)
  158.                                         pushItem({name = ore,damage = tonumber(dmg)},drop_count,ingot_name)
  159.                                         break
  160.                                     end
  161.                                 end
  162.                             end
  163.                         end
  164.                     end
  165.                 end
  166.             end
  167.             if item_count then
  168.                 item_count = false
  169.                 ore_dict = ""
  170.                 break
  171.             end
  172.         end
  173.     end
  174. end
  175.  
  176. gpu.fill(1,1,w,h," ")
  177. gpu.setResolution(80,h)
  178. while true do
  179.     print_items()
  180.     exchange_ore_dict()
  181.     os.sleep(5.4)
  182. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement