SHOW:
|
|
- or go back to the newest paste.
1 | os.loadAPI("ocs/apis/sensor") | |
2 | ||
3 | -- the location of the redstone lamp relative to the sensor | |
4 | local offset = { | |
5 | - | X = 0, |
5 | + | X = 0, |
6 | - | Y = -2, |
6 | + | Y = -2, |
7 | - | Z = 0, |
7 | + | Z = 0, |
8 | } | |
9 | ||
10 | -- how close a player has to be to activate the lamp | |
11 | local radius = 5 | |
12 | ||
13 | -- find the distance from the player position to the offset | |
14 | function distance(pos) | |
15 | - | local xd = pos.X - offset.X |
15 | + | local xd = pos.X - offset.X |
16 | - | local yd = pos.Y - offset.Y |
16 | + | local yd = pos.Y - offset.Y |
17 | - | local zd = pos.Z - offset.Z |
17 | + | local zd = pos.Z - offset.Z |
18 | - | return math.sqrt(xd*xd + yd*yd + zd*zd) |
18 | + | return math.sqrt(xd*xd + yd*yd + zd*zd) |
19 | end | |
20 | ||
21 | function zu() | |
22 | - | local proximity = sensor.wrap("right") |
22 | + | for i = 1,5 do |
23 | rs.setOutput("right", true) | |
24 | - | local signal = false |
24 | + | sleep(0.5) |
25 | - | local targets = proximity.getTargets() |
25 | + | rs.setOutput("right", false) |
26 | - | for k, v in pairs(targets) do |
26 | + | sleep(0.5) |
27 | - | if distance(v.Position) < radius then |
27 | + | end |
28 | - | if k == "MagmaLP" or k == "D0me05" or k == "JeremysWorkshop" then |
28 | + | |
29 | - | signal = true |
29 | + | |
30 | - | end |
30 | + | function auf() |
31 | for i = 1,5 do | |
32 | - | end |
32 | + | rs.setOutput("left", true) |
33 | - | rs.setOutput("bottom", signal) |
33 | + | sleep(0.5) |
34 | - | sleep(1) |
34 | + | rs.setOutput("left", false) |
35 | sleep(0.5) | |
36 | end | |
37 | end | |
38 | ||
39 | local proximity = sensor.wrap("top") | |
40 | while true do | |
41 | local signal = false | |
42 | local targets = proximity.getTargets() | |
43 | for k, v in pairs(targets) do | |
44 | if not rs.getInput("bottom", true) then | |
45 | if k ~= "MagmaLP" then | |
46 | zu() | |
47 | end | |
48 | end | |
49 | if distance(v.Position) < radius then | |
50 | if k == "MagmaLP" then | |
51 | auf() | |
52 | end | |
53 | end | |
54 | end | |
55 | ||
56 | if not rs.getInput("front", true) then | |
57 | zu() | |
58 | end | |
59 | ||
60 | sleep(1) | |
61 | end |