Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("accounts")
- pD=peripheral.wrap("playerDetector_0")
- cB=peripheral.wrap("chatBox_0")
- outerChest = peripheral.find("minecraft:chest_0")
- bankIn = peripheral.find("minecraft:chest_1")
- regDist=5
- curUser=""
- evt={}
- tick = os.startTimer(1)
- convert={
- iro={doll=1},
- gol={doll=10},
- dia={doll=100},
- net={doll=1000},
- atm={doll=10000},
- vib={doll=100000},
- uno={doll=1000000}
- }
- function convertToDollar(list)
- local dollr=0
- for item in list do
- local temp=convert[item.name].doll
- dollr=dollr+(temp*item.amt)
- end
- return dollr
- end
- function convertToItem(amt)
- local list={}
- local txt=amt.."$ converted to:"
- while amt>0 do
- if(amt>=convert.uno.doll)then
- local ni={name="uno",amt=1}
- amt=amt-1000000
- if(list~=nil)then
- if(list[#list].name=="uno")then
- list[#list].amt=list[#list]+1
- else
- table.insert(list,#list+1,ni)
- end
- end
- txt=txt.."\n"..ni.amt.." "..ni.name
- elseif(amt>=convert.vib.doll)then
- local ni={name="vib",amt=1}
- amt=amt-100000
- if(list~=nil)then
- if(list[#list].name=="vib")then
- list[#list].amt=list[#list]+1
- else
- table.insert(list,#list+1,ni)
- end
- end
- txt=txt.."\n"..ni.amt.." "..ni.name
- elseif(amt>=convert.atm.doll)then
- local ni={name="atm",amt=1}
- amt=amt-10000
- if(list~=nil)then
- if(list[#list].name=="atm")then
- list[#list].amt=list[#list]+1
- else
- table.insert(list,#list+1,ni)
- end
- end
- txt=txt.."\n1 "..ni.name
- elseif(amt>=convert.net.doll)then
- local ni={name="net",amt=1}
- amt=amt-1000
- if(list~=nil)then
- if(list[#list].name=="net")then
- list[#list].amt=list[#list]+1
- else
- table.insert(list,#list+1,ni)
- end
- end
- txt=txt.."\n1 "..ni.name
- elseif(amt>=convert.dia.doll)then
- local ni={name="dia",amt=1}
- amt=amt-100
- if(list[#list].name=="dia")then
- list[#list].amt=list[#list]+1
- else
- table.insert(list,#list+1,ni)
- end
- end
- txt=txt.."\n1 "..ni.name
- elseif(amt>=convert.gol.doll)then
- local ni={name="gol",amt=1}
- amt=amt-10
- if(list~=nil)then
- if(list[#list].name=="gol")then
- list[#list].amt=list[#list]+1
- else
- table.insert(list,#list+1,ni)
- end
- end
- txt=txt.."\n1 "..ni.name
- elseif(amt>=convert.iro.doll)then
- local ni={name="iro",amt=1}
- amt=amt-1
- if(list~=nil)then
- if(list[#list].name=="iro")then
- list[#list].amt=list[#list]+1
- else
- table.insert(list,#list+1,ni)
- end
- end
- txt=txt.."\n1 "..ni.name
- end
- end
- return list,amt,txt
- end
- function hasItemsInBank()
- return true
- end
- function transferToOutput(list)
- end
- function truncList(list)
- local li={}
- local o=0
- local prev=""
- for i=1, #list do
- end
- end
- function widraw(usr,a)
- local ac = accounts.getAccount(usr)
- local list,rest,txt=convertToItem(a)
- write(txt,1,1)
- if(ac.cash-a>0)then
- ac.cash=ac.cash-a
- if(hasItemsInBank(list))then
- transferToOutput(list)
- accounts.updateAccount(ac)
- cB.sendMessageToPlayer(txt,usr)
- else
- cB.sendMessageToPlayer("Sorry, the bank, doesnt have enough items for you to pull out.\nTalk to Runnetty for help.",usr)
- end
- else
- cB.sendMessageToPlayer("It seems you are trying to widraw more than you have in your account.",usr)
- end
- end
- while true do
- evt={os.pullEvent()}
- if(evt[1]=="timer")then
- tick=os.startTimer(1)
- else
- players = pD.getPlayersInRange(regDist)
- if(#players>0)then
- if(curUser=="")then
- curUser=players[1]
- cB.sendMessageToPlayer("Welcome,§2 "..curUser.."§f!\nAvailable commands:\n§3!deposit §f(deposits contents in chest, into your account)\n",curUser)
- else
- --We have user!
- if evt[1] =="chat" and evt[2]==curUser then
- local splt={}
- for word in string.gmatch(evt[3], "[^ ]+") do
- table.insert(splt,word)
- end
- write(splt[1].." "..splt[2].."\n",1,1)
- if splt[1]=="!deposit" then
- cB.sendMessageToPlayer("Deposited: ".." into "..curUser.."'s account.",curUser)
- elseif splt[1]=="!widraw" then
- if tonumber(splt[2])~=nil then
- --we have a value
- local v = tonumber(splt[2])
- widraw(curUser,v)
- end
- end
- end
- end
- else
- if(curUser ~="")then
- cB.sendMessageToPlayer("Bai bai "..curUser,curUser)
- curUser=""
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment