Advertisement
Marum

Mermegold V4 ATM Terminal

Mar 25th, 2025 (edited)
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.70 KB | None | 0 0
  1. -- ATM Terminal
  2.  
  3. local linkedAssistantID
  4.  
  5. local localization = {
  6. en={
  7. welcome="Welcome!",
  8. finding_assistant = "Looking for assistant (please place a turtle, install the assistant program and turn it on)",
  9. assistant_found = "Assistant found: #",
  10. calculating_value = "Calculating value...",
  11. depositing = "Depositing...",
  12. deposited = "You have deposited $",
  13. withdrawing = "Withdrawing...",
  14. not_enough_stored = {"Not enough money in the vault", "Try with lower amount"},
  15. invalid_amount = "Invalid amount",
  16. not_enough_balance = "Not enough balance",
  17. come_again = "Thank you! Come again!",
  18. login = "Log In",
  19. info = "What is Mermegold",
  20. create_account = "How do I make an account",
  21. insert_card = {"","","","","","Please insert your", "card in the disk drive"},
  22. info_screen = {
  23. "","","",
  24. "Welcome to Mermegold!",
  25. "",
  26. "With your Mermegold card you won't need to have",
  27. "money on you ever again. You will be able to",
  28. "perform remote transactions and have a full",
  29. "movement log.",
  30. "",
  31. "You will be able to install machines at your",
  32. "stores, with catalogues and automatic checkout.",
  33. "All payments will end up in your account. No",
  34. "more shuffling through chests to collect your",
  35. "payments!"
  36. },
  37. create_account_screen = {
  38. "","","","","","","",
  39. "To make an account, contact your local Mermegold",
  40. "employee and arrange a meeting. You will open an",
  41. "account together in the bank.",
  42. },
  43. pricing_screen = {
  44. "The Mermegold card is free!",
  45. "The bank automatically charges",
  46. " por every ",
  47. "transfered to or from your account.",
  48. "Ask about the Mermegold phone, which acts as a",
  49. "card and lets perform transactions anywhere!"
  50. },
  51. check_balance = "Check balance",
  52. deposit = "Deposit",
  53. withdraw = "Withdraw",
  54. perform_transaction = "Perform transaction",
  55. pricing = "Cost",
  56. history = "Log",
  57. logout = "Exit",
  58. input_money_in_container = {"","","","","",
  59. "Input money into the container",
  60. "before continuing."
  61. },
  62. confirm_deposit = {"","","","","",
  63. "Are you sure you want to",
  64. "deposit this money?"
  65. },
  66. no_money_to_deposit = {
  67. "","","","","","",
  68. "No money to deposit"
  69. },
  70. amount_to_withdraw = " to withdraw",
  71. done = "Done!",
  72. take_money = "Take the money from the container",
  73. amount_withdrawn = " withdrawn: ",
  74. transaction_instructions = {"Recipient account", "Amount to send", "Transaction description"},
  75. succesful_logout = "See you later!",
  76. ordering_money = "Organizing money before shutdown..."
  77. },
  78. es={
  79. welcome="Bienvenido!",
  80. finding_assistant = "Buscando asistente (por favor coloque y prenda una tortuga con el programa de asistente instalado)",
  81. assistant_found = "Asistente encontrado: #",
  82. calculating_value = "Calculando valor...",
  83. depositing = "Depositando...",
  84. deposited = "Has depositado $",
  85. withdrawing = "Retirando...",
  86. not_enough_stored = {"No hay suficiente dinero en la boveda", "Intente con un monto mas chico"},
  87. invalid_amount = "Monto invalido",
  88. not_enough_balance = "No tienes suficiente",
  89. come_again = "Gracias! Vuelva pronto!",
  90. login = "Ingresar",
  91. info = "Que es Mermegold",
  92. create_account = "Como me hago una cuenta",
  93. insert_card = {"","","","","","Por favor, ingrese su", "tarjeta en la disquetera"},
  94. info_screen = {
  95. "","","","",
  96. "Bienvenido a Mermegold!",
  97. "",
  98. "Con tu tarjeta mermegold, no tendras que llevar",
  99. "oro encima nunca mas. Podras hacer transacciones",
  100. "remotas y tendras un historial completo.",
  101. "",
  102. "Podras poner maquinas en tu local con catalogos",
  103. "que calculen el total de forma automatica, y",
  104. "todos los pagos iran a tu cuenta. No mas",
  105. "revolver cofres para recolectar pagos!"
  106. },
  107. create_account_screen = {
  108. "","","","","","","",
  109. "Para hacerse una cuenta, contactese con un",
  110. "empleado de Mermegold y arregle una cita.",
  111. "En el banco abriran una cuenta juntos.",
  112. },
  113. pricing_screen = {
  114. "La tarjeta Mermegold es gratis!",
  115. "El banco cobra automaticamente",
  116. " por cada ",
  117. "transferidos desde o hacia tu cuenta.",
  118. "Consulte por el movil Mermegold, que hace de",
  119. "tarjeta y puede realizar transacciones donde sea!"
  120. },
  121. check_balance = "Consultar balance",
  122. deposit = "Depositar",
  123. withdraw = "Retirar",
  124. perform_transaction = "Realizar transaccion",
  125. pricing = "Costo",
  126. history = "Historial",
  127. logout = "Salir",
  128. input_money_in_container = {"","","","","",
  129. "Ingrese dinero en el contenedor",
  130. "antes de continuar."
  131. },
  132. confirm_deposit = {"","","","","",
  133. "Estas seguro que quieres",
  134. "depositar este dinero?"
  135. },
  136. no_money_to_deposit = {
  137. "","","","","","",
  138. "No hay dinero para depositar"
  139. },
  140. amount_to_withdraw = " a retirar",
  141. done = "Listo!",
  142. take_money = "Tome el dinero del contenedor",
  143. amount_withdrawn = " retirados: ",
  144. transaction_instructions = {"Cuenta a recibir los fondos", "Monto a enviar", "Descripcion de la transaccion"},
  145. succesful_logout = "Hasta luego!",
  146. ordering_money = "Organizando dinero antes de apagar..."
  147. },
  148. de={
  149. welcome="Willkommen!",
  150. finding_assistant = "Auf der Suche nach einem Assistenten (bitte eine Schildkröte platzieren, das Assistentenprogramm installieren und einschalten)",
  151. assistant_found = "Assistent gefunden: #",
  152. calculating_value = "Wert wird berechnet...",
  153. depositing = "Einzahlen...",
  154. deposited = "Sie haben $ eingezahlt",
  155. withdrawing = "Auszahlen...",
  156. not_enough_stored = {"Nicht genug Geld im Tresor", "Versuchen Sie es mit geringerer Menge nochmal"},
  157. invalid_amount = "Ungueltiger Betrag",
  158. not_enough_balance = "Kontostandt zu niedrig",
  159. come_again = "Danke! Kommen Sie wieder!",
  160. login = "Anmelden",
  161. info = "Was ist Mermegold",
  162. create_account = "Wie erstelle ich ein Konto?",
  163. insert_card = {"", "", "", "", "", "Bitte stecken Sie Ihre", "Karte ins Laufwerk"},
  164. info_screen = {
  165. "", "", "",
  166. "Willkommen bei Mermegold!",
  167. "",
  168. "Mit Ihrer Mermegold-Karte müssen Sie nie wieder",
  169. "Bargeld bei sich tragen. Sie können damit",
  170. "Transaktionen aus der Ferne durchführen und erhalten",
  171. "ein vollständiges Bewegungsprotokoll.",
  172. "",
  173. "Sie können in Ihren Geschäften Geräte mit",
  174. "Produktkatalogen und automatischer Kasse installieren.",
  175. "Alle Zahlungen landen direkt auf Ihrem Konto.",
  176. "Kein mühsames Kisten-Durchsuchen mehr, um Geld",
  177. "einzusammeln!"
  178. },
  179. create_account_screen = {
  180. "", "", "", "", "", "", "",
  181. "Um ein Konto zu eröffnen, wenden Sie sich an einen",
  182. "Mermegold-Mitarbeiter vor Ort und vereinbaren Sie",
  183. "einen Termin. Die Kontoeröffnung erfolgt gemeinsam",
  184. "in der Bank."
  185. },
  186. pricing_screen = {
  187. "Die Mermegold-Karte ist kostenlos!",
  188. "Die Bank erhebt automatisch Gebühren",
  189. " pro jeder ",
  190. "Überweisung auf oder von Ihrem Konto.",
  191. "Fragen Sie nach dem Mermegold-Telefon – es dient",
  192. "ebenfalls als Karte und ermöglicht Transaktionen",
  193. "von überall!"
  194. },
  195. check_balance = "Kontostandt Ansehen",
  196. deposit = "Einzahlen",
  197. withdraw = "Auszahlen",
  198. perform_transaction = "Transaktion durchführen",
  199. pricing = "Preis",
  200. history = "Log",
  201. logout = "Abmelden",
  202. input_money_in_container = {"","","","","",
  203. "Legen Sie geld in den Behaelter",
  204. "bevor Sie fortfahren."
  205. },
  206. confirm_deposit = {"","","","","",
  207. "Sind Sie sicher, dass Sie diesen",
  208. "Betrag einzahlen moechten?"
  209. },
  210. no_money_to_deposit = {
  211. "","","","","","",
  212. "Kein Geld zum Einzahlen"
  213. },
  214. amount_to_withdraw = " zum Auszahlen",
  215. done = "Done!",
  216. take_money = "Nehme das Geld aus dem Behälter",
  217. amount_withdrawn = " Auszahlen: ",
  218. transaction_instructions = {"Empfaenger Konto", "Betrag zu Senden", "Transaktios Beschreibung"},
  219. succesful_logout = "Auf Wiedersehen!",
  220. ordering_money = "Geld vor dem Shutdown organisieren..."
  221. },
  222. }
  223.  
  224. -------------------- Start
  225. local modem = peripheral.find("modem")
  226.  
  227. while (modem == nil) do
  228. modem = peripheral.find("modem")
  229. if (modem == nil) then
  230. term.setBackgroundColor(colors.red)
  231. term.setTextColor(colors.white)
  232. term.clear()
  233. term.setCursorPos(1,1)
  234. print("Ender modem required. Please connect a modem to continue...")
  235. os.pullEvent("peripheral")
  236. end
  237. end
  238.  
  239. peripheral.find("modem", rednet.open)
  240.  
  241. local diskdrive = peripheral.find("drive")
  242. os.loadAPI("bankapi.lua")
  243. local serverData = bankapi.getServerData()
  244. local lang = serverData.lang
  245.  
  246. local f = fs.open("assistant.txt", "r")
  247. if (f ~= nil) then
  248. linkedAssistantID = tonumber(f.readLine())
  249. f.close()
  250. else
  251. print(localization[lang].finding_assistant)
  252. while (true) do
  253. rednet.broadcast("hiring", "mermegold_customer")
  254. local sender, message = rednet.receive("mermegold_customer", 1)
  255. if (message == "offering") then
  256. linkedAssistantID = sender
  257. break
  258. end
  259. end
  260. print(localization[lang].assistant_found..linkedAssistantID)
  261. local f = fs.open("assistant.txt", "w")
  262. f.write(tostring(linkedAssistantID))
  263. f.close()
  264. end
  265.  
  266. local currentAccount = 0
  267.  
  268. if (diskdrive.isDiskPresent()) then
  269. local f = fs.open("disk/mermegold.txt", "r")
  270. if (f ~= nil) then
  271. local value = f.readLine()
  272. if (value ~= nil) then
  273. local tempClientData = bankapi.getClientData()
  274. if (tempClientData[value] ~= nil) then
  275. currentAccount = value
  276. end
  277. end
  278. end
  279. end
  280.  
  281. -------------------- Functions
  282. local function calculateValue()
  283. local message = {
  284. action = "calculateValue",
  285. serverData = serverData
  286. }
  287. bankapi.waitScreen(localization[lang].calculating_value)
  288. while (true) do
  289. rednet.send(linkedAssistantID, message, "mermegold_customer")
  290. local sender, message = rednet.receive("mermegold_customer")
  291. if (message.success) then
  292. return message.response
  293. end
  294. end
  295. end
  296.  
  297. local function deposit()
  298. local message = {
  299. action = "deposit",
  300. serverData = serverData
  301. }
  302. bankapi.waitScreen(localization[lang].depositing)
  303. rednet.send(linkedAssistantID, message, "mermegold_customer")
  304. local sender, message = rednet.receive("mermegold_customer")
  305. local amount = message.response
  306. local success, response = bankapi.deposit(currentAccount, amount)
  307. bankapi.successScreen(localization[lang].deposited..amount)
  308. return success, response
  309. end
  310.  
  311. local function assistantWithdrawItems(amount)
  312. if (amount <= 0 or amount == nil) then
  313. return false, "invalid_amount"
  314. end
  315.  
  316. local message = {
  317. action = "withdraw",
  318. amount = amount,
  319. serverData = serverData
  320. }
  321. bankapi.waitScreen(localization[lang].withdrawing)
  322. rednet.send(linkedAssistantID, message, "mermegold_customer")
  323. local sender, message = rednet.receive("mermegold_customer")
  324. return message.success, message.response
  325. end
  326.  
  327. local function reduceStorage()
  328. local message = {
  329. action = "reduce",
  330. serverData = serverData
  331. }
  332. while (true) do
  333. rednet.send(linkedAssistantID, message, "mermegold_customer")
  334. local sender, message = rednet.receive("mermegold_customer")
  335. if (message.success) then
  336. bankapi.successScreen(localization[lang].come_again)
  337. return
  338. end
  339. end
  340. end
  341. ---------------------------
  342.  
  343. -------------------- Loop
  344. while true do
  345. while true do
  346. local tempClientData = bankapi.getClientData()
  347. local command
  348. if (tempClientData[currentAccount] == nil) then -- Guest screen
  349. command = bankapi.optionMenu(localization[lang].welcome, {
  350. {option = "login",
  351. text = localization[lang].login},
  352. {option = "info",
  353. text = localization[lang].info},
  354. {option = "createaccount",
  355. text = localization[lang].create_account},
  356. {option = "pricing",
  357. text = localization[lang].pricing},
  358. })
  359.  
  360. if (command == "login") then
  361. if (diskdrive.isDiskPresent()) then
  362. os.reboot()
  363. end
  364. local accept = bankapi.confirmScreen(localization[lang].insert_card)
  365. if (accept) then
  366. os.reboot()
  367. end
  368. elseif (command == "info") then
  369. bankapi.textScreen(localization[lang].info_screen)
  370. elseif (command == "createaccount") then
  371. bankapi.textScreen(localization[lang].create_account_screen)
  372. elseif (command == "pricing") then
  373. bankapi.textScreen({
  374. "","","","","",
  375. localization[lang].pricing_screen[1],
  376. "",
  377. localization[lang].pricing_screen[2],
  378. "$"..serverData.cumulativePrice..localization[lang].pricing_screen[3].."$"..serverData.cumulativeLimit,
  379. localization[lang].pricing_screen[4],
  380. "",
  381. localization[lang].pricing_screen[5],
  382. localization[lang].pricing_screen[6],
  383. })
  384. end
  385. else
  386. local line = string.rep(string.char(140), 3)
  387. command = bankapi.optionMenu(line.." "..tempClientData[currentAccount].name.." "..line, {
  388. {option = "balance",
  389. text = localization[lang].check_balance},
  390. {option = "deposit",
  391. text = localization[lang].deposit},
  392. {option = "withdraw",
  393. text = localization[lang].withdraw},
  394. {option = "transaction",
  395. text = localization[lang].perform_transaction},
  396. {option = "log",
  397. text = localization[lang].history},
  398. {option = "logout",
  399. text = localization[lang].logout},
  400. }, 2)
  401.  
  402. if (command == "balance") then
  403. bankapi.showBalance(currentAccount)
  404.  
  405. elseif (command == "deposit") then
  406. local amount = calculateValue()
  407. local superbreak = false
  408. while (amount <= 0) do
  409. local accept = bankapi.confirmScreen(localization[lang].input_money_in_container)
  410. if (not accept) then
  411. superbreak = true
  412. break
  413. end
  414. amount = calculateValue()
  415. end
  416. if (superbreak) then break end
  417. local accept = bankapi.confirmScreen(localization[lang].confirm_deposit, {amount = "$"..amount})
  418. if (not accept) then break end
  419. if (amount > 0) then
  420. deposit()
  421. else
  422. bankapi.textScreen(localization[lang].no_money_to_deposit)
  423. end
  424. elseif (command == "withdraw") then
  425. local tempClientData = bankapi.getClientData()
  426. local multiplier = tonumber(serverData.valueMultiplier)
  427. local steps = {serverData.currency[1].plural[lang]..localization[lang].amount_to_withdraw}
  428. local itemMax = math.floor(tempClientData[currentAccount].balance/multiplier)
  429. local amount = bankapi.inputNumberScreen(steps, 1, itemMax, itemMax.." "..serverData.currency[1].plural[lang])
  430. if (amount == nil) then break end
  431. amount = tonumber(amount)
  432. if (amount > itemMax) then
  433. bankapi.errorScreen(localization[lang].not_enough_balance)
  434. break
  435. end
  436. local success, message = assistantWithdrawItems(amount)
  437. if (not success) then
  438. bankapi.errorScreen(localization[lang][message])
  439. break
  440. end
  441. local success, message = bankapi.withdraw(currentAccount, amount*multiplier)
  442. if (success) then
  443. bankapi.textScreen({
  444. "",
  445. "",
  446. "",
  447. localization[lang].done,
  448. localization[lang].take_money,
  449. "",
  450. serverData.currency[1].plural[lang]..localization[lang].amount_withdrawn..tostring(amount),
  451. "",
  452. smallestDenomination})
  453. else
  454. bankapi.errorScreen(message)
  455. end
  456.  
  457. elseif (command == "log") then
  458. bankapi.transactionLogScreen(currentAccount)
  459.  
  460. elseif (command == "transaction") then
  461. local tempClientData = bankapi.getClientData()
  462. local steps = localization[lang].transaction_instructions
  463. local to = bankapi.selectAccountScreen(steps, 1, currentAccount)
  464. if (to == nil) then break end
  465. local amount = bankapi.inputNumberScreen(steps, 2, tempClientData[currentAccount].balance)
  466. if (amount == nil) then break end
  467. local description = bankapi.inputTextScreen(steps, 3, 100)
  468. if (description == nil) then break end
  469.  
  470. local success, message = bankapi.transaction(currentAccount, to, amount, description)
  471. bankapi.responseScreen(success, message)
  472.  
  473. elseif (command == "logout") then
  474. diskdrive.ejectDisk()
  475. bankapi.successScreen(localization[lang].succesful_logout)
  476. bankapi.waitScreen(localization[lang].ordering_money)
  477. reduceStorage()
  478. os.shutdown()
  479. end
  480. end
  481. end
  482. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement