Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- serverID = 0
- creditItem = "CreditBill50"
- creditPerItem = 50
- creditPerKEU = 10
- pMan = "powaMan"
- depositExtractor = 18
- bankDepositer = 19
- bankExtractor = 20
- withdrawalExtractor = 21
- depositBox = peripheral.wrap("chest_1")
- bankBox = peripheral.wrap("chest_3")
- depositSize = tonumber(depositBox.getInventorySize())
- bankSize = tonumber(bankBox.getInventorySize())
- peripherals = peripheral.getNames()
- periph = true
- index = 1
- while periph do
- periph = peripherals[index]
- if periph then
- periphType = peripheral.getType(periph)
- if periphType == "modem" then
- rednet.open(periph)
- end
- end
- index = index + 1
- end
- local info = { ... }
- while true do
- shell.run("clear")
- print("Please enter one of the following options:")
- print("Withdraw")
- print("Deposit")
- print("View Balance")
- print("Transfer")
- print("Register")
- print("Buy")
- option = read()
- info[1] = option
- if option == "Register" then
- shell.run("clear")
- print("Please enter a username:")
- info[2] = read()
- if info[2] then
- print("Please enter a password:")
- info[3] = read('*')
- if info[3] then
- rednet.send(serverID, info, "reg")
- id, servInfo, servProtocol = rednet.receive()
- if servProtocol == "failure" then
- print("Failed to register new account. Reason:")
- print(servInfo[1])
- os.sleep(5)
- else
- print("Account successfully registered.")
- os.sleep(5)
- end
- else
- print("Please try again and enter a vaild password.")
- os.sleep(5)
- end
- else
- print("Please try again and enter a vaild username.")
- os.sleep(5)
- end
- elseif (option == "Withdraw") or (option == "Deposit") or (option == "View Balance") or (option == "Transfer") or (option == "Buy") then
- shell.run("clear")
- print("Please enter your username:")
- info[2] = read()
- print("Please enter your password:")
- info[3] = read('*')
- rednet.send(serverID, info, "login")
- id, servInfo, servProtocol = rednet.receive()
- if servProtocol == "success" then
- loggedIn = true
- else
- print("Failed to log in. Reason:")
- print(servInfo[1])
- sleep(5)
- end
- else
- print("Please enter a vaild option.")
- sleep(5)
- end
- if loggedIn then
- loggedIn = false
- if option == "Withdraw" then
- info[1] = "View Balance"
- rednet.send(serverID, info, "balCheck")
- id, servInfo, servProtocol = rednet.receive()
- Bal = servInfo[1]
- info[1] = "Withdraw"
- print("Please enter the amount you wish to withdraw (must be multiples of ".. creditPerItem.. ":")
- withdrawalAmount = read()
- if withdrawalAmount > Bal then
- print("Sorry, but you do not have that amount in your bank account. Your current balance is: ".. Bal)
- else
- newBal = Bal - withdrawalAmount
- info[4] = newBal
- rednet.send(serverID, info, "withdrawal")
- info2 = withdrawalAmount/creditPerItem
- rednet.send(withdrawalExtractor, info2, "withdrawal")
- print("Your withdrawl was successful, thank you for banking with us.")
- sleep(10)
- end
- elseif option == "Deposit" then
- info[1] = "View Balance"
- rednet.send(serverID, info, "balCheck")
- id, servInfo, servProtocol = rednet.receive()
- oldBal = servInfo[1]
- info[1] = "Deposit"
- shell.run("clear")
- print("Please place the items in the chest to the right.")
- while not itemsInDepositBox do
- totalQty = 0
- loop = 0
- while loop < depositSize do
- loop = loop + 1
- num = depositBox.getStackInSlot(loop)
- if num ~= nil then
- if num.name == creditItem then
- totalQty = totalQty + num.qty
- end
- end
- if totalQty > 0 then
- itemsInDepositBox = true
- end
- os.sleep(0.1)
- end
- os.sleep(0.1)
- end
- rednet.send(depositExtractor, "true")
- shell.run("clear")
- print("Transfering items, please wait...")
- while itemsInDepositBox do
- loop = 0
- totalQty = 0
- while loop < depositSize do
- loop = loop + 1
- num = depositBox.getStackInSlot(loop)
- if num ~= nil then
- if num.name == creditItem then
- totalQty = totalQty + num.qty
- end
- end
- if totalQty == 0 then
- loop = 0
- while loop < depositSize do
- loop = loop + 1
- num = depositBox.getStackInSlot(loop)
- if num ~= nil then
- if num.name == creditItem then
- totalQty = totalQty + num.qty
- end
- end
- end
- if totalQty == 0 then
- itemsInDepositBox = false
- end
- end
- os.sleep(0.1)
- end
- os.sleep(0.1)
- end
- rednet.send(depositExtractor, "false")
- os.sleep(10)
- totalQty = 0
- loop = 0
- while loop < bankSize do
- loop = loop + 1
- num = bankBox.getStackInSlot(loop)
- if num ~= nil then
- if num.name == creditItem then
- totalQty = totalQty + num.qty
- end
- end
- end
- shell.run("clear")
- print("Doing the math...")
- addedCredit = creditPerItem*totalQty
- newBal = oldBal + addedCredit
- shell.run("clear")
- print("ecoATM has counted ".. totalQty.. " Items, and your account will be credited with ".. addedCredit.. " credits, is this correct? (y/n)")
- invalidInput = true
- while invalidInput do
- ATMInput = read()
- if ATMInput == "y" or ATMInput == "n" then
- invalidInput = false
- else
- print("Invalid input, please enter either \"n\" (No) or \"y\" (Yes) to continue.")
- end
- end
- if ATMInput == "y" then
- info[4] = addedCredit
- info[5] = newBal
- rednet.send(serverID, info, "deposit")
- id, servInfo, servProtocol = rednet.receive()
- print("Your final balance is: $".. newBal)
- print("Thank you for banking with us.")
- rednet.send(bankDepositer, "true")
- itemsInBankBox = true
- while itemsInBankBox do
- loop = 0
- totalQty = 0
- while loop < bankSize do
- loop = loop + 1
- num = bankBox.getStackInSlot(loop)
- if num ~= nil then
- if num.name == creditItem then
- totalQty = totalQty + num.qty
- end
- end
- if totalQty == 0 then
- loop = 0
- while loop < bankSize do
- loop = loop + 1
- num = bankBox.getStackInSlot(loop)
- if num ~= nil then
- if num.name == creditItem then
- totalQty = totalQty + num.qty
- end
- end
- end
- if totalQty == 0 then
- itemsInBankBox = false
- end
- end
- os.sleep(0.1)
- end
- os.sleep(0.1)
- end
- rednet.send(bankDepositer, "false")
- os.sleep(5)
- else
- print("Transaction canceled, refunding now.")
- rednet.send(bankExtractor, "true")
- itemsInBankBox = true
- while itemsInBankBox do
- loop = 0
- totalQty = 0
- while loop < bankSize do
- loop = loop + 1
- num = bankBox.getStackInSlot(loop)
- if num ~= nil then
- if num.name == creditItem then
- totalQty = totalQty + num.qty
- end
- end
- if totalQty == 0 then
- loop = 0
- while loop < bankSize do
- loop = loop + 1
- num = bankBox.getStackInSlot(loop)
- if num ~= nil then
- if num.name == creditItem then
- totalQty = totalQty + num.qty
- end
- end
- end
- if totalQty == 0 then
- itemsInBankBox = false
- end
- end
- os.sleep(0.1)
- end
- os.sleep(0.1)
- end
- os.sleep(5)
- rednet.send(bankExtractor, "false")
- print("Successfully refunded. We hope to see you again soon!")
- os.sleep(5)
- end
- elseif option == "View Balance" then
- shell.run("clear")
- rednet.send(serverID, info, "balCheck")
- id, servInfo, servProtocol = rednet.receive()
- print("User:".. info[2])
- print("Bal :".. servInfo[1])
- os.sleep(10)
- elseif option == "Transfer" then
- shell.run("clear")
- print("Please enter the name of the account you would like to send money to:")
- sendAcc = read()
- print("Please enter the amount of money you would like to send:")
- sendAmount = read()
- info[4] = sendAcc
- info[5] = sendAmount
- rednet.send(serverID, info, "transfer")
- id, servInfo, servProtocol = rednet.receive()
- if servProtocol == "failure" then
- print("Failed to send funds. Reason:")
- print(servInfo[1])
- else
- print("Successfully transfered all funds.")
- end
- os.sleep(10)
- elseif option == "Buy" then
- print("What would you like to buy? Please enter:")
- print("Electric Units (EU)")
- print("Water")
- buyOption = read()
- info[1] = buyOption
- info[1] = "View Balance"
- rednet.send(serverID, info, "balCheck")
- id, servInfo, servProtocol = rednet.receive()
- Bal = tonumber(servInfo[1])
- info[1] = buyOption
- if buyOption == "Electric Units (EU)" then
- shell.run("clear")
- print("Please enter the account ID you wish to purchace power from.")
- accID = tonumber(read())
- if not accID then
- print("Invalid Input. Please try again.")
- os.sleep(5)
- else
- print("How many kEU would you like to buy? (1 = 1000 units) (".. creditPerKEU.. " credits/kEU) (Bal: ".. Bal.." credits")
- kEU = read()
- if not kEU then
- print("Invalid Input. Please try again.")
- os.sleep(5)
- else
- cost = tonumber(kEU * creditPerKEU)
- info[4] = pMan
- info[5] = cost
- info[6] = kEU
- info[7] = accID
- shell.run("clear")
- print("This will cost you ".. cost.. " credits. Would you like to continue? (y/n)")
- invalidInput = true
- while invalidInput do
- ATMInput = read()
- if ATMInput == "y" or ATMInput == "n" then
- invalidInput = false
- else
- print("Invalid input, please enter either \"n\" (No) or \"y\" (Yes) to continue.")
- end
- end
- if ATMInput == "y" then
- if cost > Bal then
- print("You have insufficient funds to pay for that much power. Please try again with a smaller amount, or deposit some credits.")
- os.sleep(5)
- else
- rednet.send(serverID, info, "buy")
- id, servInfo, servProtocol = rednet.receive()
- end
- else
- print("Transaction canceled.")
- os.sleep(5)
- end
- end
- end
- elseif buyOption == "Water" then
- shell.run("clear")
- print("You've successfully logged in, but I haven't done this part of the code yet. Sorry!")
- os.sleep(5)
- else
- print("Invalid option. Please try again.")
- os.sleep(5)
- end
- -- rednet.send(serverID, info, "buy")
- -- id, servInfo, servProtocol = rednet.receive()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement