scoreboard players reset * cageID
scoreboard players reset * playerID

scoreboard players set teams gameInfoValues 0

#Player id
execute as @a[tag=!spectating,sort=random] run function subchronos:game/starting/cages/spread_players/assing_id {"score":"playerID"}
#No Teams
    execute unless entity @e[tag=team1,type=marker] as @e[type=marker,tag=cage,sort=random] run function subchronos:game/starting/cages/spread_players/assing_id {"score":"cageID"}
#With teams
    execute if entity @e[tag=team1,type=marker] unless entity @e[tag=team4,type=marker] run function subchronos:game/starting/cages/spread_players/teams4v4
    execute if entity @e[tag=team1,type=marker] if entity @e[tag=team4,type=marker] run function subchronos:game/starting/cages/spread_players/teams2v2


execute positioned 1000 0 1000 as @a[tag=!spectating] at @e[type=marker,tag=cage,distance=0..200] if score @s playerID = @n[type=marker,tag=cage,distance=0..1] cageID run tp @s ~ ~ ~ facing 1022 0 1022

####CARGAR COSMETICOS
    execute as @a[tag=!spectating] at @s run function subchronos:game/starting/cages/spread_players/apply_cosmetic_cage
#Teams
    execute as @a[tag=!spectating] at @s if entity @n[distance=0..0.5,type=marker,tag=cage,tag=team1] run team join t1
    execute as @a[tag=!spectating] at @s if entity @n[distance=0..0.5,type=marker,tag=cage,tag=team2] run team join t2
    execute as @a[tag=!spectating] at @s if entity @n[distance=0..0.5,type=marker,tag=cage,tag=team3] run team join t3
    execute as @a[tag=!spectating] at @s if entity @n[distance=0..0.5,type=marker,tag=cage,tag=team4] run team join t4

gamemode adventure @a[tag=!spectating]
gamemode spectator @a[tag=spectating]