Advertisement
MagmaLP

me auslesen alle 2 sekunden

Nov 25th, 2023 (edited)
682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function ClearPages()
  2.     sleep(0.5)
  3.     redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"), colors.black))
  4.     sleep(0.5)
  5.     redstone.setBundledOutput("back",colors.subtract(redstone.getBundledOutput("back"), colors.black))
  6.     sleep(2)
  7. end
  8.  
  9. function ResetSignals()
  10.     sleep(0.5)
  11.     redstone.setBundledOutput("back",colors.subtract(redstone.getBundledOutput("back"), colors.orange))
  12.     sleep(0.5)
  13.     redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"), colors.blue))
  14. end
  15.    
  16. function RequestItems()
  17.     -- CONSTANTS
  18.     local PIPE_SIDE = "right"
  19.  
  20.     -- IMPLEMENTATION
  21.     function convertNBT(nbt)
  22.         local conv = {}
  23.         if (nbt == nil) then
  24.             return nil
  25.         elseif (nbt["type"] == "NBTTagCompound") or (nbt["type"] == "NBTTagList") then
  26.             for key, value in pairs(nbt["value"]) do
  27.                 conv[key] = convertNBT(value)
  28.             end
  29.         else
  30.             conv = nbt["value"]
  31.         end
  32.         return conv
  33.     end
  34.  
  35.     function getItems(pipe)
  36.         pipe.getAvailableItems()
  37.         local event, result = os.pullEvent("available_items_return")
  38.         return result
  39.     end
  40.  
  41.     function inList(item)
  42.         local id = item.id
  43.         local dmg = item.dmg
  44.         local idKey = tostring(id)
  45.         local exists, requestAmount = false, 0
  46.  
  47.         if REQUEST_IDS[id] then
  48.             if type(REQUEST_IDS[id]) == "table" then
  49.                 local variantKey = idKey .. ":" .. tostring(dmg)
  50.                 if REQUEST_IDS[id][variantKey] then
  51.                     exists = true
  52.                     requestAmount = REQUEST_IDS[id][variantKey]
  53.                 end
  54.             else
  55.                 exists = true
  56.                 requestAmount = REQUEST_IDS[id]
  57.             end
  58.         end
  59.  
  60.         return exists, requestAmount
  61.     end
  62.  
  63.     -- MAIN
  64.     local pipe = peripheral.wrap(PIPE_SIDE)
  65.     for i, result in pairs(getItems(pipe)) do
  66.         local iid, amount = unpack(result)
  67.         local item = {
  68.             id = pipe.getItemID(iid),
  69.             dmg = pipe.getItemDamage(iid),
  70.             nbt = convertNBT(pipe.getNBTTagCompound(iid))
  71.         }
  72.         local exists, requestAmount = inList(item)
  73.         if exists then
  74.             pipe.makeRequest(iid, requestAmount)
  75.             sleep(sle)
  76.         end
  77.     end
  78. end
  79.  
  80. ---------------------------------------------------------
  81. function RequestPage1()
  82.     REQUEST_IDS = {
  83.         [900] = {      
  84.             ["900:2"] = 16,         --16x Controller
  85.             ["900:6"] = 16,         --16x Access Terminal
  86.             ["900:5"] = 16,         --16x Wireless Access Point
  87.             ["900:7"] = 16,         --16x ME Chest
  88.             ["900:8"] = 16,         --16x Interface
  89.             ["900:1"] = 16,         --16x Pattern Provider
  90.         },
  91.     }
  92.     RequestItems()  
  93.     sleep(0.2)
  94.     REQUEST_IDS = {
  95.         [901] = {  
  96.             ["901:3"] = 16,         --16x Crafting Terminal
  97.             ["901:12"] = 16,        --16x Storage Monitor
  98.             ["901:11"] = 16,        --16x Crafting Monitor
  99.             ["901:10"] = 16,        --16x IO Port
  100.             ["901:6"] = 16,         --16x Heat Vent
  101.             ["901:7"] = 16,         --16x Containment Wall
  102.             ["901:5"] = 16,         --16x Crafting CPU
  103.             ["901:4"] = 16,         --16x Level Emitter
  104.             ["901:9"] = 16,         --16x Storage Bus
  105.             ["901:1"] = 16,         --16x Import Bus
  106.             ["901:0"] = 16,         --16x Export Bus
  107.             ["901:13"] = 16,        --16x ME Cable
  108.         },
  109.     }
  110.     RequestItems()
  111.     sleep(0.2)
  112.     REQUEST_IDS = {
  113.         [900] = {  
  114.             ["900:0"] = 64,         --64x ME Cable Blau
  115.             ["900:10"] = 64,        --64x ME Cable Schwarz
  116.             ["900:11"] = 64,        --64x ME Cable Weis
  117.             ["900:12"] = 64,        --64x ME Cable Braun
  118.             ["900:13"] = 64,        --64x ME Cable Rot
  119.             ["900:14"] = 64,        --64x ME Cable Gelb
  120.             ["900:15"] = 64,        --64x ME Cable GråBCn
  121.         },
  122.     }
  123.     RequestItems()
  124. end
  125. ---------------------------------------------------------
  126. function RequestPage2()
  127.     REQUEST_IDS = {
  128.         [246] = {  
  129.             ["246:3"] = 60,         --60x Solar Panel
  130.         },
  131.     }
  132.     RequestItems()
  133.     REQUEST_IDS = {
  134.         [183] = {
  135.             ["183:0"] = 60,         --60x LV Solar Panel
  136.             ["183:1"] = 60,         --60x MV Solar Panel
  137.             ["183:2"] = 60,         --60x HV Solar Panel
  138.         },
  139.     }
  140.     RequestItems()
  141.     sleep(0.2)
  142.     REQUEST_IDS = {
  143.         [750] = {
  144.             ["750:1280"] = 60,      --60x Blue Alloy Wire
  145.             ["750:1281"] = 60,      --60x 10kV Wire
  146.             ["750:16913"] = 60,     --60x Jacketed Bluewire
  147.         },
  148.     }
  149.     RequestItems()
  150.     sleep(0.2)
  151.     REQUEST_IDS = {
  152.         [2050] = {  
  153.             ["2050:14"] = 32,       --32x Lead Wire
  154.             ["2050:15"] = 32,       --32x Furnace Heater
  155.         },
  156.     }
  157.     RequestItems()
  158.     sleep(0.2)
  159.     REQUEST_IDS = {
  160.         [30184] = {
  161.             ["30184:0"] = 60,       --60x Copper Cable
  162.             ["30184:4"] = 60,       --60x 2x Ins. Gold Cable
  163.             ["30184:9"] = 60,       --60x Glass Fibre Cable
  164.         },
  165.     }
  166.     RequestItems()
  167.     REQUEST_IDS = {
  168.         [227] = {  
  169.             ["227:0"] = 10,         --10x Bat Box
  170.             ["227:1"] = 10,         --10x MFE
  171.             ["227:2"] = 10,         --10x MFSU
  172.             ["227:3"] = 10,         --10x LV Transformer
  173.             ["227:4"] = 10,         --10x MV Transformer
  174.             ["227:5d"] = 10,        --10x HV Transformer
  175.         },
  176.     }
  177.     RequestItems()
  178.     sleep(0.2)
  179.     REQUEST_IDS = {
  180.         [2006] = {  ["2006:0"] = 32  },     --32x Redstone Energy Conduit  
  181.         [4320] = {  ["4320:0"] = 32  },     --32x Wooden Conductice Pipe
  182.         [4324] = {  ["4324:0"] = 32  },     --32x Golden Conductice Pipe
  183.     }
  184.     RequestItems()
  185. end
  186. ---------------------------------------------------------
  187. function RequestPage3()
  188.     REQUEST_IDS = {
  189.         [207] = {  
  190.             ["207:0"] = 5,          --5x Computer
  191.             ["207:16384"] = 5,      --5x Adv. Computer
  192.         },
  193.     }
  194.     RequestItems()
  195.     REQUEST_IDS = {
  196.         [209] = {   ["209:0"] = 5  },           --5x Turtle
  197.         [900] = {   ["900:5"] = 5  },           --5x Wireless Access Point
  198.         [3893] = {  ["3893:0"] = 5  },          --5x Sensor Peripheral
  199.         [750] = {   ["750:256"] = 5  },         --5x Red Alloy Wire
  200.     }
  201.     RequestItems()
  202.     sleep(0.2)
  203.     REQUEST_IDS = {
  204.         [7742] = {
  205.             ["7742:17"] = 2,          --2x Proximity Sensor Card Mk1
  206.             ["7742:33"] = 2,          --2x Proximity Sensor Card Mk2
  207.             ["7742:49"] = 2,          --2x Proximity Sensor Card Mk3
  208.             ["7742:65"] = 2,          --2x Proximity Sensor Card Mk4
  209.             ["7742:83"] = 2,          --2x Applied Energystics Sensor Card Mk1
  210.             ["7742:99"] = 2,          --2x Applied Energystics Sensor Card Mk2
  211.             ["7742:151"] = 2,         --2x Applied Energystics Sensor Card Mk3
  212.             ["7742:131"] = 2,         --2x Applied Energystics Sensor Card Mk4
  213.         },
  214.     }
  215.     RequestItems()
  216. end
  217. ---------------------------------------------------------
  218. function RequestPage4()
  219.     sle = 0.2
  220.     REQUEST_IDS = {
  221.         [1] = {     ["1:0"] = 192       },          --
  222.         [2] = {     ["2:0"] = 192       },          --
  223.         [3] = {     ["3:0"] = 192       },          --
  224.         [13] = {    ["13:0"] = 64       },          --
  225.         [9] = {     ["9:0"] = 64        },          --
  226.         [11] = {    ["11:0"] = 64       },          --
  227.         [17] = {    ["17:0"] = 64       },          --
  228.        
  229.         [24] = {    ["24:0"] = 64       },          --
  230.         [24] = {    ["24:1"] = 64       },          --
  231.        
  232.         [128] = {   ["128:0"] = 64      },          --      
  233.         [89] = {    ["89:0"] = 64       },          --
  234.         [85] = {    ["85:0"] = 64       },          --      
  235.         [3133] = {  ["3133:4"] = 192    },          --
  236.         [45] = {    ["45:0"] = 64       },          --
  237.         [20] = {    ["20:0"] = 64       },          --
  238.         [80] = {    ["80:0"] = 128      },          --
  239.        
  240.         [98] = {    ["98:0"] = 128      },          --
  241.         [98] = {    ["98:3"] = 64       },          --
  242.        
  243.         [44] = {    ["44:0"] = 64       },          --
  244.         [44] = {    ["44:1"] = 64       },          --
  245.        
  246.         [43] = {    ["43:0"] = 64       },          --
  247.         [43] = {    ["43:7"] = 64       },          --
  248.         }
  249.         RequestItems()
  250.         REQUEST_IDS = {
  251.         [255] = {   ["255:0"] = 64      },          --
  252.         }
  253.         RequestItems()
  254.         REQUEST_IDS = {
  255.         [255] = {   ["255:1"] = 64      },          --
  256.         }
  257.         RequestItems()
  258.         REQUEST_IDS = {
  259.         [255] = {   ["255:2"] = 64      },          --
  260.         }
  261.         RequestItems()
  262.         REQUEST_IDS = {
  263.         [255] = {   ["255:6"] = 64      },          --  
  264.     }
  265.     RequestItems()
  266.     sleep(1)
  267. end
  268. ---------------------------------------------------------
  269. function RequestPage5()
  270.  
  271. end
  272. function RequestPage6()
  273.  
  274. end
  275. function RequestPage7()
  276.  
  277. end
  278. function RequestPage8()
  279.  
  280. end
  281. function RequestPage9()
  282.  
  283. end
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291. ------------------------Program Start------------------------
  292.  
  293. sle = 0.1 --Sleep zwischen jeder Request
  294. os.loadAPI("ocs/apis/sensor")
  295. sen = sensor.wrap("bottom")
  296. redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"), colors.orange))  --orange an
  297. sleep(0.5)
  298. redstone.setBundledOutput("back",colors.subtract(redstone.getBundledOutput("back"), colors.blue))   --blau aus
  299.  
  300. while true do
  301.     s = sen.getTargets()
  302.     function getS()
  303.         for v, k  in pairs(s) do
  304.             if k.Name == "ME Wireless Access Point" then  
  305.                 target = v
  306.             end
  307.         end
  308.         return target
  309.     end
  310.  
  311.     f = getS()
  312.     s1 = sen.getTargetDetails(target)
  313.    
  314.     local Page1 = 0
  315.     local Page2 = 0
  316.     local Page3 = 0
  317.     local Page4 = 0
  318.     local Page5 = 0
  319.     local Page6 = 0
  320.     local Page7 = 0
  321.     local Page8 = 0
  322.     local Page9 = 0
  323.  
  324.     for _, item in pairs(s1.Items) do
  325.         --print(item.Name)
  326.         --sleep(2)
  327.         if item.Name == "ME Wireless Access Terminal" then
  328.             Page1 = item.Size -- Werte ermittels und setzen
  329.         end
  330.         if item.Name == "Advanced Solar Panel" then
  331.             Page2 = item.Size -- Werte ermittels und setzen
  332.         end
  333.         if item.Name == "Remote Orderer" then
  334.             Page3 = item.Size -- Werte ermittels und setzen
  335.         end
  336.         if item.Name == "Cobblestone" then
  337.             Page4 = item.Size -- Werte ermittels und setzen
  338.         end
  339.         if item.Name == "tile.machineBlock" then
  340.             Page5 = item.Size -- Werte ermittels und setzen
  341.         end
  342.         if item.Name == "item.PipeItemsDiamond" then
  343.             Page6 = item.Size -- Werte ermittels und setzen
  344.         end
  345.         if item.Name == "Electric Furnace" then
  346.             Page7 = item.Size -- Werte ermittels und setzen
  347.         end
  348.         if item.Name == "Clay Dust" then
  349.             Page8 = item.Size -- Werte ermittels und setzen
  350.         end
  351.         if item.Name == "Wooden Axe" then
  352.             Page9 = item.Size -- Werte ermittels und setzen
  353.         end
  354.         if item.Size < 0 then
  355.             os.reboot()
  356.         end
  357.     end
  358.    
  359.     term.setCursorPos(1,1)
  360.     term.clear()
  361.     print("1: "..Page1)
  362.     print("2: "..Page2)
  363.     print("3: "..Page3)
  364.     print("4: "..Page4)
  365.     print("5: "..Page5)
  366.     print("6: "..Page6)
  367.     print("7: "..Page7)
  368.     print("8: "..Page8)
  369.     print("9: "..Page9)
  370.    
  371.     reboot = 1
  372.     if Page1 < 1 or Page2 < 1 or Page3 < 1 or Page4 < 1 then
  373.         ResetSignals()
  374.         ClearPages()
  375.         reboot = 0
  376.     end
  377.    
  378.     if Page1 < 1 then
  379.         RequestPage1()
  380.     elseif Page2 < 1 then
  381.         RequestPage2()
  382.     elseif Page3 < 1 then
  383.         RequestPage3()
  384.     elseif Page4 < 1 then
  385.         RequestPage4()
  386.     end
  387.    
  388.     if reboot == 0 then
  389.         os.reboot()
  390.     end
  391.     sleep(1)
  392. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement