## Looping clock checking to see if a player is in range to use the teleport pad
## Runs from controller.animation.teleport_pad.detect_player
## @s = ldz:teleport_pad

scoreboard objectives add TPBuffer dummy
scoreboard objectives add TPPower dummy
scoreboard players add @s TPPower 0
execute positioned ~-1.5 ~ ~-1.5 if entity @a[dx=2,dy=2,dz=2] run scoreboard players set @s[scores={TPPower=0}] TPPower 1

scoreboard players add @s[scores={TPPower=1..}] TPPower 1

execute positioned ~-1.5 ~ ~-1.5 as @s[family=beast_pad_hub,scores={TPPower=1..}] run scoreboard players set @a[dx=2,dy=2,dz=2] TPBuffer 1
execute positioned ~-1.5 ~ ~-1.5 as @s[family=mystic_pad_hub,scores={TPPower=1..}] run scoreboard players set @a[dx=2,dy=2,dz=2] TPBuffer 1
execute positioned ~-1.5 ~ ~-1.5 as @s[family=scourge_pad_hub,scores={TPPower=1..}] run scoreboard players set @a[dx=2,dy=2,dz=2] TPBuffer 1
execute positioned ~-1.5 ~ ~-1.5 as @s[family=wraith_pad_hub,scores={TPPower=1..}] run scoreboard players set @a[dx=2,dy=2,dz=2] TPBuffer 1

execute as @s[family=beast_pad_dungeon,scores={TPPower=1..}] run event entity @s set_powered_to_true
execute as @s[family=mystic_pad_dungeon,scores={TPPower=1..}] run event entity @s set_powered_to_true
execute as @s[family=scourge_pad_dungeon,scores={TPPower=1..}] run event entity @s set_powered_to_true
execute as @s[family=wraith_pad_dungeon,scores={TPPower=1..}] run event entity @s set_powered_to_true

execute as @s[family=beast_pad_hub,scores={TPPower=30..}] run event entity @s set_powered_to_true
execute as @s[family=mystic_pad_hub,scores={TPPower=30..}] run event entity @s set_powered_to_true
execute as @s[family=scourge_pad_hub,scores={TPPower=30..}] run event entity @s set_powered_to_true
execute as @s[family=wraith_pad_hub,scores={TPPower=30..}] run event entity @s set_powered_to_true