View difference between Paste ID: k6mt3p8E and gUSP8jae
SHOW: | | - or go back to the newest paste.
1
local myID = os.getComputerID()
2
while true do  -- 1
3
 znovu = 1
4
 slot = 0
5
 if fs.exists("currentoffer") then  -- pokud jiz existuje ulozena objednavka, nacte se ze souboru currentoffer  2
6
   znovu = 0
7
   slot = 1
8
   fileCO = fs.open("currentoffer", "r")
9
   local line = fileCO.readAll()
10
   fileCO.close()
11
   offertable = textutils.unserialize(line)
12
   
13
   pocet = offertable[1]
14
   jidlo = offertable[2]
15
   cena = offertable[3]
16
      
17
   print("---------------------------")
18
   print("Objednavka: ", pocet, jidlo)
19
   print("Vyplata: ", cena, " kreditu.")
20
   passwordD = "david"
21
   passwordF = "filip"
22
  
23
   local heslonerozpoznano = true
24
   while heslonerozpoznano do    -- overeni heslem 3
25
   	write("Heslo: ")
26
   	local input = read("*")
27
   	if input == passwordD then   -- overeni hesla pro Davida 4
28
      heslonerozpoznano = false
29
      print ("Objednavka prijata. Na ucet David bylo pripsano " .. cena .. " kreditu.")
30
      rednet.open("top")
31
	  rednet.broadcast("poptavka", "ucel")
32
      rednet.broadcast("David","kdo")
33
      rednet.broadcast(cena,"kolik")
34
      slot = 0
35
      hotovot = {}
36
      hotovot[4] = myID
37
 	  hotovot[5] = "F"
38
      local msg = textutils.serialize(hotovot)
39
      rednet.broadcast(msg, "offer")
40
      fs.delete("currentoffer")
41
      sleep(3)
42
      
43
   elseif input == passwordF then  -- overeni hesla pro Filipa
44
      heslonerozpoznano = false
45
      print ("Objednavka prijata. Na ucet Filip bylo pripsano " .. cena .. " kreditu.")
46
      rednet.open("top")
47
	  rednet.broadcast("poptavka", "ucel")
48
      rednet.broadcast("Filip","kdo")
49
      rednet.broadcast(cena,"kolik")
50
      slot = 0
51
      hotovot = {}
52
      hotovot[4] = myID
53
      hotovot[5] = "F"
54
      local msg = textutils.serialize(hotovot)
55
      rednet.broadcast(msg, "offer")
56
      fs.delete("currentoffer")
57
      sleep(3)
58
           
59
   else print("Heslo nerozpoznano") -- pokud se neshoduje heslo
60
   sleep(1)
61
   end -- konec overeni inputu 4E
62
  end  -- ukonceni while loopu pro overeni heslem 3E
63
 
64
 else -- generace nove poptavky pokud neexistuje poptavka 2C
65
   znovu = 1 
66
   rednet.open("top")
67
   while znovu == 1 do       -- generuj, dokud se neuvolni slot 4,5
68
    while slot == 0 do       --generuj, dokud se to nepovede 5
69
    	slot = 1
70
    	sleep(180)
71-
    	n = math.random(1,194)
71+
    	n = math.random(1,190)
72
    	pocet = math.random(32,65)
73
   
74
  		if pocet == 65 then -- 6
75
   		pocet = 128
76
   		end -- 6E
77
78
   
79
   		if n == 1 then -- 7
80
    	slot = 0
81
          
82
   		elseif n == 2 then
83
    	 jidlo = "x PMP spenat"
84
    	 cenajidla = 10
85
        
86
  		 elseif n == 3 then 
87
    	  jidlo = "x PMP okurka"
88
   		  cenajidla = 10
89
            
90
   		elseif n == 4 then
91
    	 jidlo = "x PMP zluta paprika" 
92
   		 cenajidla = 10
93
       
94
   		elseif n == 5 then
95
    	 jidlo = "x PMP salat" 
96
    	 cenajidla = 10
