Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- validItems = {'minecraft:emerald', 'minecraft:diamond', 'minecraft:gold_ingot', 'minecraft:iron_ingot'}
- term.setBackgroundColor(2048)
- rednet.open('left')
- database = rednet.lookup("C_ACC", 'database')
- rednet.close()
- pin = 0
- function GetAccount(pin)
- rednet.open('left')
- rednet.send(database, textutils.serialise({'account', pin}), 'C_ACC')
- sender,message,distance = rednet.receive('C_ACC')
- account = textutils.unserialise(message)
- rednet.close()
- if account ~= nil then
- return account
- else
- return nil
- end
- end
- function PromptAccount(clear)
- while true do
- if clear then
- term.clear()
- term.setCursorPos(1,1)
- end
- print("enter pin: ")
- pin = read()
- if pin == 'e' or pin == exit then
- break
- end
- print('Fetching account...')
- account = GetAccount(pin)
- if account ~= nil then
- return account
- else
- print("Invalid pin!")
- sleep(1.5)
- end
- end
- end
- function ShowAccount(account, clear)
- if clear then
- term.clear()
- term.setCursorPos(1,1)
- end
- print('Welcome, '..account[1])
- print('')
- print('Enter your requested action:')
- print('Check balance: C')
- print('Deposit: D')
- print('Withdraw: W')
- print('Exit: E')
- end
- while true do
- account = PromptAccount(true)
- ShowAccount(account, true)
- while true do
- command = read()
- command = string.lower(command)
- if command == 'c' or command == 'check' or command == balance then
- ShowAccount(account, true)
- print('Please re-enter your PIN')
- PromptAccount(false)
- ShowAccount(account, true)
- print('Your account balance is: '..account[2]..' credits')
- elseif command == 'd' or command == 'deposit' then
- print('Place items you wish to deposit in the inventory and press ENTER')
- read()
- print('Depositing...')
- for i=1, 16 do
- data = turtle.getItemDetail(i)
- if data ~= nil then
- turtle.select(i)
- data = turtle.getItemDetail(i)
- amount = turtle.getItemCount(i)
- if data.name == validItems[1] then --Emerald
- turtle.drop()
- elseif data.name == validItems[2] then --Diamond
- turtle.turnRight()
- turtle.drop()
- turtle.turnLeft()
- elseif data.name == validItems[3] then --Gold
- turtle.dropUp()
- elseif data.name == validItems[4] then --Iron
- turtle.dropDown()
- end
- rednet.open('left')
- rednet.send(database, textutils.serialise({'depo', pin, {data.name, amount}}), 'C_ACC')
- rednet.close()
- end
- end
- account = GetAccount(pin)
- print('Your account balance is: '..account[2]..' credits')
- elseif command == 'w' or command == 'withdraw' then
- term.clear()
- term.setCursorPos(1,1)
- print('Please re-enter your PIN')
- if PromptAccount(false) == account then
- term.clear()
- term.setCursorPos(1,1)
- print('Enter items to withdraw as')
- print('Emeralds: E')
- print('Diamonds: D')
- print('Gold Ingots: G')
- print('Iron Ingots: I')
- withdraw = read()
- withdraw = string.lower(withdraw)
- if withdraw == 'e' or withdraw == 'emerald' then
- withdraw = 1
- elseif withdraw == 'd' or withdraw == 'diamond' then
- withdraw = 2
- elseif withdraw == 'g' or withdraw == 'gold' then
- withdraw = 3
- elseif withdraw == 'i' or withdraw == 'iron' then
- withdraw = 4
- end
- rednet.open('left')
- rednet.send(database, textutils.serialise({'with', pin, validItems[withdraw]}), 'C_ACC')
- sender,message,distance = rednet.receive('C_ACC')
- message = textutils.unserialise(message)
- rednet.close()
- print('Withdrawing items...')
- print(withdraw)
- withdrawAmount = math.ceil(message[2] / 64)
- if withdraw == 1 then --Emeralds
- for i=1, range(withdrawAmount) do
- turtle.suck(64)
- end
- elseif withdraw == 2 then --Diamonds
- turtle.turnRight()
- for i=1, range(withdrawAmount) do
- turtle.suck(64)
- end
- turtle.turnLeft()
- elseif withdraw == 3 then --Gold
- for i=1, range(withdrawAmount) do
- turtle.suckUp(64)
- end
- elseif withdraw == 4 then --Iron
- for i=1, range(withdrawAmount) do
- turtle.suckDown(64)
- end
- end
- account = GetAccount(pin)
- ShowAccount(account, true)
- print('Items withdrawn. Your account balance is: '..account[2]..' credits')
- end
- elseif command == 'e' or command == 'exit' then
- break
- else
- print('Command not recognized! Try again.')
- end
- end
- pin = 0
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement