lego11

CARTA Distributore creosoto

May 11th, 2018
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --VARIABILI
  2. local lbl = "BN Credit"
  3. local tabr = {}
  4.  
  5. function clear()
  6. term.clear()
  7. term.setCursorPos(1,1)
  8. end
  9.  
  10. function pinErrato()
  11. clear()
  12. print("Errore di verifica del PIN")
  13. print("")
  14. print("Premere un tasto per uscire")
  15. os.pullEvent("key")
  16. os.reboot()
  17. end
  18.  
  19.  
  20. function cartaNonValida()
  21. clear()
  22. print("Carta non valida o corrotta.")
  23. print("")
  24. print("Premere un tasto per uscire")
  25. os.pullEvent("key")
  26. os.reboot()
  27. end
  28.  
  29. function cartaVuota()
  30. clear()
  31. print("Carta smagnetizzata o vuota.")
  32. print("")
  33. print("Premere un tasto per uscire")
  34. os.pullEvent("key")
  35. os.reboot()
  36. end
  37.  
  38.  
  39. m = peripheral.wrap("right") --magcard
  40. clear()
  41. print("RGBAR Oy - Distributore di Creosoto")
  42. print("")
  43. print("Inserire la carta")
  44.  
  45. m.setInsertCardLight(true)
  46. za,rawcarta = os.pullEvent("mag_swipe")
  47. m.setInsertCardLight(false)
  48.  
  49. if rawcarta == nil then
  50. cartaVuota()
  51. end
  52.  
  53. tab = textutils.unserialize(rawcarta)
  54.  
  55. if type(tab) ~= "table" then
  56. cartaNonValida()
  57. end
  58.  
  59. if tab.t ~= "cc" then
  60. cartaNonValida()
  61. end
  62.  
  63. if tab.e ~= "BN" then
  64. cartaNonValida()
  65. end
  66.  
  67. credito = tonumber(tab.v)
  68.  
  69. while true do
  70. print("La carta ha una disponibilità di "..credito.." IC.")
  71. print("")
  72. print("Per favore scegliere un'opzione utilizzando i tasti numerici e confermare con ENTER:")
  73. print("")
  74. print("[1] Erogare 1 vagone di creosoto - 5 IC")
  75. print("[2] Annullare il pagamento")
  76. num=tonumber(read())
  77. if num == 1 then
  78. prelievo=2
  79. if prelievo > credito then
  80. clear()
  81. print("Disponibilità insufficiente")
  82. sleep(5)
  83. os.reboot()
  84. end
  85. clear()
  86. print("Inserire nuovamente la carta per confermare il pagamento")
  87.  
  88.  
  89. tabr.t = tab.t
  90. tabr.e = tab.e
  91. tabr.p = tab.p
  92. tabr.v = tostring(credito - prelievo)
  93.  
  94. ncr = textutils.serialize(tabr)
  95.  
  96. m.setInsertCardLight(true)
  97. m.beginWrite(ncr,lbl)
  98. os.pullEvent("mag_write_done")
  99. m.setInsertCardLight(false)
  100. clear()
  101. print("Pompa creosoto attivata")
  102. print("")
  103. redstone.setOutput("bottom", true)
  104. sleep(0.25)
  105. redstone.setOutput("bottom", false)
  106. sleep(0.25)
  107. redstone.setOutput("bottom", true)
  108. sleep(0.25)
  109. redstone.setOutput("bottom", false)
  110. sleep(0.25)
  111. redstone.setOutput("bottom", true)
  112. sleep(0.25)
  113. redstone.setOutput("bottom", false)
  114. sleep(0.25)
  115. redstone.setOutput("bottom", true)
  116. sleep(0.25)
  117. redstone.setOutput("bottom", false)
  118. sleep(0.25)
  119. redstone.setOutput("bottom", true)
  120. sleep(0.25)
  121. redstone.setOutput("bottom", false)
  122. sleep(0.25)
  123. print("")
  124. print("Grazie!")
  125. sleep(5)
  126. os.reboot()
  127. elseif num == 2 then clear() break end
  128. end
  129. clear()
  130. print("Attendere")
  131. sleep(1)
  132. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment