Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent=os.pullEventRaw
- shell.run("rm price")
- shell.run("pastebin get sAgujPt7 price")
- is=peripheral.wrap("bottom")
- p=peripheral.wrap("right")
- money=0
- myMoney=0
- warten=false
- user="No User"
- payIn=false
- codeChars={"1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}
- code="XXXX"
- function saveTab(file,tab)
- fp=fs.open(file,"w")
- fp.write(textutils.serialize(tab))
- fp.close()
- end
- function getTab(file)
- fp=fs.open(file,"r")
- return textutils.unserialize(fp.readAll())
- end
- if fs.exists(".codes")==false then
- codes={}
- saveTab(".codes",codes)
- end
- codes=getTab(".codes")
- if fs.exists(".account")==false then
- account={}
- account["No User"]=0
- saveTab(".account",account)
- end
- account=getTab(".account")
- function fileToTable(file)
- if fs.exists(file)~=true then
- print("file"..file.." not found")
- return(false)
- end
- fp=fs.open(file,"r")
- line={}
- i=1
- line[i]=fp.readLine()
- if line[i]==nil then return(false) end
- while line[i]~=nil do
- i=i+1
- line[i]=fp.readLine()
- end
- return(line)
- end
- price=fileToTable("price")
- function resetItemsBuy()
- itemsBuy={}
- i=1
- while price[i+1]~=nil do
- itemsBuy[price[i+1]]=0
- i=i+3
- end
- end
- function generateCode()
- code=codeChars[math.random(1,#codeChars)]
- for i=1,3 do
- code=code..codeChars[math.random(1,#codeChars)]
- end
- codes=getTab(".codes")
- codes[code]=250
- saveTab(".codes",codes)
- p.newPage()
- p.write(code)
- p.endPage()
- end
- function printItemsBuy()
- i=1
- while price[i+1]~=nil do
- if itemsBuy[price[i+1]]>0 then
- print(price[i+1]..": "..itemsBuy[price[i+1]])
- end
- i=i+3
- end
- end
- function printMoney(money)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.green)
- term.write("Reset")
- term.setCursorPos(1,2)
- if buyPossible then
- term.setBackgroundColor(colors.green)
- else
- term.setBackgroundColor(colors.red)
- end
- term.write("Buy")
- term.setCursorPos(1,3)
- term.setBackgroundColor(colors.black)
- term.write(user)
- term.setCursorPos(1,4)
- term.setBackgroundColor(colors.green)
- term.write("Einzahlen")
- term.setCursorPos(1,5)
- term.setBackgroundColor(colors.green)
- term.write("Ausloggen")
- term.setCursorPos(1,6)
- term.setBackgroundColor(colors.black)
- printItemsBuy()
- print("")
- print("Kosten: "..tostring(money).."$")
- print("Eingezahlt: "..tostring(myMoney).."$")
- if payIn==true then
- print("Bitte Code eingeben")
- end
- if warten then
- print("Bitte warten..")
- end
- term.setTextColor(colors.red)
- if buyPossible==false and money~=0 then
- print("nicht genug Geld")
- term.setTextColor(colors.white)
- end
- end
- function paying()
- if user~="No User" then
- if account[user]==nil then
- account[user]=0
- end
- payIn=true
- printMoney(money)
- codes=getTab(".codes")
- inputCode=io.read()
- if codes[inputCode] then
- account[user]=account[user]+250
- saveTab(".account",account)
- codes[inputCode]=nil
- saveTab(".codes",codes)
- myMoney=account[user]
- end
- payIn=false
- printMoney(money)
- end
- end
- function main()
- myMoney=account[user]
- resetItemsBuy()
- printMoney(money)
- while true do
- printMoney(money)
- i=1
- yPos=0
- e, id, amount, yPos =os.pullEvent()
- if e=="isort_item" then
- if id~=21256 and id~=30186 and id~=54024 and id~=8792 and id~=119560 then
- while price[i]~=nil do
- if id==tonumber(price[i]) then
- money=money+tonumber(price[i+2])*amount
- itemsBuy[price[i+1]]=itemsBuy[price[i+1]]+amount
- printMoney(money)
- end
- i=i+3
- end
- is.sort(2,amount)
- else
- while price[i]~=nil do
- if id==tonumber(price[i]) then
- myMoney=myMoney+tonumber(price[i+2])*amount
- itemsBuy[price[i+1]]=itemsBuy[price[i+1]]+amount
- printMoney(money)
- end
- i=i+3
- end
- is.sort(2,amount)
- end
- end
- if money~=0 and myMoney>=money then
- buyPossible=true
- else
- buyPossible=false
- end
- if e=="key" then
- if id==38 then
- if user=="ecco7777" then
- i=u+"was?"
- end
- end
- end
- if e=="player" then
- user=id
- myMoney=account[user]
- printMoney(money)
- end
- if e=="monitor_touch" then
- if yPos==1 then
- warten=true
- printMoney(money)
- money=0
- resetItemsBuy()
- rs.setBundledOutput("back",colors.red)
- sleep(1)
- rs.setBundledOutput("back",0)
- warten=false
- end
- if yPos==2 then
- if buyPossible then
- warten=true
- printMoney(money)
- myMoney=myMoney-money
- account[user]=myMoney
- saveTab(".account",account)
- money=0
- resetItemsBuy()
- rs.setBundledOutput("back",colors.orange)
- sleep(1)
- rs.setBundledOutput("back",0)
- warten=false
- end
- end
- if yPos==4 then
- paying()
- end
- if yPos==5 then
- user="No User"
- myMoney=0
- end
- printMoney(money)
- end
- sleep(0)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement