execute if entity @s[tag=dead] run return 0

execute if score @s spectator_time matches 239 run title @s subtitle {"text":"12","color":"gray"}
execute if score @s spectator_time matches 220 run title @s subtitle {"text":"11","color":"gray"}
execute if score @s spectator_time matches 200 run title @s subtitle {"text":"10","color":"gray"}
execute if score @s spectator_time matches 180 run title @s subtitle {"text":"9","color":"gray"}
execute if score @s spectator_time matches 160 run title @s subtitle {"text":"8","color":"gray"}
execute if score @s spectator_time matches 140 run title @s subtitle {"text":"7","color":"gray"}
execute if score @s spectator_time matches 120 run title @s subtitle {"text":"6","color":"gray"}
execute if score @s spectator_time matches 100 run title @s subtitle {"text":"5","color":"gray"}
execute if score @s spectator_time matches 80 run title @s subtitle {"text":"4","color":"gray"}
execute if score @s spectator_time matches 60 run title @s subtitle {"text":"3","color":"gray"}
execute if score @s spectator_time matches 40 run title @s subtitle {"text":"2","color":"gray"}
execute if score @s spectator_time matches 20 run title @s subtitle {"text":"1","color":"gray"}

tag @s add spec_temp
execute if entity @e[type=marker,tag=main_lobby,distance=..100] as @e[type=marker,tag=map_center] at @s if score @s map_id = @a[tag=spec_temp,sort=nearest,limit=1] on_map run tp @a[tag=spec_temp,sort=nearest,limit=1] ~ ~ ~
tag @s remove spec_temp

title @s times 0 5 5
title @s title {"text":"","color":"gray"}

execute if score @s spectator_time matches 1 run function pctf:logic/player/respawn with storage pctf:map input

#execute unless entity @a[tag=playing,gamemode=!spectator,distance=250..] at @a[tag=playing,sort=nearest,limit=1,distance=1..] run tp @s ~ ~ ~

execute if score @s spectator_time matches 1.. run scoreboard players remove @s spectator_time 1