lego11

CARTA Craftzone

May 11th, 2018
290
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 cartaNonValida()
  11. clear()
  12. print("Carta non valida o corrotta.")
  13. print("")
  14. print("Premere un tasto per uscire")
  15. os.pullEvent("key")
  16. os.reboot()
  17. end
  18.  
  19. function cartaVuota()
  20. clear()
  21. print("Carta smagnetizzata o vuota.")
  22. print("")
  23. print("Premere un tasto per uscire")
  24. os.pullEvent("key")
  25. os.reboot()
  26. end
  27.  
  28.  
  29. m = peripheral.wrap("bottom") --magcard
  30. clear()
  31. print("Benvenuti in CraftZone")
  32. print("")
  33. print("Inserire la carta")
  34.  
  35. m.setInsertCardLight(true)
  36. za,rawcarta = os.pullEvent("mag_swipe")
  37. m.setInsertCardLight(false)
  38.  
  39. if rawcarta == nil then
  40. cartaVuota()
  41. end
  42.  
  43. tab = textutils.unserialize(rawcarta)
  44.  
  45. if type(tab) ~= "table" then
  46. cartaNonValida()
  47. end
  48.  
  49. if tab.t ~= "cc" then
  50. cartaNonValida()
  51. end
  52.  
  53. if tab.e ~= "BN" then
  54. cartaNonValida()
  55. end
  56.  
  57. credito = tonumber(tab.v)
  58.  
  59. while true do
  60. print("La carta ha una disponibilità di "..credito.." IC.")
  61. print("")
  62. print("Per favore scegliere un'opzione utilizzando i tasti numerici e confermare con ENTER:")
  63. print("")
  64. print("[1] Attivare i macchinari per 2 minuti - 1 IC")
  65. print("[2] Annullare il pagamento")
  66. num=tonumber(read())
  67. if num == 1 then
  68. prelievo=1
  69. if prelievo > credito then
  70. clear()
  71. print("Disponibilità insufficiente")
  72. sleep(5)
  73. os.reboot()
  74. end
  75. clear()
  76. print("Inserire nuovamente la carta per confermare il pagamento")
  77.  
  78.  
  79. tabr.t = tab.t
  80. tabr.e = tab.e
  81. tabr.p = tab.p
  82. tabr.v = tostring(credito - prelievo)
  83.  
  84. ncr = textutils.serialize(tabr)
  85.  
  86. m.setInsertCardLight(true)
  87. m.beginWrite(ncr,lbl)
  88. os.pullEvent("mag_write_done")
  89. m.setInsertCardLight(false)
  90. clear()
  91. print("Macchinari attivati")
  92. print("")
  93. redstone.setOutput("back", true)
  94. sleep(0.25)
  95. redstone.setOutput("back", false)
  96. print("")
  97. print("Grazie!")
  98. sleep(5)
  99. os.reboot()
  100. elseif num == 2 then clear() break end
  101. end
  102. clear()
  103. print("Attendere")
  104. sleep(1)
  105. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment