Marlingaming

Card Reader Vendor Register script

Sep 14th, 2021 (edited)
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. --NEW card reading system.
  2. --this program asks for the item being bought, then asks for card. once swiped, the script will have the cash transfered to the correct Parties
  3.  
  4. local OwnerAccount = nil
  5. local ItemsSold = {...}
  6. local ItemCost = {...}
  7.  
  8. local reader = peripheral.find("reader")
  9.  
  10. start()
  11.  
  12. local function start()
  13. if fs.exists("Config") == false then
  14. Config("Save")
  15. else
  16. Config("Load")
  17. end
  18. Menu()
  19. end
  20.  
  21. local function Menu()
  22. term.clear()
  23. term.setCursorPos(1,1)
  24. print("WELCOME!")
  25. print("Options")
  26. print("1 - Purchase")
  27. print("2 - Settings")
  28. repeat
  29. local event, key = os.pullEvent("key")
  30. until event == key
  31. if key == keys.1 then
  32. PurchaseManager()
  33. elseif key == keys.two then
  34. SettingsMenu()
  35. end
  36. end
  37.  
  38. local function PurchaseManager()
  39. term.clear()
  40. term.setCursorPos(1,1)
  41. print("Please enter the Number Corsponding to the Item desired. press enter to save")
  42. print("1= "...ItemsSold[1]...", 2= "...ItemsSold[2]...", 3= "...ItemsSold[3])
  43. print("4= "...ItemsSold[4]...", 5= "...ItemsSold[5]...", 6= "...ItemsSold[6])
  44. print("7= "...ItemsSold[7]...", 8= "...ItemsSold[8]...", 9= "...ItemsSold[9])
  45. local Amount = 0
  46. local input = read()
  47. repeat
  48. local event, key = os.pullEvent("key")
  49. Amount = Amount + ItemCost[key]
  50. term.setCursorPos(1,8)
  51. term.clearLine()
  52. term.write(input)
  53. until key == keys.enter
  54. term.clear()
  55. term.setCursorPos(1,1)
  56. print("please Insert Card to continue")
  57. local event, data = os.pullEvent("mag_swipe")
  58. local DA = data
  59. local Key = DA[1]
  60. local AccountID = DA[2]
  61. shell.run("BankingAccess_Client",Amount,AccountID,Key,OwnerAccount)
  62. print("Now Attempting Transfer, once transfer is")
  63. print("complete, you will be brought back to the menu")
  64. sleep(10)
  65. Menu()
  66. end
  67.  
  68. local function SettingsMenu()
  69. term.clear()
  70. term.setCursorPos(1,1)
  71. print("SETTINGS")
  72. print("Options")
  73. print("1-Add Item")
  74. print("2-Remove Item")
  75. print("3-AccountID")
  76. print("4-Menu")
  77. repeat
  78. local event, key = os.pullEvent("key")
  79. until key == keys.one or key == keys.two or key == keys.three or key == keys.four
  80. if key == keys.1 then
  81. Settings_ItemMenu("Add")
  82. elseif key == keys.2 then
  83. Settings_ItemMenu("Remove")
  84. elseif key == keys.3 then
  85. Settings_Account()
  86. elseif key == keys.4 then
  87. Menu()
  88. end
  89. end
  90.  
  91. local function Settings_ItemMenu(type)
  92. term.clear()
  93. term.setCursorPos(1,1)
  94. print("item menu - "...type)
  95. print("Please enter Number corsponding to the item")
  96. print(ItemsSold)
  97. local event, key = os.pullEvent("key")
  98. print("now "...type..." Item")
  99. if type == "Remove" then
  100. ItemsSold[key] = nil
  101. print("Item Deleted")
  102. elseif type == "Add" then
  103. print("Please now type Name of item, once done press enter")
  104. local input = read()
  105. repeat
  106. local event, key = os.pullEvent("key")
  107. until key == keys.enter
  108. ItemsSold[key] = input
  109. print("Item Added")
  110. end
  111. Config("Save")
  112. sleep(5)
  113. SettingsMenu()
  114. end
  115.  
  116. local function Settings_Account()
  117. term.clear()
  118. term.setCursorPos(1,1)
  119. print("Account Management")
  120. print("please enter Account ID")
  121. print("then press enter to save")
  122. local input = read()
  123. repeat
  124. local event, key = os.pullEvent("key")
  125. until key == keys.enter
  126. OwnerAccount = input
  127. Config("Save")
  128. print("Saved")
  129. sleep(5)
  130. SettingsMenu()
  131. end
  132.  
  133. local function Config(Mode)
  134. local file = fs.open("Config","a")
  135. if Mode == "Save" then
  136. file.clear()
  137. file.setCursorPos(1,1)
  138. file.writeLine(OwnerAccount)
  139. file.writeLine(ItemsSold)
  140. file.writeLine(ItemCost)
  141. elseif Mode == "load" then
  142. OwnerAccount = file.readLine(1)
  143. ItemsSold = {...file.readLine(2)...}
  144. ItemCost = {...file.readLine(3)...}
  145. end
  146. file.close()
  147. end
Add Comment
Please, Sign In to add comment