Firnagzen

Untitled

Oct 31st, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.02 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. while true do
  29. -- Set screen
  30. bscreen("Interlock", 0xffffff)
  31.  
  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 other 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 other 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.  
  131. -- Wait for spawn
  132. spawned = false
  133. start_time = os.clock()
  134. while ((os.clock() - start_time) < 10) do
  135. rs_in = rs.getBundledInput("right")
  136. if colors.test(rs_in, colors.black) then
  137. spawned = true
  138. break
  139. end
  140. sleep(0.1)
  141. end
  142.  
  143. if not spawned then
  144. rs.setBundledOutput("right", colors.purple)
  145. lscreen("No spawn!", 0xFF0000)
  146. rscreen("Retrieving egg!", 0xFF0000)
  147. sleep(5)
  148. end
  149.  
  150. -- Kill dragon
  151. if spawned then
  152. bscreen("Killing...", 0x00FF00)
  153. rs.setBundledOutput("right", colors.brown + colors.purple)
  154.  
  155. while true do
  156. rs_in = rs.getBundledInput("right")
  157. if not colors.test(rs_in, colors.black) then
  158. break
  159. end
  160. sleep(0.1)
  161. end
  162. end
  163.  
  164. -- Wait for heart to drop
  165. bscreen("Deactivating...", 0x00FF00)
  166. rs.setBundledOutput("right", colors.purple)
  167. sleep(30)
  168. rs.setBundledOutput("right", 0)
  169. end
  170.  
  171. end
  172. end
Advertisement
Add Comment
Please, Sign In to add comment