97
   
98
  		elseif n == 6 then
99
    	 jidlo = "x PMP kukurice"
100
    	 cenajidla = 5
101
      
102
  		elseif n == 7 then
103
    	 jidlo = "x obili"
104
    	 cenajidla = 5
105
    
106
   		elseif n == 8 then
107
    	 jidlo = "x cervena repa"
108
    	 cenajidla = 5
109
    
110
   	 	elseif n == 9 then
111
    	 jidlo = "x meloun"
112
    	 cenajidla = 5
113
    
114
   		elseif n == 10 then
115
    	 jidlo = "x PMP divoka ryze"
116
    	 cenajidla = 15
117
    
118
   	 	elseif n == 11 then
119
    	 jidlo = "x jehneci"
120
    	 cenajidla = 20
121
         
122
   	 	elseif n == 12 then
123
    	 jidlo = "x hovezi"
124
    	 cenajidla = 15
125
         
126
   		elseif n >= 13 and n<= 18 then
127
		 cenajidla = 25
128
		 local ryba = math.random(1, 17)
129
		 if ryba == 1  then jidlo = "x ryba"   -- 8
130
    	  elseif ryba == 2  then jidlo = "x HC raw bass"
131
    	  elseif ryba == 3  then jidlo = "x HC raw carp" 
132
    	  elseif ryba == 4  then jidlo = "x HC raw catfish" 
133
    	  elseif ryba == 5  then jidlo = "x HC raw grouper"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
134
    	  elseif ryba == 6  then jidlo = "x HC raw herring"                    
135
    	  elseif ryba == 7  then jidlo = "x HC raw tilapia"
136
          elseif ryba == 8  then jidlo = "x HC raw tuna"
137
    	  elseif ryba == 9  then jidlo = "x HC raw walleye"
138
    	  elseif ryba == 10 then jidlo = "x HC raw green heart fish"
139
		  elseif ryba == 11 then jidlo = "x HC raw charr"
140
		  elseif ryba == 12 then jidlo = "x HC raw mudfish"
141
		  elseif ryba == 13 then jidlo = "x HC raw trout"
142
		  elseif ryba == 14 then jidlo = "x HC raw anchovy"
143
		  elseif ryba == 15 then jidlo = "x HC raw perch"
144
		  elseif ryba == 16 then jidlo = "x HC raw snapper"
145
		  elseif ryba == 17 then jidlo = "x HC raw eel"
146
		 end -- 8E
147
148
   		elseif n == 19 then
149
    	 jidlo = "x HC raw crab"
150
    	 cenajidla = 25
151
    
152
   		elseif n == 20 then
153
    	 jidlo = "x HC raw crayfish"
154
    	 cenajidla = 25
155
                                            
156
   		elseif n == 21 then
157
    	 jidlo = "x HC raw frog"
158
    	 cenajidla = 25
159
    
160
   		elseif n == 22 then
161
    	 jidlo = "x HC raw octopus"
162
    	 cenajidla = 25
163
        
164
   		elseif n == 23 then 
165
    	 jidlo = "x HC raw scallop"
166
    	 cenajidla = 25
167
         
168
   		elseif n == 24 then
169
    	 jidlo = "x HC raw shrimp"
170
    	 cenajidla = 25
171
        
172
   		elseif n == 25 then
173
    	 jidlo = "x HC raw snail"
174
    	 cenajidla = 25
175
     
176
   		elseif n == 26 then
177
    	 jidlo = "x HC raw turtle"
178
    	 cenajidla = 25
179
           
180
   		elseif n == 27 then
181
    	 jidlo = "x HC raw turkey"
182
    	 cenajidla = 50
183
        
184
   		elseif n == 28 then 
185
    	 jidlo = "x HC raw venison"
186
    	 cenajidla = 50
187
        
188
   		elseif n == 29 then
189
    	 jidlo = "x HC raw rabbit"
190
    	 cenajidla = 50
191
       
192
   		elseif n == 30 then
