SHOW:
|
|
- or go back to the newest paste.
1 | local slot = 0 | |
2 | local myID = os.getComputerID() | |
3 | ||
4 | - | function hotovo() |
4 | + | |
5 | - | hotovot = {} |
5 | + | |
6 | ||
7 | - | hotovot[5] = "M" |
7 | + | |
8 | local line = fileCO.readAll() | |
9 | fileCO.close() | |
10 | offertable = textutils.unserialize(line) | |
11 | ||
12 | - | sleep(320) |
12 | + | |
13 | - | end |
13 | + | |
14 | cena = offertable[3] | |
15 | - | function password() |
15 | + | |
16 | - | passwordD = "david" |
16 | + | |
17 | print("Objednavka: ", pocet, jidlo) | |
18 | print("Vyplata: ", cena, " kreditu.") | |
19 | passwordD = "david" | |
20 | passwordF = "filip" | |
21 | ||
22 | local heslonerozpoznano = true | |
23 | while heslonerozpoznano do | |
24 | write("Heslo: ") | |
25 | local input = read("*") | |
26 | if input == passwordD | |
27 | then | |
28 | heslonerozpoznano = false | |
29 | print ("Objednavka prijata. Na ucet David bylo pripsano " .. cena .. " kreditu.") | |
30 | rednet.open("top") | |
31 | rednet.broadcast("poptavka", "ucel") | |
32 | - | hotovo() |
32 | + | |
33 | rednet.broadcast(cena,"kolik") | |
34 | slot = slot - 1 | |
35 | hotovot = {} | |
36 | hotovot[4] = myID | |
37 | hotovot[5] = "F" | |
38 | local msg = textutils.serialize(hotovot) | |
39 | rednet.open("top") | |
40 | rednet.broadcast(msg, "offer") | |
41 | fs.delete("currentoffer") | |
42 | sleep(3) | |
43 | - | hotovo() |
43 | + | |
44 | elseif input == passwordF | |
45 | then | |
46 | heslonerozpoznano = false | |
47 | print ("Objednavka prijata. Na ucet Filip bylo pripsano " .. cena .. " kreditu.") | |
48 | rednet.open("top") | |
49 | - | end |
49 | + | |
50 | rednet.broadcast("Filip","kdo") | |
51 | - | function vyplata() |
51 | + | |
52 | - | sendtable() |
52 | + | |
53 | hotovot = {} | |
54 | hotovot[4] = myID | |
55 | hotovot[5] = "F" | |
56 | - | sleep(320) |
56 | + | |
57 | rednet.open("top") | |
58 | rednet.broadcast(msg, "offer") | |
59 | fs.delete("currentoffer") | |
60 | sleep(3) | |
61 | ||
62 | else print("Heslo nerozpoznano") | |
63 | sleep(1) | |
64 | end | |
65 | end | |
66 | ||
67 | else | |
68 | local vacancy = 1 | |
69 | while vacancy == 1 do | |
70 | rednet.open("top") | |
71 | while slot == 0 do | |
72 | slot = slot + 1 | |
73 | n = math.random(1,18) | |
74 | - | password() |
74 | + | |
75 | ||
76 | - | end |
76 | + | |
77 | slot = slot - 1 | |
78 | - | function sendtable() |
78 | + | |
79 | - | cena = cenajidla * pocet |
79 | + | |
80 | jidlo = "stack(s) of strings" | |
81 | cenajidla = 320 | |
82 | ||
83 | elseif n == 3 then | |
84 | jidlo = "stack(s) of wool" | |
85 | - | t[5] = "M" |
85 | + | |
86 | ||
87 | elseif n == 4 then | |
88 | jidlo = "stack(s) of stone" | |
89 | cenajidla = 640 | |
90 | - | end |
90 | + | |
91 | elseif n == 5 then | |
92 | jidlo = "stack(s) of glass" | |
93 | - | function offergen() |
93 | + | |
94 | - | while slot == 0 do |
94 | + | |
95 | elseif n == 6 then | |
96 | jidlo = "stack(s) of sandstone" | |
97 | cenajidla = 960 | |
98 | ||
99 | elseif n == 7 then | |
100 | jidlo = "stack(s) of acacia wood planks" | |
101 | cenajidla = 320 | |
102 | ||
103 | elseif n == 8 then | |
104 | jidlo = "stack(s) of birch wood planks" | |
105 | cenajidla = 320 | |
106 | ||
107 | elseif n >= 9 and n<= 18 then | |
108 | slot = slot - 1 | |
109 | ||
110 | end | |
111 | end | |
112 | ||
113 | vacancy = vacancy - 1 | |
114 | cena = cenajidla * pocet | |
115 | local t = {} | |
116 | t[1] = pocet | |
117 | t[2] = jidlo | |
118 | t[3] = cena | |
119 | t[4] = myID | |
120 | t[5] = "F" | |
121 | t[6] = "Akka Constructions" | |
122 | local msg = textutils.serialize(t) | |
123 | rednet.open("top") | |
124 | rednet.broadcast(msg, "offer") | |
125 | ||
126 | ||
127 | local id, msg = rednet.receive(2) | |
128 | if msg == "full" then | |
129 | sleep(3) | |
130 | slot = 0 | |
131 | - | slot = slot - 1 |
131 | + | |
132 | else | |
133 | print("-----------------------------") | |
134 | print("Objednavka: ", pocet, jidlo) | |
135 | - | end |
135 | + | |
136 | ||
137 | - | function checkreq() |
137 | + | |
138 | cena = cenajidla * pocet | |
139 | savetable[1] = pocet | |
140 | savetable[2] = jidlo | |
141 | savetable[3] = cena | |
142 | ||
143 | local fileWT = fs.open("currentoffer", "w") | |
144 | fileWT.write(textutils.serialize(savetable)) | |
145 | fileWT.close() | |
146 | ||
147 | passwordD = "david" | |
148 | passwordF = "filip" | |
149 | ||
150 | local heslonerozpoznano = true | |
151 | while heslonerozpoznano do | |
152 | write("Heslo: ") | |
153 | - | password() |
153 | + | |
154 | if input == passwordD | |
155 | then | |
156 | heslonerozpoznano = false | |
157 | print ("Objednavka prijata. Na ucet David bylo pripsano " .. cena .. " kreditu.") | |
158 | rednet.open("top") | |
159 | - | offergen() |
159 | + | |
160 | rednet.broadcast("David","kdo") | |
161 | rednet.broadcast(cena,"kolik") | |
162 | - | vyplata() |
162 | + | |
163 | hotovot = {} | |
164 | hotovot[4] = myID | |
165 | hotovot[5] = "F" | |
166 | - | end |
166 | + | |
167 | - | end |
167 | + | |
168 | rednet.broadcast(msg, "offer") | |
169 | fs.delete("currentoffer") | |
170 | - | |
170 | + | sleep(3) |
171 | - | checkreq() |
171 | + | |
172 | elseif input == passwordF | |
173 | then | |
174 | heslonerozpoznano = false | |
175 | print ("Objednavka prijata. Na ucet Filip bylo pripsano " .. cena .. " kreditu.") | |
176 | rednet.open("top") | |
177 | rednet.broadcast("poptavka", "ucel") | |
178 | rednet.broadcast("Filip","kdo") | |
179 | rednet.broadcast(cena,"kolik") | |
180 | slot = slot - 1 | |
181 | hotovot = {} | |
182 | hotovot[4] = myID | |
183 | hotovot[5] = "F" | |
184 | local msg = textutils.serialize(hotovot) | |
185 | rednet.open("top") | |
186 | rednet.broadcast(msg, "offer") | |
187 | fs.delete("currentoffer") | |
188 | sleep(3) | |
189 | ||
190 | else print("Heslo nerozpoznano") | |
191 | sleep(1) | |
192 | end | |
193 | end | |
194 | end | |
195 | vacancy = vacancy + 1 | |
196 | end | |
197 | end | |
198 | end |