Joining a team when the game is running ruins all lists

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

Tom1222322

Member
Feb 5, 2021
19
0
1
22
Hello, I have this problem, whenever a new player joins an already ongoing game it puts him in one of two teams, but it messes up the other player's team. For example, if I was in team a and someone else was in team b new player who joined the game is placed properly into a new team, but players who were already playing get added to both team a and team b which ruins the game.
My code when the game starts:
Code:
            loop {sf.players::*}:
                if {_red} is true:
                    delete {_red}
                    sffjTeamRed(loop-value)
                else:
                    set {_red} to true
                    sffjTeamBlue(loop-value)
    if {sf.running} is false:
        set {_size} to size of {sf.players::*}
        if {_size} > 1:
            set {sf.running} to true
            loop {_size} times:
                if mod(loop-value,2)  is not 0:
                    add {sf.players::%loop-value%} to {sf.teamred::*}
                else:
                    add {sf.players::%loop-value%} to {sf.teamblue::*}
My code, which places a player to a team when the game has already started:
Code:
                    if {sf.running} is false:
                        if {sf.firstjoin.%player%} is not set:
                            #game is about to start
                        else:
                            #game is about to start
                    
                    else:
                        #game has already started and new player joins
                        set {sf.loc.beforegame.%player%} to player's location
                        add player to {sf.players::*}
                        set {_size} to size of {sf.players::*}
                        if {_size} > 1:
                            loop {_size} times:
                                if mod(loop-value,2)  is not 0:
                                    add {sf.players::%loop-value%} to {sf.teamred::*}
                                else:
                                    add {sf.players::%loop-value%} to {sf.teamblue::*}
                            send "{@prefix} Tu prisijungei į SkyFlag!"
                            if {sf.teamred::*} contains player:
                                send "{@prefix} Tu esi raudonų komandoje!" to player
                                teleport player to {sf.redspawn}
                                clear player's inventory
                                sfTeamRed(player)
                            if {sf.teamblue::*} contains player:
                                send "{@prefix} Tu esi mėlynų komandoje!" to player
                                teleport player to {sf.bluespawn}
                                clear player's inventory
                                sfTeamBlue(player)
 
Status
Not open for further replies.