Advertisement
AdslHouba

Machine a source V2

Feb 8th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.69 KB | None | 0 0
  1. os.loadAPI("ahb")
  2. config=ahb.config("jeu",{
  3.     {
  4.         nom="chestInsertSortie",
  5.         info="Cote sortie du coffre caisse",
  6.         choices=true,
  7.         typ="string",
  8.         possibilities={'EAST','WEST','SOUTH','NORTH','UP','DOWN'}
  9.     },
  10.     {
  11.         nom="chestCoffreSortie",
  12.         info="Cote sortie du coffre bank",
  13.         choices=true,
  14.         typ="string",
  15.         possibilities={'EAST','WEST','SOUTH','NORTH','UP','DOWN'}
  16.     },
  17.     {
  18.         nom="cote1",
  19.         info="Cote interface 1",
  20.         choices=true,
  21.         typ="string",
  22.         possibilities={'EAST','WEST','SOUTH','NORTH','UP','DOWN'}
  23.     },
  24.     {
  25.         nom="cote2",
  26.         info="Cote interface 2",
  27.         choices=true,
  28.         typ="string",
  29.         possibilities={'EAST','WEST','SOUTH','NORTH','UP','DOWN'}
  30.     },
  31.     {
  32.         nom="cote3",
  33.         info="Cote interface 3",
  34.         choices=true,
  35.         typ="string",
  36.         possibilities={'EAST','WEST','SOUTH','NORTH','UP','DOWN'}
  37.     },
  38.     {
  39.         nom="chestLaine",
  40.         info="Coffre contenant des laines",
  41.         choices=false,
  42.         typ="string"
  43.     },
  44.     {
  45.         nom="chestCaisse",
  46.         info="Coffre contenant l'arriver des sous",
  47.         choices=false,
  48.         typ="string"
  49.     },
  50.     {
  51.         nom="chestCoffre",
  52.         info="Coffrefort",
  53.         choices=false,
  54.         typ="string"
  55.     },
  56. })
  57. chest=peripheral.wrap(config.chestLaine) -- Chest de laine
  58. chestInsert=peripheral.wrap(config.chestCaisse) -- Chest insert
  59. chestInsertSortie=config.chestInsertSortie
  60. chestCoffre=peripheral.wrap(config.chestCoffre)
  61. chestCoffreSortie=config.chestCoffreSortie
  62. chatBox=peripheral.find("chatBox")
  63.  
  64. noteBlock=peripheral.find("noteBlock")
  65. ecran=peripheral.find("monitor")
  66. arriveRedstone="bottom"
  67. credit=0
  68.  
  69. file=fs.open("gagnotte","r")
  70. gagnotte=tonumber(textutils.unserialize(file.readAll()))
  71. file.close()
  72.  
  73. statutActuelLanc=redstone.testBundledInput(arriveRedstone,colors.brown)
  74.  
  75.  
  76. cote={config.cote1,config.cote2,config.cote3}
  77. anim={
  78.     {0.05,0.05,0.05},
  79.     {0.05,0.05,0.05},
  80.     {0.1,0.05,0.05},
  81.     {0.2,0.05,0.05},
  82.     {0  ,0.2,0.1},
  83.     {0  ,0.3,0.1},
  84.     {0  ,0  ,0.2}
  85. }
  86. couleur={0,10,11,9,3,6,2,14,1,4,5,13,12,15,7,8}
  87. -- "north", "south"
  88.  
  89.  
  90.  
  91. redstone.setOutput("top", false)
  92. function envoi(choix,cote)
  93.     chest.condenseItems()
  94.     stacks=chest.getAllStacks()
  95.     table.foreach(stacks,function(i,data)
  96.         info=data.basic()
  97.         if info.dmg==couleur[choix+1] then
  98.             chest.pushItem(cote,i,1)
  99.             redstone.setOutput("top", true)
  100.             os.sleep(0.15)
  101.             redstone.setOutput("top", false)
  102.             return
  103.         end
  104.     end)
  105. end
  106. function actuEcran()
  107.     ecran.setTextColor(colors.white)
  108.     ecran.setBackgroundColor(colors.yellow)
  109.     ecran.clear()
  110.     ecran.setTextScale(2)
  111.     affichage=tostring(gagnotte);
  112.  
  113.     ecran.setCursorPos(1+math.floor((14-string.len(affichage))/2),1)
  114.     ecran.write(affichage)
  115.  
  116.     ecran.setCursorPos(3,2)
  117.     ecran.write(tostring(math.floor(credit/2))..' credits')
  118. end
  119. function ecranCredit2(t)
  120.     if t then
  121.         ecran.setTextColor(colors.white)
  122.         ecran.setBackgroundColor(colors.yellow)
  123.     else
  124.         ecran.setTextColor(colors.yellow)
  125.         ecran.setBackgroundColor(colors.white)
  126.     end
  127.     ecran.clear()
  128.     ecran.setTextScale(2)
  129.     ecran.setCursorPos(6,1)
  130.     ecran.write("GAIN")
  131.     ecran.setCursorPos(3,2)
  132.     ecran.write("+10 credits")
  133. end
  134. function ecranJackpot(t)
  135.     if t then
  136.         ecran.setTextColor(colors.white)
  137.         ecran.setBackgroundColor(colors.orange)
  138.     else
  139.         ecran.setTextColor(colors.white)
  140.         ecran.setBackgroundColor(colors.yellow)
  141.     end
  142.     ecran.clear()
  143.     ecran.setTextScale(2)
  144.     ecran.setCursorPos(3,1)
  145.     ecran.write("JACKPOT")
  146.     affichage=tostring(gagnotte);
  147.     ecran.setCursorPos(1+math.floor((14-string.len(affichage))/2),2)
  148.     ecran.write(affichage)
  149. end
  150.  
  151. actuEcran()
  152. jeuActif=false
  153. function lancement()          
  154.     tirage={math.random(#couleur),math.random(#couleur),math.random(#couleur)}
  155.     --tirage={4,2,1}
  156.  
  157.     table.foreach(anim,function(u,ligne)
  158.         table.foreach(ligne,function(o,dure)
  159.             if dure~=0 then
  160.                 os.sleep(dure)
  161.                 tirage[o]=tirage[o]+1
  162.                 if tirage[o]==#couleur then tirage[o]=0 end
  163.                 envoi(tirage[o],cote[o])          
  164.             end
  165.         end)
  166.     end)
  167.     if tirage[1]==tirage[2] and tirage[2]==tirage[3] then
  168.         if tirage[1]==4 then
  169.             ecranJackpot(true)
  170.             noteBlock.playNote(0,0)
  171.             os.sleep(0.5)
  172.            
  173.             gagnotteD=gagnotte
  174.             chestCoffre.condenseItems()
  175.             stacks=chestCoffre.getAllStacks()
  176.             table.foreach(stacks,function(i,data)
  177.                 if gagnotteD>0 then
  178.                     info=data.basic()
  179.                     if gagnotteD>info.qty then
  180.                         chestCoffre.pushItem(chestCoffreSortie,i,info.qty)
  181.                         gagnotteD=gagnotteD-info.qty
  182.                     else
  183.                         chestCoffre.pushItem(chestCoffreSortie,i,gagnotteD)
  184.                         gagnotteD=0
  185.                     end
  186.                 end
  187.             end)
  188.             for i = 1,40 do
  189.                 ecranJackpot(false)
  190.                 noteBlock.playNote(0,3)
  191.                 os.sleep(0.15)
  192.                 ecranJackpot(false)
  193.                 noteBlock.playNote(0,0)
  194.                 ecranJackpot(true)
  195.                 os.sleep(0.15)
  196.             end
  197.             file=fs.open("gagnotteGain","w")
  198.             file.write(tostring(gagnotte))
  199.             file.close()
  200.             gagnotte=100
  201.             file=fs.open("gagnotte","w")
  202.             file.write(tostring(100))
  203.             file.close()
  204.         else
  205.             ecranCredit2(true)
  206.             noteBlock.playNote(0,0)
  207.             os.sleep(0.5)
  208.             ecranCredit2(false)
  209.             noteBlock.playNote(0,1)
  210.             for i = 1,6 do
  211.                 os.sleep(0.1)
  212.                 ecranCredit2(true)
  213.                 os.sleep(0.1)
  214.                 ecranCredit2(false)
  215.             end
  216.             credit=credit+10
  217.         end
  218.     else
  219.         os.sleep(0.5)
  220.         noteBlock.playNote(4,4)
  221.         os.sleep(0.3)
  222.         noteBlock.playNote(4,2)
  223.     end
  224.     actuEcran()
  225.     jeuActif=false
  226. end
  227. function verifDollar()
  228.     if redstone.testBundledInput(arriveRedstone,colors.green) then
  229.         print("verif dollar")
  230.         chestInsert.condenseItems()
  231.         stacks=chestInsert.getAllStacks()
  232.         table.foreach(stacks,function(i,data)
  233.             info=data.basic()          
  234.             chestInsert.pushItem(chestInsertSortie,i,info.qty)
  235.             credit=credit+info.qty
  236.             noteBlock.playNote(0,2)
  237.         end)
  238.         actuEcran()
  239.     end
  240. end
  241. function verif()
  242.     while true do
  243.         local event = os.pullEvent("redstone")
  244.         verifDollar()
  245.     end
  246. end
  247. while true do
  248.     local event = os.pullEvent("redstone")
  249.     verifDollar()
  250.     if redstone.testBundledInput(arriveRedstone,colors.brown)~=statutActuelLanc then
  251.         statutActuelLanc=redstone.testBundledInput(arriveRedstone,colors.brown)
  252.         if jeuActif==false then
  253.             if credit>=2 then
  254.                 credit=credit-2
  255.                 gagnotte=gagnotte+1
  256.                 file=fs.open("gagnotte","w")
  257.                 file.write(tostring(gagnotte))
  258.                 file.close()
  259.                 actuEcran()
  260.                 jeuActif=true
  261.                 parallel.waitForAny(verif,lancement)
  262.             else
  263.                 noteBlock.playNote(4,2)
  264.                 ecran.setTextColor(colors.white)
  265.                 ecran.setBackgroundColor(colors.red)  
  266.                 ecran.clear()
  267.                 ecran.setTextScale(2)
  268.                 ecran.setCursorPos(1,1)
  269.                 ecran.write("PAS DE CREDIT")
  270.                 ecran.setCursorPos(1,2)
  271.                 ecran.write("insert 2 coin")
  272.             end
  273.         end
  274.     end
  275. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement