View difference between Paste ID: JjPwgmU7 and JtZU2vF6
SHOW: | | - or go back to the newest paste.
1
usernamesetup = "tomtrein"
2
3
turtleid = 116
4
settings = {}
5
6
num = 0
7
8
file = fs.open("settings", "r")
9
istrue = true
10
i = 0
11
while istrue do
12
i = i+1
13
string1 = file.readLine()
14
if string1==nill then
15
  istrue = false
16
  break
17
end
18
string2 = file.readLine()
19
settings[i] = string2
20
end
21
22
if not settings[4]==nill then
23
  order = settings[4]=="true"
24
else
25
  order = false
26
end
27
28
file.close()
29
30
turtleid = tonumber(settings[3])
31
32
banking = function()
33
term.setTextColor(colors.black)
34
term.setBackgroundColor(colors.white)
35
term.clear()
36
local image = paintutils.loadImage("bank")
37
paintutils.drawImage(image, 1, 1)
38
term.setCursorPos(16, 8)
39
term.write("Please input card")
40
while not disk.hasData(settings[1]) do
41
  os.queueEvent("randomEvent")
42
  os.pullEvent()
43
end
44
term.setTextColor(colors.black)
45
term.setBackgroundColor(colors.white)
46
term.clear()
47
local image = paintutils.loadImage("bank")
48
paintutils.drawImage(image, 1, 1)
49
term.setCursorPos(16, 8)
50
term.write("Please enter code")
51
code = ""
52
for i=1, 4 do
53
  ponies=false
54
  while not ponies do
55
    local event, key = os.pullEvent("key")
56
    if key>1 and key<11 then
57
      amount = key-1
58
      ponies = true
59
    end
60
  end
61
  code = code..amount
62
  paintutils.drawImage(image, 1, 1)
63
  term.setCursorPos(16, 10)
64
  term.setBackgroundColor(colors.lightBlue)
65
  term.write(code)
66
end
67
68
shell.run("delete", "disk/temp")
69
shell.run("cp", "disk/money", "disk/temp")
70
71
file = fs.open("disk/temp", "r")
72
stringcode = file.readLine()
73
file.close()
74
shell.run("delete", "disk/temp")
75
76
stringcode = string.sub(stringcode, 5, -5)
77
78
file = fs.open("disk/temp", "w")
79
file.writeLine(stringcode)
80
file.close()
81
82
shell.run("decrypt", "disk/temp", code)
83
84
file = fs.open("disk/temp", "r")
85
stringcode = tonumber(file.readLine())
86
file.close()
87
88
89
shell.run("delete", "disk/temp")
90
91
if stringcode == nill then
92
  return "n"
93
else
94
95
stringcode = stringcode - price
96
97
if stringcode < 0 then
98
  return "n"
99
else
100
101
stringcode = math.random(9)..math.random(9)..math.random(9)..math.random(9)..stringcode..math.random(9)..math.random(9)..math.random(9)..math.random(9)
102
103
file = fs.open("disk/temp", "w")
104
file.writeLine(stringcode)
105
file.close()
106
107
shell.run("crypt", "disk/temp", code, "f")
108
109
shell.run("delete", "disk/money")
110
111
shell.run("cp", "disk/temp", "disk/money")
112
113
shell.run("delete", "disk/temp")
114
115
return "y"
116
end
117
end
118
end
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
term.setTextColor(colors.black)
135
term.setBackgroundColor(colors.white)
136
term.clear()
137
local image = paintutils.loadImage("recipe")
138
paintutils.drawImage(image, 13, 5)
139
140
term.setBackgroundColor(colors.white)
141
term.setCursorPos(14, 6)
142
term.write("Username")
143
term.setCursorPos(14, 9)
144
term.write("Purchase")
145
term.setCursorPos(29, 9)
146
term.write("*")
147
term.setCursorPos(14, 11)
148
term.write("Cost:")
149
150
list = fs.open("items", "r")
151
152
intrue = true
153
while intrue do
154
  local event, button, x, y = os.pullEvent( "mouse_click" )
155
  if y==7 and x>14 and x<28 then
156
    paintutils.drawLine(15,7,27,7,colors.lightBlue)
157
    term.setBackgroundColor(colors.lightBlue)
158
    term.setCursorPos(14, 7)
159
    user = read()
160
    if user == usernamesetup then
161
      shell.run("fg")
162
    end
163
    if user == settings[2] then
164
      shell.run("menu")
165
    end
166
  end
167
  if y==10 and x>14 and x<28 then
168
    term.setBackgroundColor(colors.lightBlue)
169
    term.setCursorPos(15,10)
170
    term.write("go up")
171
    ponies=false
172
    while not ponies do
173
      local event, key = os.pullEvent("key")
174
      if key == keys.enter then
175
        ponies = true
176
      end
177
      if key == keys.up then
178
        paintutils.drawLine(15,10,27,10,colors.lightBlue)
179
        term.setCursorPos(15,10)
180
        num = num+1
181
        toprint = list.readLine()
182
        cost = list.readLine()
183
        if cost == nill or toprint == nill then
184
          list.close()
185
          list = fs.open("items", "r")
186
          toprint = list.readLine()
187
          cost = list.readLine()
188
          num = 1
189
        end
190
        term.write(toprint)
191
        thitemchosen = toprint
192
      end
193
    end
194
  end
195
  if y==10 and x==29 then
196
    term.setCursorPos(29, 10)
197
    ponies=false
198
    while not ponies do
199
    local event, key = os.pullEvent("key")
200
    if key>1 and key<11 then
201
    amount = key-1
202
    paintutils.drawLine(29,10,29,10,colors.lightBlue)
203
    term.setBackgroundColor(colors.lightBlue)
204
    term.setCursorPos(29, 10)
205
    term.write(amount)
206
    ponies = true
207
      paintutils.drawLine(15,12,22,12,colors.lightBlue)
208
      term.setCursorPos(15,12)
209
      price = tonumber(cost)*amount
210
      amount2020 = amount
211
      term.write(price)
212
    end
213
    end
214
  end
215
  if y==13 and x>32 and x<37 then
216
    if price == nill and user == nill then
217
    else
218
      intrue = false
219
    end
220
  end
221
end
222
223
if banking()=="y" then
224
  term.setBackgroundColor(colors.white)
225
  term.clear()
226
  local image = paintutils.loadImage("bank-ok")
227
  term.setCursorPos(1,1)
228
  paintutils.drawImage(image, 1, 1)
229
else
230
  term.setBackgroundColor(colors.white)
231
  term.clear()
232
  local image = paintutils.loadImage("bank-bad")
233
  term.setCursorPos(1,1)
234
  paintutils.drawImage(image, 1, 1)
235
  os.sleep(3)
236
  os.reboot()
237
end
238
239
if not fs.exists("money") then
240
file = fs.open("money", "w")
241
file.writeLine("0")
242
file.close()
243
end
244
245
file = fs.open("money", "r")
246
money = tonumber(file.readLine())
247
if money==nill then
248
  money=price
249
else
250
money = money+price
251
end
252
file.close()
253
shell.run("delete", "money")
254
255
file = fs.open("money", "w")
256
file.writeLine(money)
257
file.close()
258
259-
rednet.open("top")
259+
  temp = fs.open(user, "w")
260-
rednet.send(turtleid, amount2020)
260+
  temp.writeLine(thitemchosen)
261-
rednet.send(turtleid, num)
261+
  temp.writeLine(amount2020)
262-
  os.sleep(1)
262+
  temp.writeLine(user)
263
  temp.close()
264
temp = fs.open("jobs", "a")
265
temp.writeLine(user)
266
temp.close()
267
  os.reboot()