Advertisement
lego11

Bancomat

May 11th, 2018
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --BANCOMAT V2 copyright lego11
  2. --VARIABILI
  3. local lbl = "BN Credit"
  4. local tabr = {}
  5.  
  6. function clear()
  7. term.clear()
  8. term.setCursorPos(1,1)
  9. end
  10.  
  11. function pinErrato()
  12. clear()
  13. print("Errore di verifica del PIN")
  14. print("")
  15. print("Premere un tasto per uscire")
  16. os.pullEvent("key")
  17. os.reboot()
  18. end
  19.  
  20.  
  21. function cartaNonValida()
  22. clear()
  23. print("Carta non valida o corrotta.")
  24. print("")
  25. print("Premere un tasto per uscire")
  26. os.pullEvent("key")
  27. os.reboot()
  28. end
  29.  
  30. function cartaVuota()
  31. clear()
  32. print("Carta smagnetizzata o vuota.")
  33. print("")
  34. print("Premere un tasto per uscire")
  35. os.pullEvent("key")
  36. os.reboot()
  37. end
  38.  
  39. function preleva()
  40. tabr.t = tab.t
  41. tabr.e = tab.e
  42. tabr.p = tab.p
  43. tabr.v = tostring(credito - prelievo)
  44.  
  45. ncr = textutils.serialize(tabr)
  46.  
  47. m.setInsertCardLight(true)
  48. m.beginWrite(ncr,lbl)
  49. os.pullEvent("mag_write_done")
  50. m.setInsertCardLight(false)
  51. end
  52.  
  53.  
  54. m = peripheral.wrap("right")
  55. lbl = "BN Credit"
  56.  
  57.  
  58.  
  59. clear()
  60. print("Banco di NEBRASKA - Sistema BANCOMAT(R)")
  61. print("")
  62. print("Inserire la carta")
  63. m.setInsertCardLight(true)
  64. za,rawcarta = os.pullEvent("mag_swipe")
  65. m.setInsertCardLight(false)
  66.  
  67. if rawcarta == nil then
  68. cartaVuota()
  69. end
  70.  
  71. tab = textutils.unserialize(rawcarta)
  72.  
  73. if type(tab) ~= "table" then
  74. cartaNonValida()
  75. end
  76.  
  77. if tab.t ~= "cc" then
  78. cartaNonValida()
  79. end
  80.  
  81. if tab.e ~= "BN" then
  82. cartaNonValida()
  83. end
  84.  
  85. if tab.p ~= "0000" then
  86. print("")
  87. print("Inserire il PIN e premere ENTER")
  88. print("")
  89. local pinUtente = read("#")
  90. if pinUtente ~= tab.p then
  91. pinErrato()
  92. end
  93. end
  94.  
  95. credito = tonumber(tab.v)
  96. clear()
  97. while true do
  98. print("La carta ha una disponibilità di "..credito.." IC.")
  99. print("")
  100. print("Per favore scegliere un'opzione utilizzando i tasti numerici e confermare con ENTER:")
  101. print("")
  102. print("[1] Preleva   64 IC")
  103. print("[2] Preleva  128 IC")
  104. print("[3] Preleva  256 IC")
  105. print("[4] Preleva  512 IC")
  106. print("[5] Preleva 4096 IC")
  107. print("[6] Cambia il PIN")
  108. print("[7] Esci senza prelevare")
  109. num=tonumber(read())
  110. if num == 1 then
  111. prelievo=64
  112. if prelievo > credito then
  113. clear()
  114. print("Disponibilità insufficiente")
  115. sleep(5)
  116. os.reboot()
  117. end
  118. clear()
  119. print("Inserire nuovamente la carta per confermare il prelievo")
  120. preleva()
  121. print("Ritirare il denaro")
  122. print("")
  123. redstone.setOutput("bottom", true)
  124. sleep(0.25)
  125. print("Erogati 64 IC")
  126. redstone.setOutput("bottom", false)
  127. print("")
  128. print("Prelievo effettuato!")
  129. print("")
  130. print("Tra poco sarà possibile eseguire un'altra operazione.")
  131. sleep(5)
  132. os.reboot()
  133.  
  134. elseif num == 2 then
  135.  
  136. prelievo=128
  137. if prelievo > credito then
  138. clear()
  139. print("Disponibilità insufficiente")
  140. sleep(5)
  141. os.reboot()
  142. end
  143. clear()
  144. print("Inserire nuovamente la carta per confermare il prelievo")
  145. preleva()
  146. print("Ritirare il denaro")
  147. print("")
  148. redstone.setOutput("bottom", true)
  149. sleep(0.25)
  150. print("Erogati 64 IC")
  151. redstone.setOutput("bottom", false)
  152. sleep(0.25)
  153. redstone.setOutput("bottom", true)
  154. sleep(0.25)
  155. print("Erogati 128 IC")
  156. redstone.setOutput("bottom", false)
  157. print("")
  158. print("Prelievo effettuato!")
  159. print("")
  160. print("Tra poco sarà possibile eseguire un'altra operazione.")
  161. sleep(5)
  162. os.reboot()
  163.  
  164. elseif num == 3 then
  165.  
  166. prelievo=256
  167. if prelievo > credito then
  168. clear()
  169. print("Disponibilità insufficiente")
  170. sleep(5)
  171. os.reboot()
  172. end
  173. clear()
  174. print("Inserire nuovamente la carta per confermare il prelievo")
  175. preleva()
  176. print("Ritirare il denaro")
  177. print("")
  178. redstone.setOutput("bottom", true)
  179. sleep(0.25)
  180. print("Erogati 64 IC")
  181. redstone.setOutput("bottom", false)
  182. sleep(0.25)
  183. redstone.setOutput("bottom", true)
  184. sleep(0.25)
  185. print("Erogati 128 IC")
  186. redstone.setOutput("bottom", false)
  187. sleep(0.25)
  188. redstone.setOutput("bottom", true)
  189. sleep(0.25)
  190. print("Erogati 192 IC")
  191. redstone.setOutput("bottom", false)
  192. sleep(0.25)
  193. redstone.setOutput("bottom", true)
  194. sleep(0.25)
  195. print("Erogati 256 IC")
  196. redstone.setOutput("bottom", false)
  197. print("")
  198. print("Prelievo effettuato!")
  199. print("")
  200. print("Tra poco sarà possibile eseguire un'altra operazione.")
  201.  
  202. sleep(5)
  203. os.reboot()
  204.  
  205. elseif num == 4 then
  206.  
  207. prelievo=512
  208. if prelievo > credito then
  209. clear()
  210. print("Disponibilità insufficiente")
  211. sleep(5)
  212. os.reboot()
  213. end
  214. clear()
  215. print("Inserire nuovamente la carta per confermare il prelievo")
  216. preleva()
  217. print("Ritirare il denaro")
  218. print("")
  219. redstone.setOutput("bottom", true)
  220. sleep(0.25)
  221. print("Erogati 64 IC")
  222. redstone.setOutput("bottom", false)
  223. sleep(0.25)
  224. redstone.setOutput("bottom", true)
  225. sleep(0.25)
  226. print("Erogati 128 IC")
  227. redstone.setOutput("bottom", false)
  228. sleep(0.25)
  229. redstone.setOutput("bottom", true)
  230. sleep(0.25)
  231. print("Erogati 192 IC")
  232. redstone.setOutput("bottom", false)
  233. sleep(0.25)
  234. redstone.setOutput("bottom", true)
  235. sleep(0.25)
  236. print("Erogati 256 IC")
  237. redstone.setOutput("bottom", false)
  238. sleep(0.25)
  239. redstone.setOutput("bottom", true)
  240. sleep(0.25)
  241. print("Erogati 320 IC")
  242. redstone.setOutput("bottom", false)
  243. sleep(0.25)
  244. redstone.setOutput("bottom", true)
  245. sleep(0.25)
  246. print("Erogati 384 IC")
  247. redstone.setOutput("bottom", false)
  248. sleep(0.25)
  249. redstone.setOutput("bottom", true)
  250. sleep(0.25)
  251. print("Erogati 448 IC")
  252. redstone.setOutput("bottom", false)
  253. sleep(0.25)
  254. redstone.setOutput("bottom", true)
  255. sleep(0.25)
  256. print("Erogati 512 IC")
  257. redstone.setOutput("bottom", false)
  258. print("")
  259. print("Prelievo effettuato!")
  260. print("")
  261. print("Tra poco sarà possibile eseguire un'altra operazione.")
  262. sleep(5)
  263. os.reboot()
  264.  
  265. elseif num == 5 then
  266. prelievo=4096
  267. erogati = 0
  268. if prelievo > credito then
  269. clear()
  270. print("Disponibilità insufficiente")
  271. sleep(5)
  272. os.reboot()
  273. end
  274. clear()
  275. print("Inserire nuovamente la carta per confermare il prelievo")
  276. preleva()
  277. print("Ritirare il denaro")
  278. print("")
  279. for i=prelievo,0,-64 do
  280. redstone.setOutput("bottom", true)
  281. sleep(0.25)
  282. erogati = erogati + 64
  283. print("Erogati "..erogati.." IC")
  284. redstone.setOutput("bottom", false)
  285. end
  286. print("")
  287. print("Prelievo effettuato!")
  288. print("")
  289. print("Tra poco sarà possibile eseguire un'altra operazione.")
  290. sleep(5)
  291. os.reboot()
  292.  
  293. elseif num == 6 then
  294. clear()
  295. print("Cambio PIN della carta di credito")
  296. print("")
  297. print("Nota: Impostare il PIN a '0000' per disabilitarlo")
  298. print("")
  299. print("Inserire il PIN e premere ENTER:")
  300. tab.p = read("#")
  301. clear()
  302. print("Inserire la carta per confermare il cambiamento")
  303. prelievo=0
  304. preleva()
  305. print("")
  306. if tab.p == "0000" then
  307. print("PIN disabilitato correttamente")
  308. else
  309. print("PIN cambiato correttamente")
  310. end
  311. print("")
  312. print("Premere un tasto qualsiasi per ritorare al menu' principale")
  313. os.pullEvent("key")
  314. elseif num == 7 then clear() break end
  315. clear()
  316. sleep(2)
  317. clear()
  318. end
  319. clear()
  320. print("Tra poco sarà possibile eseguire un'altra operazione.")
  321. sleep(1)
  322. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement