Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shell.run("rm price")
- shell.run("pastebin get KkUbsxEG price")
- is=peripheral.wrap("bottom")
- money=0
- myMoney=0
- warten=false
- 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 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)
- printItemsBuy()
- print("")
- print("Kosten: "..tostring(money).."$")
- print("Eingezahlt: "..tostring(myMoney).."$")
- 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 main()
- money=0
- resetItemsBuy()
- printMoney(money)
- while true do
- i=1
- 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=="monitor_touch" then
- if yPos==1 then
- warten=true
- printMoney(money)
- money=0
- myMoney=0
- resetItemsBuy()
- rs.setBundledOutput("top",colors.red)
- sleep(1)
- rs.setBundledOutput("top",0)
- warten=false
- end
- if yPos==2 then
- if buyPossible then
- warten=true
- printMoney(money)
- myMoney=myMoney-money
- money=0
- resetItemsBuy()
- rs.setBundledOutput("top",colors.orange)
- sleep(1)
- rs.setBundledOutput("top",0)
- warten=false
- end
- end
- printMoney(money)
- end
- sleep(0)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement