SHOW:
|
|
- or go back to the newest paste.
| 1 | local detector = peripheral.find("environment_detector")
| |
| 2 | local gearshift = peripheral.find("Create_SequencedGearshift")
| |
| 3 | ||
| 4 | if not detector then | |
| 5 | error("No environment detector found")
| |
| 6 | end | |
| 7 | ||
| 8 | if not gearshift then | |
| 9 | error("No Create Sequenced Gearshift found")
| |
| 10 | end | |
| 11 | ||
| 12 | local isDoorOpen = false -- Initial state of the door | |
| 13 | local minYLevel = -1 -- Minimym Y level to consider user valid (relative to detector) | |
| 14 | ||
| 15 | local doorStateFile = fs.open(".door_state", "r")
| |
| 16 | if doorStateFile then | |
| 17 | isDoorOpen = doorStateFile.readLine() == "1" | |
| 18 | doorStateFile.close() | |
| 19 | end | |
| 20 | ||
| 21 | local allowedUsers = {
| |
| 22 | "f48e6371-3ed0-4738-a5e0-0f29bc2da9d4", -- LunaFolf | |
| 23 | "442b1cce-8356-450d-9a5d-d1a040ee15ac", -- lifeline4603 | |
| 24 | "9c4b7608-6411-45d7-b0ab-e13587c81074", -- PrinceOfCookies | |
| 25 | "fbd30864-b8d8-431e-83d6-a86d68281f7d", -- AdventurousMR | |
| 26 | "d94e1d90-c8db-4b98-8958-af7a57a99266", -- beLLecolond | |
| 27 | "dd91707a-b7a0-4ab7-9bbd-498a4f35e8b2", -- NoxxyTheStars | |
| 28 | ||
| 29 | ||
| 30 | } | |
| 31 | ||
| 32 | --[[ | |
| 33 | Table Structure for detector.scanEntities(): | |
| 34 | {
| |
| 35 | {
| |
| 36 | canFreeze = true, | |
| 37 | health = 20, | |
| 38 | id = 1, | |
| 39 | isGlowing = false, | |
| 40 | isInWall = false, | |
| 41 | maxHealth = 20, | |
| 42 | name = "LunaFolf", | |
| 43 | tags = {},
| |
| 44 | uuid = "f48e6371-3ed0-4738-a5e0-0f29bc2da9d4", | |
| 45 | x = 3.4389338271924, | |
| 46 | y = 0, | |
| 47 | z = -0.18627323016072 | |
| 48 | ||
| 49 | }, | |
| 50 | ... | |
| 51 | } | |
| 52 | --]] | |
| 53 | ||
| 54 | function toggleDoor(open) | |
| 55 | if isDoorOpen == open then | |
| 56 | print("Door is already ", open and "open" or "closed")
| |
| 57 | print("Skipping toggle.")
| |
| 58 | return | |
| 59 | end | |
| 60 | ||
| 61 | gearshift.rotate(90, open and -1 or 1) | |
| 62 | isDoorOpen = open | |
| 63 | ||
| 64 | local doorStateFile = fs.open(".door_state", "w")
| |
| 65 | if doorStateFile then | |
| 66 | doorStateFile.writeLine(open and "1" or "0") | |
| 67 | doorStateFile.close() | |
| 68 | end | |
| 69 | end | |
| 70 | ||
| 71 | -- Main loop | |
| 72 | while true do | |
| 73 | local detectedEntities = nil | |
| 74 | if not gearshift.isRunning() then | |
| 75 | detectedEntities = detector.scanEntities(4) -- Scan within 4 blocks | |
| 76 | end | |
| 77 | local userDetected = false | |
| 78 | ||
| 79 | if detectedEntities ~= nil then | |
| 80 | for _, entity in ipairs(detectedEntities) do | |
| 81 | for _, allowedUUID in ipairs(allowedUsers) do | |
| 82 | if entity.uuid == allowedUUID and entity.y >= minYLevel then | |
| 83 | userDetected = true | |
| 84 | break | |
| 85 | end | |
| 86 | end | |
| 87 | if userDetected then | |
| 88 | break | |
| 89 | end | |
| 90 | end | |
| 91 | ||
| 92 | if userDetected and not isDoorOpen then | |
| 93 | toggleDoor(true) | |
| 94 | elseif not userDetected and isDoorOpen then | |
| 95 | toggleDoor(false) | |
| 96 | end | |
| 97 | end | |
| 98 | end |