LolzPB

BCBancomat

Feb 18th, 2020
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.33 KB | None | 0 0
  1. modem = peripheral.wrap("back")
  2. mag = peripheral.wrap("right")
  3. local timer
  4.  
  5. function program()
  6. print("Banca di BlueCity - Ritiro da carta")
  7. print("\nInserire la carta")
  8. _, data, label = os.pullEvent("mag_swipe")
  9. tab = textutils.unserialize(data)
  10.  
  11. if tab == nil or tab.credito == nil or tab.label == nil then
  12.   print("\nCarta non valida!")
  13.   sleep(2)
  14.   os.reboot()
  15. end
  16. if tab.credito < 0 or tab.label ~= "BCB" then
  17.  print("\nCarta non valida!")
  18.  sleep(2)
  19.  os.reboot()
  20. end
  21.  
  22. print("\nCredito disponibile: "..tostring(tab.credito).." IC")
  23.  
  24. term.write("Quanto vuoi ritirare? >> ")
  25. quant = read()
  26.  
  27. if tonumber(quant) == nil or tonumber(quant) < 0 or tonumber(quant) > tab.credito then
  28.   print("\nInserire un numero valido!")
  29.   sleep(2)
  30.   os.reboot()
  31. end
  32.  
  33.  
  34.  
  35. tab.credito = tab.credito - tonumber(quant)
  36. timer = os.startTimer(10)
  37. print("\nInserire nuovamente la carta per confermare")
  38. while true do
  39. mag.beginWrite(textutils.serialize(tab), "BC Bank")
  40. _, k = os.pullEvent("mag_write_done")
  41. if _ == "key" then
  42.   print("Annullamento in corso")
  43.   sleep(2)
  44.   os.reboot()
  45. elseif _ == "mag_write_done" then
  46.   print("\nNuovo credito: "..tostring(tab.credito))
  47.   modem.send(quant)
  48.   sleep(2)
  49. end
  50. end
  51. end
  52.  
  53. function timer()
  54.   os.pullEvent("timer")
  55.   os.reboot()
  56. end
  57.  
  58. parallel.waitForAny(program, timer)
  59. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment