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:
My code, which places a player to a team when the game has already started:
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::*}
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)