AdslHouba

Jeu1 : verif money

May 30th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.48 KB | None | 0 0
  1. modem=peripheral.find("modem")
  2. chest=peripheral.wrap("back")
  3.  
  4. file=fs.open("leCote","r")
  5. leCote=file.readLine()
  6. file.close()
  7.  
  8. function verifier()
  9.     print("Verif")
  10.     chest.condenseItems()
  11.     stacks=chest.getAllStacks()
  12.     money=0
  13.     table.foreach(stacks,function(i,data)
  14.         info=data.basic()
  15.         if info.name=="note500" then
  16.             money=info.qty*5
  17.         elseif info.name=="coin100" or info.name=="note100" then
  18.             money=info.qty*1
  19.         elseif info.name=="note200" then
  20.             money=info.qty*2
  21.         end
  22.     end)
  23.     if money>=5 then
  24.         print("ok")
  25.         modem.transmit(1,3,textutils.serialize({cote=leCote,argent=true}))
  26.     else
  27.         print("pas ok")
  28.         modem.transmit(1,3,textutils.serialize({cote=leCote,argent=false}))
  29.     end
  30. end
  31. function payer()
  32.     print("payer")
  33.     chest.condenseItems()
  34.     stacks=chest.getAllStacks()
  35.     moneys={note500=0,coin100=0,note100=0,note200=0}
  36.     table.foreach(stacks,function(i,data)
  37.         info=data.basic()
  38.         if info.name=="note500" or info.name=="coin100" or info.name=="note100" or info.name=="note200" then
  39.             moneys[info.name]=moneys[info.name]+info.qty
  40.         end
  41.     end)
  42.     money=5
  43.     table.foreach(stacks,function(i,data)
  44.         info=data.basic()
  45.         if moneys.note500~=0 then
  46.             if info.name=="note500" then
  47.                 if money==5 then
  48.                     print("> payer billet de 5 ")
  49.                     chest.pushItem("DOWN",i,1)
  50.                     money=0
  51.                 end
  52.             end
  53.         else
  54.             if money>0 then
  55.                 if info.name=="coin100" or info.name=="note100" then
  56.                    
  57.                     if info.qty<money then
  58.                         chest.pushItem("DOWN",i,info.qty)
  59.                         print("> payer "..info.qty.."x " ..info.name)
  60.                         money=money-info.qty
  61.                         print("reste a payer "..money)
  62.                     else
  63.                         chest.pushItem("DOWN",i,money)                     
  64.                         print("> payer "..money.."x " ..info.name)
  65.                         money=0
  66.                         print("reste a payer "..money)
  67.                     end
  68.                 elseif info.name=="note200" then
  69.                     if info.qty*2<money then
  70.                         chest.pushItem("DOWN",i,info.qty)
  71.                         print("> payer "..info.qty.."x " ..info.name)
  72.                         money=money-(info.qty*2)                       
  73.                         print("reste a payer "..money)
  74.                     else
  75.                         chest.pushItem("DOWN",i,math.ceil(money/2))
  76.                         print("> payer "..math.ceil(money/2).."x " ..info.name)
  77.                         money=0            
  78.                         print("reste a payer "..money)
  79.                     end
  80.                 end
  81.             end
  82.         end
  83.     end)
  84. end
  85.  
  86. modem.open(3)
  87. while true do
  88.     local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  89.     --local event, message = os.pullEvent("paste")
  90.      
  91.     if message=="verif" then
  92.         verifier()
  93.     elseif message=="payer" then
  94.         payer()
  95.     end
  96. end
Add Comment
Please, Sign In to add comment