SHOW:
|
|
- or go back to the newest paste.
1 | shell.run("rm price") | |
2 | shell.run("pastebin get KkUbsxEG price") | |
3 | is=peripheral.wrap("bottom") | |
4 | money=0 | |
5 | myMoney=0 | |
6 | warten=false | |
7 | ||
8 | function fileToTable(file) | |
9 | if fs.exists(file)~=true then | |
10 | print("file"..file.." not found") | |
11 | return(false) | |
12 | end | |
13 | fp=fs.open(file,"r") | |
14 | line={} | |
15 | i=1 | |
16 | line[i]=fp.readLine() | |
17 | if line[i]==nil then return(false) end | |
18 | while line[i]~=nil do | |
19 | i=i+1 | |
20 | line[i]=fp.readLine() | |
21 | end | |
22 | return(line) | |
23 | end | |
24 | ||
25 | - | term.write("Click here to reset") |
25 | + | |
26 | ||
27 | - | term.write("Money: "..tostring(money)) |
27 | + | function resetItemsBuy() |
28 | itemsBuy={} | |
29 | i=1 | |
30 | while price[i+1]~=nil do | |
31 | itemsBuy[price[i+1]]=0 | |
32 | i=i+3 | |
33 | end | |
34 | end | |
35 | ||
36 | ||
37 | - | e, id, amount =os.pullEvent() |
37 | + | |
38 | function printItemsBuy() | |
39 | i=1 | |
40 | while price[i+1]~=nil do | |
41 | - | money=money+tonumber(price[i+2])*amount |
41 | + | if itemsBuy[price[i+1]]>0 then |
42 | print(price[i+1]..": "..itemsBuy[price[i+1]]) | |
43 | end | |
44 | i=i+3 | |
45 | end | |
46 | - | is.sort(3,amount) |
46 | + | |
47 | ||
48 | - | if e=="key" then |
48 | + | |
49 | - | if id==28 then money=0 end |
49 | + | term.setTextColor(colors.white) |
50 | term.clear() | |
51 | term.setCursorPos(1,1) | |
52 | term.setBackgroundColor(colors.green) | |
53 | term.write("Reset") | |
54 | term.setCursorPos(1,2) | |
55 | if buyPossible then | |
56 | term.setBackgroundColor(colors.green) | |
57 | else | |
58 | term.setBackgroundColor(colors.red) | |
59 | end | |
60 | term.write("Buy") | |
61 | term.setCursorPos(1,3) | |
62 | term.setBackgroundColor(colors.black) | |
63 | printItemsBuy() | |
64 | print("") | |
65 | print("Kosten: "..tostring(money).."$") | |
66 | print("Eingezahlt: "..tostring(myMoney).."$") | |
67 | if warten then | |
68 | print("Bitte warten..") | |
69 | end | |
70 | term.setTextColor(colors.red) | |
71 | if buyPossible==false and money~=0 then | |
72 | print("nicht genug Geld") | |
73 | term.setTextColor(colors.white) | |
74 | end | |
75 | end | |
76 | ||
77 | function main() | |
78 | money=0 | |
79 | resetItemsBuy() | |
80 | printMoney(money) | |
81 | ||
82 | ||
83 | while true do | |
84 | i=1 | |
85 | e, id, amount, yPos =os.pullEvent() | |
86 | if e=="isort_item" then | |
87 | if id~=21256 and id~=30186 and id~=54024 and id~=8792 and id~=119560 then | |
88 | while price[i]~=nil do | |
89 | if id==tonumber(price[i]) then | |
90 | money=money+tonumber(price[i+2])*amount | |
91 | itemsBuy[price[i+1]]=itemsBuy[price[i+1]]+amount | |
92 | printMoney(money) | |
93 | end | |
94 | i=i+3 | |
95 | end | |
96 | is.sort(2,amount) | |
97 | else | |
98 | while price[i]~=nil do | |
99 | if id==tonumber(price[i]) then | |
100 | myMoney=myMoney+tonumber(price[i+2])*amount | |
101 | itemsBuy[price[i+1]]=itemsBuy[price[i+1]]+amount | |
102 | printMoney(money) | |
103 | end | |
104 | i=i+3 | |
105 | end | |
106 | is.sort(2,amount) | |
107 | end | |
108 | end | |
109 | ||
110 | if money~=0 and myMoney>=money then | |
111 | buyPossible=true | |
112 | else | |
113 | buyPossible=false | |
114 | ||
115 | end | |
116 | ||
117 | if e=="monitor_touch" then | |
118 | if yPos==1 then | |
119 | warten=true | |
120 | printMoney(money) | |
121 | money=0 | |
122 | myMoney=0 | |
123 | resetItemsBuy() | |
124 | ||
125 | rs.setBundledOutput("top",colors.red) | |
126 | sleep(1) | |
127 | rs.setBundledOutput("top",0) | |
128 | warten=false | |
129 | end | |
130 | if yPos==2 then | |
131 | if buyPossible then | |
132 | warten=true | |
133 | printMoney(money) | |
134 | myMoney=myMoney-money | |
135 | money=0 | |
136 | resetItemsBuy() | |
137 | rs.setBundledOutput("top",colors.orange) | |
138 | sleep(1) | |
139 | rs.setBundledOutput("top",0) | |
140 | warten=false | |
141 | end | |
142 | end | |
143 | printMoney(money) | |
144 | end | |
145 | sleep(0) | |
146 | end | |
147 | end | |
148 | ||
149 | main() |