Marlingaming

SCS3 ATM MK 1

Sep 7th, 2021 (edited)
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.56 KB | None | 0 0
  1. --this program acts as both a local circulation and national circulation ATM system for the SCS3 Project
  2. Settings_ATMID = "0"
  3. Settings_Access = "local"
  4. Settings_Bank = "Guest"
  5. Settings_State = "Locked"
  6. Settings_AdminAccount = "Admin"
  7. Settings_CurrencyName = "Credit"--Use the word for a single of it
  8. Settings_AllowedAmounts[false,true,false,true,true]--five, ten, twenty, one hundred, one thousand
  9. --User
  10. Client_Username = "Guest"
  11. Client_UserCode = 0
  12. Client_HostServer = -1
  13. Client_Transfer = 0
  14. Client_Balance = 0
  15. --Program
  16. start()
  17. function start()
  18.     print("Checking Files")
  19.     if fs.exists(".Accounts") == false then
  20.         CreateFiles("Accounts")
  21.     end
  22.     if fs.exists(".Balance") == false then
  23.         CreateFiles("Balance")
  24.     end
  25.     if fs.exists(".SystemSettings") == false then
  26.         CreateFile("Settings")
  27.     end
  28.     SetupSettings()
  29.     Login()
  30. end
  31.  
  32. function CreateFiles(File)
  33.     local h = 0
  34.     if File == "Accounts" then
  35.         h = fs.open(".Accounts","w")
  36.         h.write("This FIle is for Accounts")
  37.         h.close()
  38.     else if File == "Balance" then
  39.         h = fs.open(".Balance","w")
  40.         h.write("This file is for Balance")
  41.         h.close()
  42.     else if File == "Settings" then
  43.  
  44.     end
  45. end
  46.  
  47. function SetupSettings()
  48.  
  49. end
  50.  
  51. function LogOut()
  52.     term.clear()
  53.     Client_Username = "Guest"
  54.     Client_UserCode = 0
  55.     Client_HostServer = -1
  56.     Client_Transfer = 0
  57.     Client_Balance = 0
  58.     Login()
  59. end
  60.  
  61. function Login()
  62.     term.setCursorPos(1,1)
  63.     term.write("Please Login")
  64.     local User = read()
  65.     local event, key = os.pullEvent("key")
  66.     while true do
  67.         if key == keys.enter then
  68.             if User == Settings_AdminAccount then
  69.                 AdminMenu()
  70.                 break
  71.             else
  72.                 CheckAccounts(User)
  73.                 break
  74.             end
  75.         end
  76.     end
  77. end
  78.  
  79. function CheckAccounts(User)
  80.     if Settings_Access == "local" then
  81.         local h = fs.open(".Accounts","r")
  82.         local i = 2
  83.         while true do
  84.             if h.read(i) == User then
  85.                 h.close()
  86.                 Client_Username = User
  87.                 Client_UserCode = i
  88.                 break
  89.                 Menu()
  90.             else
  91.                 i = i+1
  92.             end
  93.         end
  94.     else if Settings_Access == "Server" then
  95.         Network("Confirm","Account",User)
  96.     else if Settings_Access == "Disabled" then
  97.                
  98.     end
  99. end
  100.  
  101. function Menu()
  102.     term.clear()
  103.     term.setCursorPos(1,1)
  104.     term.write("----------MENU-----------")
  105.     term.setCursorPos(1,2)
  106.     term.write("Options")
  107.     term.setCursorPos(1,3)
  108.     term.write(" 1 - Account Details")
  109.     term.setCursorPos(1,4)
  110.     term.write(" 2 - Deposit")
  111.     term.setCursorPos(1,5)
  112.     term.write(" 3 - WithDraw")
  113.     term.setCursorPos(1,6)
  114.     term.write(" 4 - ")
  115.     term.setCursorPos(1,7)
  116.     term.write(" X - Log Out")
  117.     local event, key = os.pullEvent("key")
  118.     while true do
  119.         if key == keys.1 then
  120.             break
  121.         else if key == keys.2 then
  122.             break
  123.             TransferMenu("Deposit")
  124.         else if key == keys.3 then
  125.             break
  126.             TransferMenu("WithDraw")
  127.         else if key == keys.4 then
  128.            
  129.         else if key == keys.x then
  130.             break
  131.             LogOut()
  132.         end
  133.     end
  134. end
  135.  
  136. function TransferMenu(Type)
  137.     term.clear()
  138.     term.setCursorPos(1,1)
  139.     term.write(Type)
  140.     term.setCursorPos(1,2)
  141.     if Type == "Deposit" then
  142.         term.write("Please Place Cash in Container, then press Enter")
  143.     else if Type == "WithDraw" then
  144.         term.write("Please Enter Amount, then Press Enter")
  145.     end
  146.     local Amount = read()
  147.     local event, key = os.pullEvent("key")
  148.     while true do
  149.         if key == keys.enter then
  150.             if Type == "Deposit" then
  151.                 break
  152.                 CountCash()
  153.             else if Type == "WithDraw" then
  154.                 Transfer("WithDraw",Amount)
  155.             end                                      
  156.         end
  157.     end
  158. end
  159.  
  160. function CountCash()
  161.     local Container = peripheral.find("minecraft:Despenser")
  162.     local DetectedAmount = 0
  163.     for slot, item in pairs(Container.list()) do
  164.         if item.name == "1 " + Settings_CurrencyName then
  165.             DetectedAmount = DetectedAmount+1
  166.         else if item.name == "5 " + Settings_CurrencyName + "s" && Settings_AllowedAmounts[0] == true then
  167.             DetectedAmount = DetectedAmount + 5
  168.         else if item.name == "10 " + Settings_CurrencyName + "s" && Settings_AllowedAmounts[1] == true then
  169.             DetectedAmount = DetectedAmount + 10
  170.         else if item.name == "20 " + Settings_CurrencyName + "s" && Settings_AllowedAmounts[2] == true then
  171.             DetectedAmount = DetectedAmount + 20
  172.         else if item.name == "100 " + Settings_CurrencyName + "s" && Settings_AllowedAmounts[3] == true then
  173.             DetectedAmount = DetectedAmount + 100
  174.         else if item.name == "1000 " + Settings_CurrencyName + "s" && Settings_AllowedAmounts[4] == true then
  175.             DetectedAmount = DetectedAmount + 1000
  176.         end
  177.     end
  178.     Client_Transfer = DetectedAmount
  179.     Transfer("Deposit",DetectedAmount)
  180. end
  181.  
  182. function Transfer(Method,Amount)
  183.     if Method == "Deposit" then
  184.         if Settings_Access == "Local" then
  185.             local h = fs.open(".Balances","a")
  186.             h.setCursorPos(0,Client_UserCode)
  187.             Client_Balance = h.readLine()
  188.             Client_Balance = Client_Balance + Amount
  189.             h.clearLine()
  190.             h.write(Client_Balance)
  191.             h.close()
  192.         else if Settings_Access == "Network" then
  193.  
  194.         end
  195.     else if Method == "WithDraw" then
  196.  
  197.     end
  198.     term.setCursorPos(0,9)
  199.     term.write("New Balance = "+Client_Balance+" "+Settings_CurrencyName)
  200.     term.write("Amount Processed, Logging Out")
  201.     sleep(10)
  202.     LogOut()
  203. end
  204.  
  205. function Network(Mode,Item,ID)
  206.     if Mode == "Confirm" then
  207.        
  208.     else if Mode == "Change" then
  209.                    
  210.     else if Mode == "Create" then
  211.                        
  212.     end
  213. end
  214.  
  215. function AdminMenu()
  216.    
  217. end
Add Comment
Please, Sign In to add comment