View difference between Paste ID: NsZYx2Az and e2heDwda
SHOW: | | - or go back to the newest paste.
1
os.pullEvent=os.pullEventRaw
2-
shell.run("pastebin get KkUbsxEG price")
2+
3
shell.run("pastebin get sAgujPt7 price")
4
is=peripheral.wrap("bottom")
5
p=peripheral.wrap("right")
6
money=0
7
myMoney=0
8
warten=false
9
user="No User"
10
payIn=false
11
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"}
12
code="XXXX"
13
14
15
16
function saveTab(file,tab)
17
fp=fs.open(file,"w")
18
fp.write(textutils.serialize(tab))
19
fp.close()
20
end
21
 
22
function getTab(file)
23
fp=fs.open(file,"r")
24
return textutils.unserialize(fp.readAll())
25
end
26
27
if fs.exists(".codes")==false then
28
codes={}
29
saveTab(".codes",codes)
30
end
31
codes=getTab(".codes")
32
33
if fs.exists(".account")==false then
34
account={}
35
account["No User"]=0
36
saveTab(".account",account)
37
end
38
account=getTab(".account")
39
40
function fileToTable(file)
41
if fs.exists(file)~=true then
42
print("file"..file.." not found")
43
return(false)
44
end
45
fp=fs.open(file,"r")
46
line={}
47
i=1
48
line[i]=fp.readLine()
49
if line[i]==nil then return(false) end
50
while line[i]~=nil do
51
i=i+1
52
line[i]=fp.readLine()
53
end
54
return(line)
55
end
56
57
price=fileToTable("price")
58
59
function resetItemsBuy()
60
itemsBuy={}
61
i=1
62
while price[i+1]~=nil do
63
itemsBuy[price[i+1]]=0
64
i=i+3
65
end
66
end
67
68
function generateCode()
69
code=codeChars[math.random(1,#codeChars)]
70
for i=1,3 do
71
code=code..codeChars[math.random(1,#codeChars)]
72
end
73
codes=getTab(".codes")
74
codes[code]=250
75
saveTab(".codes",codes)
76
p.newPage()
77
p.write(code)
78
p.endPage()
79
end
80
81
function printItemsBuy()
82
i=1
83
while price[i+1]~=nil do
84
if itemsBuy[price[i+1]]>0 then
85
print(price[i+1]..": "..itemsBuy[price[i+1]])
86
end
87
i=i+3
88
end
89
end
90
91
function printMoney(money)
92
term.setTextColor(colors.white)
93
term.clear()
94
term.setCursorPos(1,1)
95
term.setBackgroundColor(colors.green)
96
term.write("Reset")
97
term.setCursorPos(1,2)
98
if buyPossible then
99
term.setBackgroundColor(colors.green)
100
else
101
term.setBackgroundColor(colors.red)
102
end
103
term.write("Buy")
104
term.setCursorPos(1,3)
105
term.setBackgroundColor(colors.black)
106
term.write(user)
107
term.setCursorPos(1,4)
108
term.setBackgroundColor(colors.green)
109
term.write("Einzahlen")
110
term.setCursorPos(1,5)
111
term.setBackgroundColor(colors.green)
112
term.write("Ausloggen")
113
term.setCursorPos(1,6)
114
term.setBackgroundColor(colors.black)
115
printItemsBuy()
116
print("")
117
print("Kosten: "..tostring(money).."$")
118
print("Eingezahlt: "..tostring(myMoney).."$")
119
if payIn==true then
120
print("Bitte Code eingeben")
121
end
122
if warten then
123
print("Bitte warten..")
124
end
125-
rs.setBundledOutput("top",colors.red)
125+
126
if buyPossible==false and money~=0 then
127-
rs.setBundledOutput("top",0)
127+
128
term.setTextColor(colors.white)
129
end
130
end
131
132
function paying()
133
if user~="No User" then
134-
myMoney=myMoney-money
134+
if account[user]==nil then
135
account[user]=0
136
end
137-
rs.setBundledOutput("top",colors.orange)
137+
payIn=true
138
printMoney(money)
139-
rs.setBundledOutput("top",0)
139+
codes=getTab(".codes")
140
inputCode=io.read()
141
if codes[inputCode] then
142
account[user]=account[user]+250
143
saveTab(".account",account)
144
codes[inputCode]=nil
145
saveTab(".codes",codes)
146
myMoney=account[user]
147
end
148
payIn=false
149
printMoney(money)
150
end
151
end
152
153
function main()
154
myMoney=account[user]
155
resetItemsBuy()
156
printMoney(money)
157
158
159
while true do
160
printMoney(money)
161
i=1
162
yPos=0
163
e, id, amount, yPos =os.pullEvent()
164
if e=="isort_item" then
165
if id~=21256 and id~=30186 and id~=54024 and id~=8792 and id~=119560 then
166
while price[i]~=nil do
167
if id==tonumber(price[i]) then 
168
money=money+tonumber(price[i+2])*amount
169
itemsBuy[price[i+1]]=itemsBuy[price[i+1]]+amount
170
printMoney(money) 
171
end
172
i=i+3
173
end
174
is.sort(2,amount) 
175
else
176
while price[i]~=nil do
177
if id==tonumber(price[i]) then 
178
myMoney=myMoney+tonumber(price[i+2])*amount
179
itemsBuy[price[i+1]]=itemsBuy[price[i+1]]+amount
180
printMoney(money) 
181
end
182
i=i+3
183
end
184
is.sort(2,amount) 
185
end
186
end
187
188
if money~=0 and myMoney>=money then
189
buyPossible=true
190
else
191
buyPossible=false
192
193
end
194
195
if e=="key" then
196
if id==38 then
197
if user=="ecco7777" then
198
i=u+"was?"
199
end
200
end
201
end
202
203
if e=="player" then
204
user=id
205
myMoney=account[user]
206
printMoney(money)
207
end
208
209
if e=="monitor_touch" then
210
if yPos==1 then
211
warten=true
212
printMoney(money)
213
money=0
214
resetItemsBuy()
215
216
rs.setBundledOutput("back",colors.red)
217
sleep(1)
218
rs.setBundledOutput("back",0)
219
warten=false
220
end
221
222
if yPos==2 then
223
	if buyPossible then
224
		warten=true
225
		printMoney(money)
226
		myMoney=myMoney-money
227
		account[user]=myMoney
228
		saveTab(".account",account)
229
		money=0
230
		resetItemsBuy()
231
		rs.setBundledOutput("back",colors.orange)
232
		sleep(1)
233
		rs.setBundledOutput("back",0)
234
		warten=false
235
	end
236
end
237
238
if yPos==4 then 
239
	paying()
240
end
241
242
if yPos==5 then
243
user="No User"
244
myMoney=0
245
end
246
247
printMoney(money)
248
end
249
sleep(0)
250
end
251
end
252
253
main()