Firnagzen

dragon

Oct 24th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. allowed_players = {"Firnagzen", "KitFuzzyFox"}
  2. bounded_radius = 10
  3.  
  4. -- Get sensor
  5. sensor = peripheral.wrap("back")
  6.  
  7. -- Reset all redstone
  8. rs.setBundledOutput("right", 0)
  9.  
  10. while true do
  11. -- Wait for redstone
  12. local active = false
  13. local event = os.pullEvent("redstone")
  14. local activated = os.clock()
  15.  
  16. if rs.getInput("left") then
  17. print("First interlock active!")
  18. while (os.clock() - activated) < 10 do
  19. sleep(0.05)
  20. if rs.getInput("front") then
  21. active = true
  22. break
  23. end
  24. end
  25. if active then
  26. print("Both interlocks active!")
  27. else
  28. print("Timed out.")
  29. end
  30. end
  31.  
  32. if not active then
  33. if rs.getInput("front") then
  34. print("First interlock active!")
  35. while (os.clock() - activated) < 10 do
  36. sleep(0.05)
  37. if rs.getInput("left") then
  38. active = true
  39. break
  40. end
  41. end
  42. if active then
  43. print("Both interlocks active!")
  44. else
  45. print("Timed out.")
  46. end
  47. end
  48. end
  49.  
  50.  
  51. if active then
  52. print("System activated!")
  53. -- get all players around
  54. local players = sensor.getPlayers()
  55.  
  56. -- Check if allowed members are present
  57. local continue = false
  58. for _, UUID_name in ipairs(players) do
  59. local name = UUID_name.name
  60. for _, allowed in ipairs(allowed_players) do
  61. if name == allowed then continue = true end
  62. end
  63. end
  64.  
  65. if not continue then
  66. print("No authorised players in vicinity")
  67. end
  68.  
  69. -- Check if all players are within acceptable distance
  70. if continue then
  71. print("Authorised players nearby")
  72. within_bounds = true
  73. for i, UUID_name in ipairs(players) do
  74. if within_bounds then
  75. -- Get player info
  76. local name = UUID_name.name
  77. local ok, player = pcall(sensor.getPlayerByName, name)
  78.  
  79. if ok then
  80. -- Get player position
  81. local pos = player.all().position
  82.  
  83. -- Compute distance
  84. local distance = math.sqrt(pos.x^2 + pos.y^2 + pos.z^2)
  85. print(distance)
  86.  
  87. -- Check bounds
  88. within_bounds = distance < bounded_radius
  89.  
  90. else
  91. -- Player left range while scanning
  92. within_bounds = false
  93. end
  94. end
  95. end
  96. end
  97.  
  98. if not within_bounds then
  99. print("Players out of bounds!")
  100. end
  101.  
  102. -- Activate dragon killer
  103. if within_bounds then
  104. print("Activating system!")
  105. rs.setBundledOutput("right", colors.brown + colors.red)
  106. sleep(30)
  107. print("Deactivating system!")
  108. rs.setBundledOutput("right", 0)
  109. end
  110.  
  111. end
  112. end
Advertisement
Add Comment
Please, Sign In to add comment