Advertisement
Guest User

startup

a guest
Mar 1st, 2019
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.32 KB | None | 0 0
  1. rednet.open("right")
  2.  
  3. term.clear()
  4. term.setCursorPos(1,1)
  5.  
  6. local username, password
  7.  
  8. print("Withdraw Cash")
  9. print("---------------------------------------------------")
  10. print("")
  11. io.write("Username: ")
  12. username = io.read()
  13. print("")
  14. io.write("Password: ")
  15. password = read("*")
  16.  
  17. rednet.send(0, username, "getAccount")
  18.  
  19. local senderId, message, protocol = rednet.receive()
  20.  
  21. term.clear()
  22. term.setCursorPos(1,1)
  23. if message == "dns" then
  24.   print("User does not exist. Please create an account")
  25.   sleep(2)
  26.   os.reboot()
  27. end
  28.  
  29. if password == message[3] then
  30.    local done = false
  31.    while not done do
  32.       term.clear()
  33.       term.setCursorPos(1,1)
  34.       print("Current Balance: "..message[4].."$")
  35.       print("---------------------------------------------------")
  36.       print("")
  37.       print("Please enter the amount you wish to withdraw")
  38.       print("Enter 'exit' to exit")
  39.       print("")
  40.       io.write("Amount to withdraw: ")
  41.       local amount = io.read()
  42.      
  43.       if amount == "exit" then  
  44.         os.reboot()
  45.       end
  46.       if tonumber(amount) == nil then
  47.         term.clear()
  48.         term.setCursorPos(1,1)
  49.         print("Please enter a number...")
  50.         sleep(2)
  51.       else
  52.         amount = tonumber(amount)
  53.         if amount > message[4] then
  54.           term.clear()
  55.           term.setCursorPos(1,1)
  56.           print("You have insufficient funds")
  57.           sleep(2)
  58.         else
  59.           rednet.send(10, {message[2], amount}, "withdraw")
  60.  
  61.           local senderId, success, protocol = rednet.receive()
  62.  
  63.           term.clear()
  64.           term.setCursorPos(1,1)
  65.           if success == true then
  66.             rednet.send(0, {username, message[4] - amount}, "editBalance")
  67.             print("Withdrawal complete...")
  68.             print("New balance: "..message[4] - amount.."$")
  69.             print("")
  70.             print("Press any key to continue...")
  71.                        
  72.             os.pullEvent("key")
  73.             os.reboot()
  74.           else
  75.             print("Withdrawal failed...")
  76.             print("Perhaps you spelled your MC name wrong.")
  77.             print("Press any key to continue...")
  78.             os.pullEvent("key")
  79.             os.reboot()
  80.           end
  81.         end
  82.       end
  83.    end
  84. else
  85.   print("Incorrect password. Please try again")
  86.   sleep(2)
  87.   os.reboot()
  88. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement