Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- allowed_players = {"Firnagzen", "KitFuzzyFox"}
- bounded_radius = 10
- -- Get sensor
- sensor = peripheral.wrap("back")
- -- Reset all redstone
- rs.setBundledOutput("right", 0)
- while true do
- -- Wait for redstone
- local active = false
- local event = os.pullEvent("redstone")
- local activated = os.clock()
- if rs.getInput("left") then
- print("First interlock active!")
- while (os.clock() - activated) < 10 do
- sleep(0.05)
- if rs.getInput("front") then
- active = true
- break
- end
- end
- if active then
- print("Both interlocks active!")
- else
- print("Timed out.")
- end
- end
- if not active then
- if rs.getInput("front") then
- print("First interlock active!")
- while (os.clock() - activated) < 10 do
- sleep(0.05)
- if rs.getInput("left") then
- active = true
- break
- end
- end
- if active then
- print("Both interlocks active!")
- else
- print("Timed out.")
- end
- end
- end
- if active then
- print("System activated!")
- -- get all players around
- local players = sensor.getPlayers()
- -- Check if allowed members are present
- local continue = false
- for _, UUID_name in ipairs(players) do
- local name = UUID_name.name
- for _, allowed in ipairs(allowed_players) do
- if name == allowed then continue = true end
- end
- end
- if not continue then
- print("No authorised players in vicinity")
- end
- -- Check if all players are within acceptable distance
- if continue then
- print("Authorised players nearby")
- within_bounds = true
- for i, UUID_name in ipairs(players) do
- if within_bounds then
- -- Get player info
- local name = UUID_name.name
- local ok, player = pcall(sensor.getPlayerByName, name)
- if ok then
- -- Get player position
- local pos = player.all().position
- -- Compute distance
- local distance = math.sqrt(pos.x^2 + pos.y^2 + pos.z^2)
- print(distance)
- -- Check bounds
- within_bounds = distance < bounded_radius
- else
- -- Player left range while scanning
- within_bounds = false
- end
- end
- end
- end
- if not within_bounds then
- print("Players out of bounds!")
- end
- -- Activate dragon killer
- if within_bounds then
- print("Activating system!")
- rs.setBundledOutput("right", colors.brown + colors.red)
- sleep(30)
- print("Deactivating system!")
- rs.setBundledOutput("right", 0)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment