View difference between Paste ID: N0EAX9vM and LTWfiLUV
SHOW: | | - or go back to the newest paste.
1
function showacc()
2
 cteniD()
3
 cteniF()
4
 print("David: " .. ucetD)
5
 print("Filip: " .. ucetF)
6
 print("---------------")
7
 print(" ") 
8
end 
9
10
function zapisD()
11
 local fileD = fs.open("ucetDf", "w")
12
 fileD.writeLine(ucetD)
13
 fileD.close() 
14
end
15
16
function zapisF()
17
 local fileF = fs.open("ucetFf", "w")
18
 fileF.writeLine(ucetF)
19
 fileF.close()
20
end 
21
22
function cteniD()
23
 local fileD = fs.open("ucetDf", "r")
24
 ucetDs = fileD.readLine()
25
 ucetD = tonumber(ucetDs)
26
 if ucetD == nil then
27
  ucetD = 0
28
 end
29
 fileD.close()
30
end
31
32
function cteniF()
33
 local fileF = fs.open("ucetFf", "r")
34
 ucetFs = fileF.readLine()
35
 ucetF = tonumber(ucetFs)
36
 if ucetF == nil then
37
  ucetF = 0
38
 end
39
 fileF.close() 
40
end
41
42
43
44
--zacatek
45
if fs.exists("ucetDf") then
46
47
showacc()
48
rednet.open("top")
49
while true do
50
 local id, msgwhat, protocol = rednet.receive("ucel")
51
 
52
 if msgwhat == "poptavka" then
53
 local id, msgwho, protocol = rednet.receive("kdo")
54
 local id, msghowmuch, protocol = rednet.receive("kolik")
55
 vydelek = tonumber(msghowmuch)
56
  
57
  if msgwho == "David"
58
  then 
59
  cteniD()
60
  showacc()
61
  ucetD = ucetD + vydelek
62
  zapisD()
63
  end
64
  
65
  if msgwho == "Filip"
66
  then
67
  cteniF()
68
  ucetF = ucetF + vydelek
69
  zapisF()  
70
  end
71
 
72
  showacc()
73
  
74
  elseif msgwhat == "admin" then
75
  
76
  local id, msgwho, protocol = rednet.receive("kdo")
77
  local id, msghowmuch, protocol = rednet.receive("kolik")
78
  cheaty = tonumber(msghowmuch)
79
   
80
   if msgwho == "David" then
81
    cteniD()
82
    ucetD = ucetD + cheaty
83
    zapisD()
84
    showacc() 
85
   
86
   elseif msgwho == "Filip" then
87
    cteniF()
88
    ucetF = ucetF + cheaty
89
    zapisF()
90
    showacc()
91
   end 
92
  
93
  elseif msgwhat == "bankomat" then
94
  
95
   local id, msgwho, protocol = rednet.receive("kdo")
96
   local id, msghowmuch, protocol = rednet.receive("kolik")
97
   transfer = tonumber(msghowmuch)
98
   
99
   if msgwho == "David" then
100
   cteniD()
101
   cteniF()
102
   ucetF = ucetF - transfer
103
   ucetD = ucetD + transfer
104
   zapisD()
105
   zapisF()
106
   showacc()
107
   
108
   elseif msgwho == "Filip" then
109
   cteniD()
110
   cteniF()
111
   ucetD = ucetD - transfer
112
   ucetF = ucetF + transfer
113
   zapisD()
114
   zapisF()
115
   showacc()
116
   end
117
   
118
  elseif msgwhat == "requeststate" then
119
  local id, msgid, protocol = rednet. receive("id")
120
  local id, msgwho, protocol = rednet.receive("kdo")
121
   if msgwho == "David" then
122
   cteniD()
123
   rednet.send(msgid, ucetD)
124
   
125
   elseif msgwho == "Filip" then
126
   cteniF()
127
   rednet.send(msgid, ucetF)
128
   end
129
          
130
  end
131
end
132
else
133
 local ucetD = 0
134
 local ucetF = 0
135
 zapisD()
136
 zapisF()
137
  
138
end
139
os.reboot()