View difference between Paste ID: 810i16Jx and N1tFvw1H
SHOW: | | - or go back to the newest paste.
1
m = peripheral.find("modem")
2
m.open(51)
3
---------------------- CONFIG ------------------------------------------------
4
ID = "BEDDR" --Door ID for "rOpen"
5
------------------------------------------------------------------------------
6
-- redstone pulse
7
local function pulse(side)
8
rs.setOutput(side, true)
9
sleep(3)
10
rs.setOutput(side,false)
11
end
12
13
Tr = true
14
function os.pullEvent()
15
local event, p1,p2,p3,p4,p5 = os.pullEventRaw()
16
if event == "terminate" then write("For terminate need password:")
17
p = read()
18
if p == "ex" then
19
Tr = false
20
print("exiting")
21
end
22
end
23
return event,p1,p2,p3,p4,p5
24
end
25
 
26
 --add function from command "add"
27
function Add(Name)
28
Fold = "Assets/"
29
RC = Fold .. Name
30
fs.makeDir("Assets")
31
Name = tostring(RC)
32
if fs.exists(RC) then
33
return false
34
else
35
f = fs.open(RC,"w")
36
f.close()
37
return true
38
end
39
end
40
 --remove function from command "rm" 
41
function Rm(Name)
42
inp = "Assets/" .. Name
43
if fs.exists(inp) then
44
fs.delete(inp)
45
return true
46
else
47
return false
48
end
49
end
50
 
51
while Tr do
52
Recive = {"","",""}
53
Recive[1],Recive[2],Recive[3],Recive[4],Recive[5] = os.pullEvent()
54
pL = fs.list("Assets")
55
--check events
56
if Recive[1] == "player" or "modem_message" then
57
if Recive[1] == "modem_message" then
58
for k,v in string.gmatch(Recive[5], "(%w+)=(%w+)") do
59
--command exicute
60
if (k == "rOpen" and v == ID) then
61
pulse("right")
62
elseif k == "add" then
63
Add(v)
64
elseif k == "rm" then
65
Rm(v)
66
end
67
end
68
 -- check player and open door
69
elseif Recive[1] == "player" then
70
for i =1 , 10 ,1 do
71
if Recive[3] == pL[i] then
72
pulse("right")
73
end
74
end
75
end
76
end
77
end