command /minigame_flags_start:
    description: Zapni celou minihru flags
    usage: /minigame_flags_start
    executable by: the console and players
    permission: skript.op
    trigger:
        execute console command "/gamerule keepInventory true"
        clear {gaming_players::*}
        loop 10 times:
            loop entries of team "IDList%loop-number%":
                add loop-value-2 to {gaming_players::*}
        broadcast "Načítám minihru Vlajky"
        send title "§2Vlajky" to all players
        set {game_status} to "init"
        set {game_on} to "True"
        wait 2 seconds
        send subtitle "Teleportuji" to all players
        wait 1 second
        set {intro} to "True"
        set gamemode of {gaming_players::*} to adventure
        teleport {gaming_players::*} to {introlocation}
        set {stop_players} to "True"
        hide {gaming_players::*}
        wait 1 seconds
        send "§e----------- Vlajky -----------" to {gaming_players::*}
        send " V této minihře máte za úkol, jako první získat vlajku na středu, kterou vezmene pravím kliknutím a donést jí domů, ale pozor, protivník tě může dát na jednu rádu lukem, proto jsou po stranách instakill potiony, který můžeš použít jako obranu." to {gaming_players::*}
        wait 15 seconds
        set {stop_players} to "False"
        reveal {gaming_players::*}

        while {game_on} is "True":
            if {game_status} is "init":   # kód před prvním startem

                # procesy před startem

                clear {flag_won::*}
                set {teamscore::1} to 0
                set {teamscore::2} to 0
                set {teamscore::3} to 0
                set {teamscore::4} to 0
                set {teamscore::5} to 0
                set {teamscore::6} to 0
                set {teamscore::7} to 0
                set {teamscore::8} to 0
                set {teamscore::9} to 0
                set {teamscore::10} to 0


                # //procesy před startem

                set {flags_kola} to 1
                clear inventory of all players
                wait 20 ticks
                send title "§4§l1. KOLO" to all players

                if {flags_kola} is 1:
                    spawngate(3)
                    spawnteam(1,1)
                    spawnteam(2,2)
                    spawnteam(3,3)
                    spawnteam(10,4)
                    spawnteam(4,5)
                    spawnteam(9,6)
                    spawnteam(5,7)
                    spawnteam(8,8)
                    spawnteam(6,9)
                    spawnteam(7,10)

                    loop {flag_locations::*}:
                        set block at loop-value to white banner


                    loop {potion_locations::*}:
                        drop {dmgpotion} named "§4Insta-kill potion" at loop-value

                    set {game_status} to "playing"

                    set {flags_timer} to {čas_kola}

                wait 5 seconds
                send title "§4§l%{flags_kola}%. KOLO" with subtitle "3" to all players
                play sound "block.note_block.bell" at volume 50 to all players
                wait 1 second
                send title "§4§l%{flags_kola}%. KOLO" with subtitle "2" to all players
                play sound "block.note_block.bell" at volume 50 to all players
                spawngate(2)
                wait 1 second
                send title "§4§l%{flags_kola}%. KOLO" with subtitle "1" to all players
                play sound "block.note_block.bell" at volume 50 to all players
                wait 1 second
                send title "GO" with subtitle "" to all players
                play sound "block.note_block.bell" at volume 50 with pitch 18 to all players
                spawngate(1)


            if {game_status} is "next":

                loop {flag_locations::*}:
                    loop all blocks in radius 35 around loop-value-1:
                        if loop-value-2 is banner:
                            set block at loop-value-2 to air
                loop 10 times:
                    loop entries of team "IDList%loop-number%":
                        if {flag_won::*} contains loop-value-2:
                            set {teamscore::%loop-number-1%} to {teamscore::%loop-number-1%} + 1
                clear inventory of all players
                loop {potion_locations::*}:
                    loop all entities in radius 4 around loop-value-1:
                        kill loop-value-2

                set {flags_kola} to {flags_kola} + 1


                clear {flag_won::*}
                spawngate(3)

                if {flags_kola} is 2:

                    spawnteam(2,1)
                    spawnteam(3,2)
                    spawnteam(1,3)
                    spawnteam(7,4)
                    spawnteam(8,5)
                    spawnteam(6,6)
                    spawnteam(9,7)
                    spawnteam(5,8)
                    spawnteam(4,9)
                    spawnteam(10,10)

                    loop {flag_locations::*}:
                        set block at loop-value to white banner

                    loop {potion_locations::*}:
                        drop {dmgpotion} named "§4Insta-kill potion" at loop-value

                    set {game_status} to "playing"

                if {flags_kola} is 3:
                    spawnteam(6,1)
                    spawnteam(9,2)
                    spawnteam(8,3)
                    spawnteam(7,4)
                    spawnteam(3,5)
                    spawnteam(1,6)
                    spawnteam(4,7)
                    spawnteam(2,8)
                    spawnteam(5,9)
                    spawnteam(10,10)
                    loop {flag_locations::*}:
                        set block at loop-value to white banner
                    loop {potion_locations::*}:
                        drop {dmgpotion} named "§4Insta-kill potion" at loop-value
                    set {game_status} to "playing"

                if {flags_kola} is 4:
                    spawnteam(10,1)
                    spawnteam(6,2)
                    spawnteam(2,3)
                    spawnteam(5,4)
                    spawnteam(3,5)
                    spawnteam(4,6)
                    spawnteam(1,7)
                    spawnteam(8,8)
                    spawnteam(7,9)
                    spawnteam(9,10)
                    loop {flag_locations::*}:
                        set block at loop-value to white banner
                    loop {potion_locations::*}:
                        drop {dmgpotion} named "§4Insta-kill potion" at loop-value
                    set {game_status} to "playing"

                if {flags_kola} is 5:
                    spawnteam(5,1)
                    spawnteam(3,2)
                    spawnteam(6,3)
                    spawnteam(2,4)
                    spawnteam(7,5)
                    spawnteam(10,6)
                    spawnteam(8,7)
                    spawnteam(9,8)
                    spawnteam(4,9)
                    spawnteam(1,10)
                    loop {flag_locations::*}:
                        set block at loop-value to white banner
                    loop {potion_locations::*}:
                        drop {dmgpotion} named "§4Insta-kill potion" at loop-value
                    set {game_status} to "playing"

                if {flags_kola} is 6:
                    spawnteam(1,1)
                    spawnteam(9,2)
                    spawnteam(10,3)
                    spawnteam(8,4)
                    spawnteam(2,5)
                    spawnteam(7,6)
                    spawnteam(3,7)
                    spawnteam(6,8)
                    spawnteam(4,9)
                    spawnteam(5,10)
                    loop {flag_locations::*}:
                        set block at loop-value to white banner
                    loop {potion_locations::*}:
                        drop {dmgpotion} named "§4Insta-kill potion" at loop-value
                    set {game_status} to "playing"

                if {flags_kola} is 7:
                    spawnteam(5,1)
                    spawnteam(1,2)
                    spawnteam(6,3)
                    spawnteam(4,4)
                    spawnteam(7,5)
                    spawnteam(3,6)
                    spawnteam(8,7)
                    spawnteam(2,8)
                    spawnteam(9,9)
                    spawnteam(10,10)
                    loop {flag_locations::*}:
                        set block at loop-value to white banner
                    loop {potion_locations::*}:
                        drop {dmgpotion} named "§4Insta-kill potion" at loop-value
                    set {game_status} to "playing"

                if {flags_kola} is 8:
                    spawnteam(5,1)
                    spawnteam(6,2)
                    spawnteam(1,3)
                    spawnteam(10,4)
                    spawnteam(2,5)
                    spawnteam(9,6)
                    spawnteam(3,7)
                    spawnteam(8,8)
                    spawnteam(4,9)
                    spawnteam(7,10)
                    loop {flag_locations::*}:
                        set block at loop-value to white banner
                    loop {potion_locations::*}:
                        drop {dmgpotion} named "§4Insta-kill potion" at loop-value
                    set {game_status} to "playing"

                if {flags_kola} is 9:
                    spawnteam(9,1)
                    spawnteam(3,2)
                    spawnteam(10,3)
                    spawnteam(2,4)
                    spawnteam(6,5)
                    spawnteam(1,6)
                    spawnteam(7,7)
                    spawnteam(5,8)
                    spawnteam(8,9)
                    spawnteam(4,10)
                    loop {flag_locations::*}:
                        set block at loop-value to white banner
                    loop {potion_locations::*}:
                        drop {dmgpotion} named "§4Insta-kill potion" at loop-value
                    set {game_status} to "playing"
                if {flags_kola} is 10:
                    set {game_status} to "end"
                else:

                    send title "§4§l%{flags_kola}%. KOLO" to all players
                    wait 5 second
                    send title "§4§l%{flags_kola}%. KOLO" with subtitle "3" to all players
                    play sound "block.note_block.bell" at volume 50 to all players
                    wait 1 second
                    send title "§4§l%{flags_kola}%. KOLO" with subtitle "2" to all players
                    play sound "block.note_block.bell" at volume 50 to all players
                    spawngate(2)
                    wait 1 second
                    send title "§4§l%{flags_kola}%. KOLO" with subtitle "1" to all players
                    play sound "block.note_block.bell" at volume 50 to all players
                    wait 1 second
                    send title "GO" with subtitle "" to all players
                    play sound "block.note_block.bell" at volume 50 with pitch 18 to all players
                    spawngate(1)

                set {flags_timer} to {čas_kola} # NASTAVENÍ ČASU

            if {game_status} is "playing":   # kód kontroly konce kola
                send action bar "§4§lČas: §7%{flags_timer}%" to all players
                set {flags_timer} to {flags_timer} - 1
                wait 1 second
                if {flags_timer} is 0:
                    send title "§4§lDošel čas!" to all players
                    set {gaming_players::*}'s gamemode to spectator
                    set {game_status} to "next"
                    wait 5 seconds

                if size of {flag_won::*} is 5:
                    set {game_status} to "next"
                    set {gaming_players::*}'s gamemode to spectator
                    wait 1 second
                    send title "§a§lKonec kola!" to all players
                    wait 5 seconds

            if {game_status} is "end":
                send "game end"
                send title "&4Konec hry" to all players
                # VYHODNOCENÍ BODŮ

                loop 10 times:
                    execute console command "/scoreboard players add @a[scores={IDlist=%loop-number%}] Win %{teamscore::%loop-number%}%"
                    if loop-number is 10:
                        execute console command "/scoreboard players add @a[scores={IDlist=20}] Win %{teamscore::%loop-number%}%"
                    else:
                        execute console command "/scoreboard players add @a[scores={IDlist=1%loop-number%}] Win %{teamscore::%loop-number%}%"

                set {game_on} to "False"
                send "game stop"
                wait 5 seconds
                make console execute command "/function ctf:vlajky"
                wait 3 seconds
                teleport {gaming_players::*} to {lobbylocation}
                set {gaming_players::*}'s gamemode to adventure
