Advertisement
cc-editor

lager-sub

Mar 19th, 2022 (edited)
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.93 KB | None | 0 0
  1. function Settings()
  2.     term.clear()
  3.     term.setCursorPos(1,1)
  4.     term.write("Setup-Modus für Fachtechniker")
  5.     local pin = "----"
  6.     repeat
  7.         term.setCursorPos(1,2)
  8.         term.write("Bitte Fachtechniker-PIN eingeben:")
  9.         term.setCursorPos(1,3)
  10.         term.write("(zum Verlassen ENTER drücken)")
  11.         term.setCursorPos(1,4)
  12.         pin = io.read()
  13.         if pin == "" then
  14.             return false
  15.         elseif pin ~= "0000" then
  16.             term.setCursorPos(1,4)
  17.             term.clearLine()
  18.             term.setCursorPos(1,1)
  19.             term.clearLine()
  20.             term.write("FALSCHER PIN")
  21.         end
  22.     until (pin == "0000")
  23.    
  24.     local connectors = {}
  25.     local okKey
  26.     local id
  27.     local color
  28.    
  29.     repeat
  30.         id, color = selectionMenu.selectionMenu("Farbe für Silo1 auswählen", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
  31.         connectors["silo1"] = color
  32.         id, color = selectionMenu.selectionMenu("Farbe für Silo2 auswählen", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
  33.         connectors["silo2"] = color
  34.         id, color = selectionMenu.selectionMenu("Farbe für Silo3 wählen", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
  35.         connectors["silo3"] = color
  36.         id, color = selectionMenu.selectionMenu("Farbe für Silo4 unten wählen", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
  37.         connectors["silo4"] = color
  38.         id, color = selectionMenu.selectionMenu("Farbe für Silo5 wählen", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
  39.         connectors["silo5"] = color
  40.         id, color = selectionMenu.selectionMenu("Farbe für Silo6 wählen", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
  41.         connectors["silo6"] = color
  42.         id, color = selectionMenu.selectionMenu("Farbe für Silo7 wählen", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
  43.         connectors["silo7"] = color
  44.         id, color = selectionMenu.selectionMenu("Farbe für Silo8 wählen", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
  45.         connectors["silo8"] = color
  46.         id, color = selectionMenu.selectionMenu("Farbe für Silo9 wählen", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
  47.         connectors["silo9"] = color
  48.         id, color = selectionMenu.selectionMenu("Farbe für Silo10 wählen", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
  49.         connectors["silo10"] = color
  50.         id, color = selectionMenu.selectionMenu("Seite für Kabel wählen", "left", "right", "top", "bottom", "front", "back")
  51.         connectors["kabel"] = color
  52.         id, color = selectionMenu.selectionMenu("Seite für Kiste wählen", "left", "right", "top", "bottom", "front", "back")
  53.         connectors["kiste"] = color
  54.         id, color = selectionMenu.selectionMenu("Seite für Modem wählen", "left", "right", "top", "bottom", "front", "back")
  55.         connectors["modem"] = color
  56.        
  57.         term.clear()
  58.         term.setCursorPos(1,1)
  59.         term.setTextColor(connectors["silo1"])
  60.         print("Silo 1")
  61.         term.setTextColor(connectors["silo2"])
  62.         print("Silo 2")
  63.         term.setTextColor(connectors["silo3"])
  64.         print("Silo 3")
  65.         term.setTextColor(connectors["silo4"])
  66.         print("Silo 4")
  67.         term.setTextColor(connectors["silo5"])
  68.         print("Silo 5")
  69.         term.setTextColor(connectors["silo6"])
  70.         print("Silo 6")
  71.         term.setTextColor(connectors["silo7"])
  72.         print("Silo 7")
  73.         term.setTextColor(connectors["silo8"])
  74.         print("Silo 8")
  75.         term.setTextColor(connectors["silo9"])
  76.         print("Silo 9")
  77.         term.setTextColor(connectors["silo10"])
  78.         print("Silo 10")
  79.        
  80.         term.setTextColor(colors.white)
  81.         print("Kabel: " .. connectors["kabel"])
  82.         print("Kiste: " .. connectors["kiste"])
  83.         print("Modem: " .. connectors["modem"])
  84.         print()
  85.         print("Auswahl OK ? (j/n)")
  86.         okKey = io.read()  
  87.     until(okKey == "j")
  88.    
  89.     local file = fs.open("/lager/redstone/connectors","w")
  90.     file.write(textutils.serialize(connectors))
  91.     file.close()
  92.    
  93.     return true
  94. end
  95.  
  96. function checkChest()
  97.     print("Kiste wird überwacht")
  98.     local kiste = peripheral.wrap(Connectors["kiste"])
  99.    
  100.     while true do
  101.         item = kiste.getItemDetail(1)
  102.         if item ~= nil then
  103.             print(item["displayName"] .. " - Lager voll")
  104.             print("Rückführung in Zug")
  105.             rednet.send(0, item["displayName"], "lager_voll")      
  106.             redstone.setBundledOutput(Connectors["kabel"], bander)         
  107.         end
  108.     end
  109. end
  110.  
  111. function checkRednet()
  112.     print("Rednet wird überwacht")
  113.  
  114.     while true do
  115.         local event = {os.pullEvent("rednet_message")}
  116.        
  117.         if event[4] == "beladen" then
  118.             print("Beladen aus " .. event[3])
  119.             redstone.setBundledOutput(Connectors["kabel"], (bander - Connectors[event[3]]))
  120.            
  121.             rednet.receive("lager_ok", 400)
  122.             redstone.setBundledOutput(Connectors["kabel"], 0)
  123.             print("Beladen beendet")
  124.         elseif event[4] == "block" then
  125.             print("Blockiere Fließbänder")
  126.             redstone.setBundledOutput(Connectors["kabel"], bander)
  127.            
  128.             rednet.receive("lager_ok", 400)
  129.             redstone.setBundledOutput(Connectors["kabel"], 0)
  130.             print("Blockieren beendet")
  131.         elseif event[4] == "entladen_ok" then
  132.             redstone.setBundledOutput(Connectors["kabel"], 0)
  133.             print("Lager wieder bereit")
  134.         end
  135.     end
  136. end
  137.  
  138. os.loadAPI("selectionMenu")
  139. if not fs.exists("/lager/redstone/connectors") then
  140.     if not Settings() then
  141.         term.clear()
  142.         return
  143.     end
  144. end
  145.  
  146. local file = fs.open("/lager/redstone/connectors","r")
  147. Connectors = textutils.unserialize(file.readAll())
  148. file.close()
  149.  
  150. term.clear()
  151. print("Lager bereit")
  152.  
  153. rednet.open(Connectors["modem"])
  154. bander = Connectors["silo1"] + Connectors["silo2"] + Connectors["silo3"] + Connectors["silo4"] + Connectors["silo5"] + Connectors["silo6"] + Connectors["silo7"] + Connectors["silo8"] + Connectors["silo9"] + Connectors["silo10"]
  155.  
  156. parallel.waitForAny(checkChest, checkRednet)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement