Marum

Computercraft Bank ATM v1

Jan 25th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. local bankServerID = 15
  2. local modemSide = "top"
  3. local diskSide = "bottom"
  4.  
  5. rednet.open(modemSide)
  6.  
  7. os.loadAPI("bankapi.lua")
  8. bankapi.setBankServerID(bankServerID)
  9.  
  10. local currentAccount = 0
  11.  
  12. if (fs.exists("disk")) then
  13. local f = fs.open("disk/mermegold.txt", "r")
  14. if (f ~= nil) then
  15. local value = f.readLine()
  16. if (value ~= nil) then
  17. local tempClientData = bankapi.getClientData()
  18. if (tempClientData[value] ~= nil) then
  19. currentAccount = value
  20. end
  21. end
  22. end
  23. end
  24.  
  25. while true do
  26. while true do
  27. local tempClientData = bankapi.getClientData()
  28. local command
  29. if (tempClientData[currentAccount] == nil) then -- Guest screen
  30. command = bankapi.optionMenu("¡Bienvenido!", {
  31. [1] = {
  32. ["option"] = "login",
  33. ["text"] = "Ingresar"},
  34. [2] = {
  35. ["option"] = "info",
  36. ["text"] = "¿Que es Mermegold?"},
  37. [3] = {
  38. ["option"] = "createaccount",
  39. ["text"] = "¿Como me hago una cuenta?"},
  40. })
  41.  
  42. if (command == "login") then
  43. local accept = bankapi.confirmScreen({"Por favor, ingrese su", "tarjeta en la disquetera"})
  44. if (accept) then
  45. os.reboot()
  46. end
  47. elseif (command == "info") then
  48. bankapi.textScreen({
  49. "¡Bienvenido a Mermegold!",
  50. "¡El primer y unico banco de Izit!",
  51. "",
  52. "Con tu tarjeta mermegold, no tendrás",
  53. "que llevar oro encima nunca más.",
  54. "Podrás hacer transacciónes remotas",
  55. "y tendrás un historial completo.",
  56. "Podrás poner máquinas en tu local",
  57. "con catálogos que calculen el total",
  58. "de forma automática, y todos los",
  59. "pagos iran al mismo lugar. ¡No mas",
  60. "revolver cofres para recolectar pagos!"
  61. })
  62. elseif (command == "createaccount") then
  63. bankapi.textScreen({
  64. "",
  65. "",
  66. "Para hacerse una cuenta, contactese",
  67. "con un empleado de Mermegold y arregle",
  68. "una cita. Abrirán juntos la cuenta",
  69. "en el banco.",
  70. "",
  71. "El costo de la tarjeta es de una pepita",
  72. "por cada 100 pepitas de transacciones.",
  73. "Esto se cobrará automáticamente."
  74. })
  75. end
  76. else
  77. command = bankapi.optionMenu("--- "..tempClientData[currentAccount].name.." ---", {
  78. [1] = {
  79. ["option"] = "balance",
  80. ["text"] = "Consultar balance"},
  81. [2] = {
  82. ["option"] = "transaction",
  83. ["text"] = "Realizar transacción"},
  84. [3] = {
  85. ["option"] = "log",
  86. ["text"] = "Historial de transacciones"},
  87. [4] = {
  88. ["option"] = "logout",
  89. ["text"] = "Salir"},
  90. }, 2)
  91.  
  92. if (command == "balance") then
  93. bankapi.showBalance(currentAccount)
  94.  
  95. elseif (command == "log") then
  96. bankapi.transactionLogScreen(currentAccount)
  97.  
  98. elseif (command == "transaction") then
  99. local tempClientData = bankapi.getClientData()
  100. local steps = {"Cuenta a recibir los fondos", "Monto a enviar", "Descripción de la transacción"}
  101. local to = bankapi.selectAccountScreen(steps, 1, currentAccount, true)
  102. if (to == nil) then break end
  103. local amount = bankapi.inputNumberScreen(steps, 2, tempClientData[currentAccount].balance)
  104. if (amount == nil) then break end
  105. local description = bankapi.inputTextScreen(steps, 3, 100)
  106. if (description == nil) then break end
  107.  
  108. local success, message = bankapi.transaction(currentAccount, to, amount, description)
  109. bankapi.responseScreen(message.success, message.response)
  110.  
  111. elseif (command == "logout") then
  112. disk.eject(diskSide)
  113. bankapi.successScreen("¡Hasta luego!")
  114. os.shutdown()
  115. end
  116. end
  117. end
  118. end
Add Comment
Please, Sign In to add comment