Advertisement
AdslHouba

Contrôle de multiple pièges parallèle

Jul 26th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.66 KB | None | 0 0
  1. os.loadAPI("ahb")
  2.  
  3. liste={
  4.     {
  5.         nom="fan bleu",
  6.         defaut=false,
  7.         bouton=colors.lightGray,
  8.         red=ahb.addPeripheral("hb_interupteur_11"),
  9.         dure=40,
  10.         delay=80,
  11.         curs=0,
  12.         actif=false,
  13.         spam=false
  14.     },
  15.     {
  16.         nom="piston bleu",
  17.         defaut=false,
  18.         bouton=colors.cyan,
  19.         red=ahb.addPeripheral("hb_interupteur_13"),
  20.         dure=40,
  21.         delay=80,
  22.         curs=0,
  23.         actif=false,
  24.         spam=true,
  25.         spamVar=9
  26.     },
  27.     {
  28.         nom="tapis bleu",
  29.         defaut=true,
  30.         bouton=colors.purple,
  31.         red=ahb.addPeripheral("hb_interupteur_9"),
  32.         dure=40,
  33.         delay=80,
  34.         curs=0,
  35.         actif=false,       
  36.         spam=false
  37.     },
  38.     {
  39.         nom="porte 1 bleu",
  40.         defaut=false,
  41.         bouton=colors.blue,
  42.         red=ahb.addPeripheral("hb_interupteur_19"),
  43.         dure=40,
  44.         delay=80,
  45.         curs=0,
  46.         actif=false,       
  47.         spam=false
  48.     },
  49.     {
  50.         nom="porte 2 bleu",
  51.         defaut=false,
  52.         bouton=colors.brown,
  53.         red=ahb.addPeripheral("hb_interupteur_17"),
  54.         dure=40,
  55.         delay=80,
  56.         curs=0,
  57.         actif=false,       
  58.         spam=false
  59.     },
  60.     {
  61.         nom="neige bleu",
  62.         defaut=false,
  63.         bouton=colors.green,
  64.         red=ahb.addPeripheral("hb_interupteur_15"),
  65.         dure=40,
  66.         delay=80,
  67.         curs=0,
  68.         actif=false,       
  69.         spam=true,
  70.         spamVar=2
  71.     },
  72.     {
  73.         nom="trappe bleu",
  74.         defaut=false,
  75.         bouton=colors.red,
  76.         red=ahb.addPeripheral("hb_interupteur_25"),
  77.         dure=10,
  78.         delay=1,
  79.         curs=0,
  80.         actif=false
  81.     },
  82.     {
  83.         nom="fan rouge",
  84.         defaut=false,
  85.         bouton=colors.gray,
  86.         red=ahb.addPeripheral("hb_interupteur_10"),
  87.         dure=40,
  88.         delay=80,
  89.         curs=0,
  90.         actif=false,
  91.         spam=false
  92.     },
  93.     {
  94.         nom="piston rouge",
  95.         defaut=false,
  96.         bouton=colors.pink,
  97.         red=ahb.addPeripheral("hb_interupteur_12"),
  98.         dure=40,
  99.         delay=80,
  100.         curs=0,
  101.         actif=false,
  102.         spam=true,
  103.         spamVar=9
  104.     },
  105.     {
  106.         nom="tapis rouge",
  107.         defaut=true,
  108.         bouton=colors.lime,
  109.         red=ahb.addPeripheral("hb_interupteur_8"),
  110.         dure=40,
  111.         delay=80,
  112.         curs=0,
  113.         actif=false,       
  114.         spam=false
  115.     },
  116.     {
  117.         nom="porte 1 rouge",
  118.         defaut=false,
  119.         bouton=colors.yellow,
  120.         red=ahb.addPeripheral("hb_interupteur_27"),
  121.         dure=40,
  122.         delay=80,
  123.         curs=0,
  124.         actif=false,       
  125.         spam=false
  126.     },
  127.     {
  128.         nom="porte 2 rouge",
  129.         defaut=false,
  130.         bouton=colors.lightBlue,
  131.         red=ahb.addPeripheral("hb_interupteur_18"),
  132.         dure=40,
  133.         delay=80,
  134.         curs=0,
  135.         actif=false,       
  136.         spam=false
  137.     },
  138.     {
  139.         nom="neige rouge",
  140.         defaut=false,
  141.         bouton=colors.magenta,
  142.         red=ahb.addPeripheral("hb_interupteur_16"),
  143.         dure=40,
  144.         delay=80,
  145.         curs=0,
  146.         actif=false,       
  147.         spam=true,
  148.         spamVar=2
  149.     },
  150.     {
  151.         nom="trappe rouge",
  152.         defaut=false,
  153.         bouton=colors.orange,
  154.         red=ahb.addPeripheral("hb_interupteur_24"),
  155.         dure=10,
  156.         delay=1,
  157.         curs=0,
  158.         actif=false,
  159.         spam=false
  160.     }
  161. }
  162. moniteur=ahb.addPeripheral("monitor_2")
  163. timerVictoire=false
  164. depart1=ahb.addPeripheral("hb_interupteur_21")
  165. depart1.pp.set(15)
  166. go=0
  167. note=ahb.addPeripheral("noteBlock_0")
  168. function routine()
  169.     for i, data in pairs(liste) do
  170.         if data.defaut then
  171.             data.red.pp.set(15)
  172.         else
  173.             data.red.pp.set(0)
  174.         end
  175.     end
  176.     while true do
  177.         for i, data in pairs(liste) do
  178.             if data.actif then
  179.                 if data.curs==0 then
  180.                     if data.defaut then
  181.                         data.red.pp.set(0)
  182.                     else
  183.                         data.red.pp.set(15)
  184.                     end
  185.                     print(data.nom..' debut activation')
  186.                 elseif data.curs<data.dure then
  187.                     if data.spam then
  188.                         if math.floor(data.curs/data.spamVar)%2==1 then
  189.                             if data.defaut then
  190.                                 data.red.pp.set(15)
  191.                             else
  192.                                 data.red.pp.set(0)
  193.                             end
  194.                         else
  195.                             if data.defaut then
  196.                                 data.red.pp.set(0)
  197.                             else
  198.                                 data.red.pp.set(15)
  199.                             end
  200.                         end
  201.                         print(data.nom..' spam')
  202.                     end
  203.                 elseif data.curs==data.dure then
  204.                     if data.defaut then
  205.                         data.red.pp.set(15)
  206.                     else
  207.                         data.red.pp.set(0)
  208.                     end
  209.                     print(data.nom..' fin activation')
  210.                 elseif data.curs==data.dure+data.delay then
  211.                     liste[i].curs=-1
  212.                     liste[i].actif=false
  213.                     print(data.nom..' fin du delay')
  214.                 end
  215.                 liste[i].curs=liste[i].curs+1
  216.             end
  217.         end
  218.         if not(go==0) then
  219.             go=go-1
  220.             if go%20==0 and go~=0 then
  221.                 note.pp.playNote(0,0)              
  222.             end
  223.             if go==0 then
  224.                 note.pp.playNote(0,15)
  225.                 depart1.pp.set(0)              
  226.                 timerVictoire=true
  227.             end
  228.         end
  229.         os.sleep(0.05)
  230.     end
  231. end
  232. function ecoute()
  233.     while true do
  234.         local event = os.pullEvent("redstone")
  235.         print("ecoute")
  236.         if redstone.getInput("left") or redstone.getInput("right") then
  237.             moniteur.pp.setBackgroundColor(colors.black)
  238.             moniteur.pp.clear()
  239.             go=20*4
  240.         end
  241.         if timerVictoire==true then
  242.             if redstone.testBundledInput("bottom",colors.white) then
  243.                 -- ROUGE GAGNE
  244.                 moniteur.pp.setBackgroundColor(colors.red)
  245.                 moniteur.pp.clear()
  246.                 moniteur.pp.setCursorPos(1,1)
  247.                 moniteur.pp.setTextScale(5)
  248.                 moniteur.pp.write("Rouge gagne")
  249.                 timerVictoire=false
  250.                 depart1.pp.set(15)
  251.             end
  252.             if redstone.testBundledInput("bottom",colors.black) then
  253.                 moniteur.pp.setBackgroundColor(colors.blue)
  254.                 moniteur.pp.clear()
  255.                 moniteur.pp.setCursorPos(1,1)
  256.                 moniteur.pp.setTextScale(5)
  257.                 moniteur.pp.write("Bleu gagne")
  258.                 timerVictoire=false
  259.                 depart1.pp.set(15)
  260.                 -- BLEU GAGNE
  261.             end
  262.             if redstone.testBundledInput("bottom",colors.white) and redstone.testBundledInput("bottom",colors.black) then
  263.                 moniteur.pp.setBackgroundColor(colors.black)
  264.                 moniteur.pp.clear()
  265.                 moniteur.pp.setCursorPos(1,1)
  266.                 moniteur.pp.setTextScale(5)
  267.                 moniteur.pp.write("Egalite")
  268.                 timerVictoire=false
  269.                 depart1.pp.set(15)
  270.             end
  271.         end
  272.         for i, data in pairs(liste) do
  273.             if redstone.testBundledInput("bottom",data.bouton) then
  274.                 print(data.nom..' bouton '..tostring(data.actif)..' '..data.curs)
  275.                 liste[i].actif=true
  276.             end
  277.         end
  278.        
  279.     end
  280. end
  281. parallel.waitForAll(routine,ecoute)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement