Firnagzen

Untitled

Oct 26th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. allowed_players = {"Firnagzen", "KitFuzzyFox"}
  2. bounded_radius = 10
  3.  
  4. -- screen.setText("left", "test", 0xffffff)
  5.  
  6. -- Get peripherals
  7. screen = peripheral.wrap("top")
  8. sensor = peripheral.wrap("back")
  9.  
  10. -- Screen helpers
  11. function lscreen(text, colour)
  12. screen.setText("left" , text, colour)
  13. print(text)
  14. end
  15. function rscreen(text, colour)
  16. screen.setText("right", text, colour)
  17. print(text)
  18. end
  19. function bscreen(text, colour)
  20. screen.setText("left", text, colour)
  21. screen.setText("right", text, colour)
  22. print(text)
  23. end
  24.  
  25. -- Reset all redstone
  26. rs.setBundledOutput("right", 0)
  27.  
  28. -- Set screen
  29. bscreen("Interlock", 0xffffff)
  30.  
  31. while true do
  32. -- Wait for redstone
  33. local active = false
  34. local event = os.pullEvent("redstone")
  35. local activated = os.clock()
  36.  
  37. if rs.getInput("left") then
  38. lscreen("Awaiting second interlock", 0x00FF00)
  39. while (os.clock() - activated) < 10 do
  40. sleep(0.05)
  41. if rs.getInput("front") then
  42. active = true
  43. break
  44. end
  45. end
  46. if active then
  47. bscreen("Activated", 0x00FF00)
  48. else
  49. bscreen("Timed out.", 0xff0000)
  50. end
  51. end
  52.  
  53. if not active then
  54. if rs.getInput("front") then
  55. lscreen("Awaiting second interlock", 0x00FF00)
  56. while (os.clock() - activated) < 10 do
  57. sleep(0.05)
  58. if rs.getInput("left") then
  59. active = true
  60. break
  61. end
  62. end
  63. if active then
  64. bscreen("Activated", 0x00FF00)
  65. else
  66. bscreen("Timed out.", 0xff0000)
  67. end
  68. end
  69. end
  70.  
  71. sleep(0.2)
  72.  
  73. if active then
  74. bscreen("System scanning.", 0x00FF00)
  75. -- get all players around
  76. local players = sensor.getPlayers()
  77.  
  78. -- Check if allowed members are present
  79. local continue = false
  80. for _, UUID_name in ipairs(players) do
  81. local name = UUID_name.name
  82. for _, allowed in ipairs(allowed_players) do
  83. if name == allowed then continue = true end
  84. end
  85. end
  86.  
  87. bscreen("System scanning..", 0x00FF00)
  88.  
  89. if not continue then
  90. bscreen("No authorised players", 0xFF0000)
  91. end
  92.  
  93. -- Check if all players are within acceptable distance
  94. if continue then
  95. bscreen("System scanning..", 0x00FF00)
  96. within_bounds = true
  97. for i, UUID_name in ipairs(players) do
  98. if within_bounds then
  99. -- Get player info
  100. local name = UUID_name.name
  101. local ok, player = pcall(sensor.getPlayerByName, name)
  102.  
  103. if ok then
  104. -- Get player position
  105. local pos = player.all().position
  106.  
  107. -- Compute distance
  108. local distance = math.sqrt(pos.x^2 + pos.y^2 + pos.z^2)
  109.  
  110. -- Check bounds
  111. within_bounds = distance < bounded_radius
  112.  
  113. else
  114. -- Player left range while scanning
  115. within_bounds = false
  116. end
  117. end
  118. end
  119. bscreen("System scanning...", 0x00FF00)
  120. end
  121.  
  122. if not within_bounds then
  123. bscreen("Players out of bounds!", 0xFF0000)
  124. end
  125.  
  126. -- Activate dragon killer
  127. if within_bounds then
  128. bscreen("Spawning...", 0x00FF00)
  129. rs.setBundledOutput("right", colors.brown + colors.red)
  130. sleep(10)
  131. bscreen("Killing...", 0x00FF00)
  132. rs.setBundledOutput("right", colors.brown + colors.purple)
  133. sleep(30)
  134. bscreen("Deactivating...", 0x00FF00)
  135. rs.setBundledOutput("right", 0)
  136. end
  137.  
  138. end
  139. end
Advertisement
Add Comment
Please, Sign In to add comment