View difference between Paste ID: BUrAgjFE and XwZfZawM
SHOW: | | - or go back to the newest paste.
1-
shell.run("rm lista_barboni")
1+
margherita = "right"
2-
rs.setOutput("left", false)
2+
marinara = "bottom"
3-
rs.setOutput("top", false)
3+
allowed = "left"
4-
local interrupt = os.setAlarm(0)
4+
denied = "top"
5-
local creaListaBarboni = fs.open("lista_barboni", "w")
5+
6-
creaListaBarboni.writeLine("BigBrother")
6+
pizzaType = true
7-
creaListaBarboni.close()
7+
8
local function searchUser(user)
9-
    local event, barbone = os.pullEvent()
9+
	local userList = fs.open("users", "r")
10-
    if event == "player" then
10+
	checkUser = string.find(userList.readAll(), user)
11-
        local ControllaBarbone = fs.open("lista_barboni", "r")
11+
	userList.close()
12-
        trovaBarbone = string.find(ControllaBarbone.readAll(), barbone)
12+
	return checkUser
13-
        if trovaBarbone == nil or trovaBarbone == "" then
13+
end
14-
            ControllaBarbone.close()
14+
15-
            print(textutils.formatTime(os.time(),true).." Pranzo erogato: "..barbone)
15+
local function addUser(user)
16-
            local AggiungiBarbone = fs.open("lista_barboni", "a")
16+
	local userList = fs.open("users", "a")
17-
            AggiungiBarbone.writeLine(barbone)
17+
  userList.writeLine(user)
18-
            AggiungiBarbone.close()
18+
  userList.close()
19-
            rs.setOutput("left", true)
19+
end
20-
            sleep(1)
20+
21-
            rs.setOutput("left", false)
21+
local function resetRedstone()
22-
        else
22+
	rs.setOutput(margherita, false)
23-
            print(textutils.formatTime(os.time(),true).." Pranzo non erogato: "..barbone)
23+
	rs.setOutput(marinara, false)
24-
            rs.setOutput("top", true)
24+
	rs.setOutput(allowed, false)
25-
            sleep(1)
25+
	rs.setOutput(denied, false)
26-
            rs.setOutput("top", false)
26+
end
27-
        end
27+
28-
    elseif event == "alarm" then
28+
local function resetList()
29-
        os.reboot()
29+
	if fs.exists("users") then
30-
    end
30+
		fs.delete("users")
31-
    sleep(1)
31+
	end
32
	local userList = fs.open("users", "w")
33
	userList.writeLine("MegaAlbert4000")
34
	userList.close()
35
end
36
37
os.setAlarm(0)
38
resetRedstone()
39
resetList()
40
41
while true do
42
	local event, user = os.pullEvent()
43
	if event == "player" then
44
		local checkUser = searchUser(user)
45
		if checkUser == nil or checkUser == "" then
46
			addUser(user)
47
			if pizzaType then
48
				rs.setOutput(margherita, true)
49
			else
50
				rs.setOutput(marinara, true)
51
			end
52
			pizzaType = not pizzaType
53
			rs.setOutput(allowed, true)
54
      sleep(1)
55
      resetRedstone()
56
    else
57
    	rs.setOutput(denied, true)
58
      sleep(1)
59
      resetRedstone()
60
		end
61
	elseif event == "alarm" then
62
		resetList()
63
	end
64
	sleep(1)
65
end