#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#
#    This function has been created by Skilendarz Group.
#             https://skilendarz.com
#
#      GIVE MAP MAKERS THE CREDIT THEY DESERVE!
#             COPYING IS PROHIBITED!
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

#Count players
scoreboard players set start main -1
scoreboard players set start tick 0
scoreboard players set start team-count 0
execute if entity @a[team=f-blue] run scoreboard players add start team-count 1
execute if entity @a[team=f-green] run scoreboard players add start team-count 1
execute if entity @a[team=f-yellow] run scoreboard players add start team-count 1
execute if entity @a[team=f-red] run scoreboard players add start team-count 1
execute as @a[team=random] run scoreboard players add start team-count 1
execute as @a[team=f-hider] run scoreboard players add start team-count 1
execute if score $game_type main matches 3 if entity @a[team=lobby] run scoreboard players add start team-count 1

execute if entity @a[tag=test,team=!lobby] run scoreboard players set start team-count 2

#Start
execute if score start team-count matches 2.. run kill @e[tag=floor]
execute if score start team-count matches 2.. run scoreboard players set start time 0
execute if score start team-count matches 2.. run fill 320 108 -347 318 108 -347 air
execute if score start team-count matches 2.. run clone 326 100 -382 331 100 -376 315 106 -354
execute if score start team-count matches 2.. run function f:game/start/global

#Cancel
execute if score start team-count matches ..1 run team join lobby @a
execute if score start team-count matches ..1 run title @a title {"text":""}
execute if score start team-count matches ..1 run title @a subtitle ["",{"text":"[","color":"dark_gray"},{"text":"✖","color":"red"},{"text":"] ","color":"dark_gray"},{"translate":"game.players","color":"gray"},{"text":" [","color":"dark_gray"},{"text":"✖","color":"red"},{"text":"]","color":"dark_gray"}]
execute if score start team-count matches ..1 run scoreboard players set start time 100

tag @s[scores={main=0}] remove start
scoreboard players set @s[scores={main=0}] main 16