Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- allowed_players = {"Firnagzen", "KitFuzzyFox"}
- bounded_radius = 10
- -- screen.setText("left", "test", 0xffffff)
- -- Get peripherals
- screen = peripheral.wrap("top")
- sensor = peripheral.wrap("back")
- -- Screen helpers
- function lscreen(text, colour)
- screen.setText("left" , text, colour)
- print(text)
- end
- function rscreen(text, colour)
- screen.setText("right", text, colour)
- print(text)
- end
- function bscreen(text, colour)
- screen.setText("left", text, colour)
- screen.setText("right", text, colour)
- print(text)
- end
- -- Reset all redstone
- rs.setBundledOutput("right", 0)
- -- Set screen
- bscreen("Interlock", 0xffffff)
- while true do
- -- Wait for redstone
- local active = false
- local event = os.pullEvent("redstone")
- local activated = os.clock()
- if rs.getInput("left") then
- lscreen("Awaiting second interlock", 0x00FF00)
- while (os.clock() - activated) < 10 do
- sleep(0.05)
- if rs.getInput("front") then
- active = true
- break
- end
- end
- if active then
- bscreen("Activated", 0x00FF00)
- else
- bscreen("Timed out.", 0xff0000)
- end
- end
- if not active then
- if rs.getInput("front") then
- lscreen("Awaiting second interlock", 0x00FF00)
- while (os.clock() - activated) < 10 do
- sleep(0.05)
- if rs.getInput("left") then
- active = true
- break
- end
- end
- if active then
- bscreen("Activated", 0x00FF00)
- else
- bscreen("Timed out.", 0xff0000)
- end
- end
- end
- sleep(0.2)
- if active then
- bscreen("System scanning.", 0x00FF00)
- -- 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
- bscreen("System scanning..", 0x00FF00)
- if not continue then
- bscreen("No authorised players", 0xFF0000)
- end
- -- Check if all players are within acceptable distance
- if continue then
- bscreen("System scanning..", 0x00FF00)
- 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)
- -- Check bounds
- within_bounds = distance < bounded_radius
- else
- -- Player left range while scanning
- within_bounds = false
- end
- end
- end
- bscreen("System scanning...", 0x00FF00)
- end
- if not within_bounds then
- bscreen("Players out of bounds!", 0xFF0000)
- end
- -- Activate dragon killer
- if within_bounds then
- bscreen("Spawning...", 0x00FF00)
- rs.setBundledOutput("right", colors.brown + colors.red)
- sleep(10)
- bscreen("Killing...", 0x00FF00)
- rs.setBundledOutput("right", colors.brown + colors.purple)
- sleep(30)
- bscreen("Deactivating...", 0x00FF00)
- rs.setBundledOutput("right", 0)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment