SHOW:
|
|
- or go back to the newest paste.
1 | - | local scanSide = "right" |
1 | + | local scanSide = "bottom" |
2 | - | local projSide = "left" |
2 | + | local projSide = "top" |
3 | - | local modemSide = "back" |
3 | + | local modemSide = "front" |
4 | local doorSec = 3 | |
5 | local masterSec = 41 | |
6 | local scanPath = "z" | |
7 | ||
8 | p = peripheral.wrap(scanSide) | |
9 | rednet.open(modemSide) | |
10 | redstone.setOutput(projSide, true) | |
11 | ||
12 | function playerInRange(name) | |
13 | data = p.getPlayerData(name) | |
14 | if data then | |
15 | return(math.abs(tonumber(data["position"][scanPath])) <2.5) | |
16 | end | |
17 | return false | |
18 | end | |
19 | ||
20 | function openDoor(name) | |
21 | redstone.setOutput(projSide, false) | |
22 | while playerInRange(name) do | |
23 | sleep(0.5) | |
24 | end | |
25 | redstone.setOutput(projSide, true) | |
26 | end | |
27 | ||
28 | function getAccess(player) | |
29 | rednet.send(masterSec, player) | |
30 | local id, msg, dist = rednet.receive(5) | |
31 | -- print(msg) | |
32 | return(msg) | |
33 | end | |
34 | ||
35 | function checkAccess(secLevel) | |
36 | if secLevel ~= nil then | |
37 | return(secLevel >= doorSec) | |
38 | end | |
39 | return(false) | |
40 | end | |
41 | ||
42 | function scan() | |
43 | local players = p.getPlayerNames() | |
44 | local playerAccess | |
45 | for num,name in pairs(players) do | |
46 | playerAccess = getAccess(name) | |
47 | if checkAccess(playerAccess) then | |
48 | if playerInRange(name) then | |
49 | openDoor(name) | |
50 | end | |
51 | end | |
52 | end | |
53 | end | |
54 | ||
55 | while true do | |
56 | scan() | |
57 | sleep(0.025) | |
58 | end |