193
    	 jidlo = "x HC raw calamari"
194
   		 cenajidla = 25
195
            
196
   		elseif n == 31 then
197
    	 jidlo = "x losos"			
198
    	 cenajidla = 30                                                                   
199
                
200
   		elseif n == 32 then 
201
    	 jidlo = "x PMP rajce"
202
    	 cenajidla = 10
203
       
204
   		elseif n == 33 then
205
    	 jidlo = "x PMP cibule"
206
    	 cenajidla = 10
207
        
208
   		elseif n == 34 then
209
    	 jidlo = "x mrkev"
210
    	 cenajidla = 10
211
        
212
   		elseif n == 35 then 
213
    	 jidlo = "x PMP peanuts"
214-
    	 cenajidla = 10     
214+
    	 cenajidla = 30     
215
   
216
   		elseif n == 36 then
217
    	 jidlo = "x kaktus"
218
    	 cenajidla = 15
219
        
220
   		elseif n == 37 then
221
    	 jidlo = "x kure"
222
    	 cenajidla = 10
223
        
224
   		elseif n == 38 then
225
    	 jidlo = "x veprove"
226
    	 cenajidla = 20
227
    
228
   		elseif n == 39 then
229
    	 jidlo = "x cukr"
230
    	 cenajidla = 10
231
        
232
   		elseif n == 40 then                
233
    	 jidlo = "x PMP blueberry"
234
    	 cenajidla = 5
235
    
236
   		elseif n == 41 then
237
    	 jidlo = "x PMP strawberry"
238
    	 cenajidla = 5
239
        
240
   		elseif n == 42 then
241
    	 jidlo = "x PMP blackberry"
242
    	 cenajidla = 5
243
        
244
   		elseif n == 43 then
245
    	 jidlo = "x PMP whiteberry" 
246
    	 cenajidla = 5
247
   
248
   		elseif n == 44 then
249
    	 jidlo = "x PMP gooseberry"
250
    	 cenajidla = 5
251
       
252
   		elseif n == 45 then
253
    	 jidlo = "x PMP beautyberry"
254
    	 cenajidla = 5                                                                           
255
     
256
   		elseif n == 46 then
257
    	 jidlo = "x PMP orangeberry"
258
    	 cenajidla = 5
259
    
260
   		elseif n == 47 then
261
    	 jidlo = "x brambory"
262
    	 cenajidla = 5
263
264
  		elseif n == 48 then
265
    	 jidlo = "x HC avocado"
266
    	 cenajidla = 15
267
268
  	 	elseif n == 49 then
269
    	 jidlo = "x HC olive"
270
    	 cenajidla = 15
271
272
  		elseif n == 50 then
273
    	 jidlo = "x HC pea"
274
    	 cenajidla = 5
275
276
  		elseif n == 51 then
277
    	 jidlo = "x HC chilli"
278
    	 cenajidla = 15
279
 
280
  		elseif n == 52 then
281
    	 jidlo = "x HC plum"
282
    	 cenajidla = 5
283
284
  		elseif n == 53 then
285
    	 jidlo = "x HC lemon"
286
    	 cenajidla = 15
287
288
  		elseif n == 54 then
289
    	 jidlo = "x HC tea leaf"
290
    	 cenajidla = 15
291
292
  		elseif n == 55 then
293
    	 jidlo = "x HC soybean"
294
    	 cenajidla = 5
295
296
  		elseif n == 56 then
297
    	 jidlo = "x HC asparagus"
298
    	 cenajidla = 5
299
300
 		elseif n == 57 then
301
    	 jidlo = "x HC garlic"
302
    	 cenajidla = 5
303
304
  		elseif n == 58 then
305
    	 jidlo = "x HC rhubarb"
306
    	 cenajidla = 5
307
308
  		elseif n == 59 then
309
    	 jidlo = "x HC grape"
310
    	 cenajidla = 5
311
312
  		elseif n == 60 then
313
    	 jidlo = "x HC mustard"
314
    	 cenajidla = 5
315
   
316
  		elseif n == 61 then
317
    	 jidlo = "x HC coconut"
318
    	 cenajidla = 15
319
  
320
  		elseif n == 62 then
321
    	 jidlo = "x HC maple syrup"
322
    	 cenajidla = 10  
323
324
  		elseif n == 63 then
325
    	 jidlo = "x HC orange"
326
    	 cenajidla = 15
327
328
  		elseif n == 64 then
329
    	 jidlo = "x HC chestnut"
330
    	 cenajidla = 5
331
332
 		elseif n == 65 then
333
    	 jidlo = "x HC cherry"
334
		 cenajidla = 5
335
336
 		elseif n == 66 then
337
		 jidlo = "x HC banana"
338
		 cenajidla = 15
339
340
 		elseif n == 67 then
341
		 jidlo = "x HC cashew"
342
		 cenajidla = 15
343
344
 		elseif n == 68 then
345
		 jidlo = "x HC grapefruit"
346
		 cenajidla = 15
347
348
 		elseif n == 69 then
349
		 jidlo = "x HC cinnamon"
350-
		 cenajidla = 10
350+
		 cenajidla = 30
351
	
352
 		elseif n == 70 then
353
		 jidlo = "x HC vanilla bean"
354
		 cenajidla = 15
355
356
 		elseif n == 71 then
357
 		 jidlo = "x HC fig"
358
		 cenajidla = 15
359
360
 		elseif n == 72 then
361
		 jidlo = "x HC almond"
362
		 cenajidla = 5
363
364
 		elseif n == 73 then
365
		 jidlo = "x HC pomegranate"
366
		 cenajidla = 15
367
368
 		elseif n == 74 then
369
		 jidlo = "x HC pepper"
370
		 cenajidla = 15
371
372
 		elseif n == 75 then
373
		 jidlo = "x HC broccoli"
374
		 cenajidla = 5
375
 
376
 		elseif n == 76 then
377
		 jidlo = "x HC coffee"
378
		 cenajidla = 15
379
380
 		elseif n == 77 then
381
		 jidlo = "x HC lime"
382
		 cenajidla = 15
383
384
 		elseif n == 78 then
385
		 jidlo = "x HC date"
386
		 cenajidla = 15
387
388
 		elseif n == 79 then
389
		 jidlo = "x HC ginger"
390
		 cenajidla = 15
391
 
392
 		elseif n == 80 then
393
		 jidlo = "x HC zucchini"
394
		 cenajidla = 5
395
396
 		elseif n == 81 then
397
 		 jidlo = "x HC honey"
398
		 cenajidla = 5
399
	
400
 		elseif n == 82 then
401
		 jidlo = "x PC wine grapes"
402
		 cenajidla = 5
403
404
 		elseif n == 83 then
405
		 jidlo = "x eggs"
406
		 cenajidla = 5
407
408-
  		elseif n >= 84 and n<= 96 then
408+
        elseif n == 84 then
409-
    	 jidlo = "x jidlo"
409+
		 jidlo = "x HC peach"
410
	 	 cenajidlo = 5
411
            
412-
 		elseif n >= 97 and n <= 194 then
412+
		elseif n == 85 then
413
		 jidlo = "x HC pistachio"
414
		 cenajidla = 15
415
416
		elseif n == 86 then
417
		 jidlo = "x HC peanut"
418
 		 cenajidla = 15
419
420
		elseif n == 87 then
421
		 jidlo = "x HC celery"
422
		 cenajidla = 5
423
424
		elseif n == 88 then
425
		 jidlo = "x HC onion"
426
		 cenajidla = 5
427
428
		elseif n == 89 then
429
		 jidlo = "x HC apricot"
430
		 cenajidla = 5
431
432
		elseif n == 90 then
433
		 jidlo = "x HC sesame"
434
		 cenajidla = 15
435
436
		elseif n == 91 then
437
		 jidlo = "x HC curry leaves"
438
		 cenajidla = 15
439
		
440
		elseif n == 92 then
441
		 jidlo = "x PC coffee"
442
		 cenajidla = 15
443
444
		elseif n == 93 then
445
		 jidlo = "x PMP sea weed"
446
		 cenajidla = 5
447
448
		elseif n == 94 then
449
		 jidlo = "x PMP mushrooms"
450
		 cenajidla = 5
451
  		       
452
 		elseif n >= 95 and n <= 190 then
453
   	 	 slot = 0 
454
  
455
  		    
456
        end    -- konec rng jidla 7E
457
      end -- konec while loop pro generaci poptavky 5E
458
  
459
    
460
    cena = cenajidla * pocet
461
 	local t = {}           
462
 	t[1] = pocet
463
 	t[2] = jidlo
464
 	t[3] = cena
465
 	t[4] = myID
466
 	t[5] = "F"
467
 	t[6] = "David's Corner"
468
 	local msg = textutils.serialize(t)
469
 	
470
  	rednet.open("top")
471
 	rednet.broadcast(msg, "offer")
472
 	local id, msg = rednet.receive(2)
473
 	if msg == "full" then   -- overi dostupnost slotu - pokud neni volny, opakuj gen 9
474
   		sleep(3)
475
   		znovu = 1
476
   
477
 	else
478
		znovu = 0
479
   		print("-----------------------------")  -- pokud je volny slot, vypis poptavku
480
   		print("Objednavka: ", pocet, jidlo)
481
   		print("Vyplata: ", cena," kreditu.")
482
   
483
   		local savetable = {}
484
   		cena = cenajidla * pocet
485
   		savetable[1] = pocet
486
   		savetable[2] = jidlo
487
   		savetable[3] = cena
488
   
489
   		local fileWT = fs.open("currentoffer", "w")
490
   		fileWT.write(textutils.serialize(savetable))
491
   		fileWT.close()
492
   
493
        passwordD = "david"
494
 		passwordF = "filip"
495
  
496
 		local heslonerozpoznano = true
497
 		while heslonerozpoznano do   -- 10
498
   			write("Heslo: ")
499
   			local input = read("*")
500
   			if input == passwordD then -- 11
501
      			heslonerozpoznano = false
502
      			print ("Objednavka prijata. Na ucet David bylo pripsano " .. cena .. " kreditu.")
503
      			rednet.open("top")
504
	  			rednet.broadcast("poptavka", "ucel")
505
      			rednet.broadcast("David","kdo")
506
      			rednet.broadcast(cena,"kolik")
507
      			slot = 0
508
      			hotovot = {}
509
 				hotovot[4] = myID
510
 				hotovot[5] = "F"
511
 				local msg = textutils.serialize(hotovot)
512
 			 	rednet.broadcast(msg, "offer")
513
 				fs.delete("currentoffer")
514
 				sleep(3)
515
      
516
   			elseif input == passwordF then
517
      			heslonerozpoznano = false
518
      			print ("Objednavka prijata. Na ucet Filip bylo pripsano " .. cena .. " kreditu.")
519
      			rednet.open("top")
520
	  			rednet.broadcast("poptavka", "ucel")
521
      			rednet.broadcast("Filip","kdo")
522
      			rednet.broadcast(cena,"kolik")
523
      			slot = 0
524
      			hotovot = {}
525
 				hotovot[4] = myID
526
 				hotovot[5] = "F"
527
 				local msg = textutils.serialize(hotovot)
528
 				rednet.broadcast(msg, "offer")
529
 				fs.delete("currentoffer")
530
 				sleep(3)
531
           
532
   			else print("Heslo nerozpoznano")
533
   			sleep(1)
534
   			end      -- konec overeni hesla 11E
535
  		end  -- konec loopu pro heslo 10E
536
  	end  -- konec overeni dostupnosti slotu 9E
537
    end -- konec znovu loopu 4,5E
538
    znovu = 1
539
   end -- konec while loopu pro gen poptavky 2E
540
  end -- konec if statement pro overeni existence currentoffer 1E