I want to create a command "team", its effect is that when the player use, if his team is infected, he will join survivors, and if he is a survivor, he will join infected. This is to be able to switch team freely when the team is full. Its code like
public Action Command_Team(int client, int args)
if (client && IsClientInGame(client))
if (GetClientTeam(client) != 3) ChangeClientTeam(client, 3);
else ChangeClientTeam(client, 2);
While it works, there are often strange situations when using it, when there are more than 5 real (non-bot) players in the infected's team, if an infected real player uses the "team" command join the survivors. At this time, in addition to this real player of the infected who used the command, there is another real player of the Infected who is inexplicably switched to the survivors despite not using the command.
But using the default vanilla "M" key of the game itself to switch teams no such problem(, but it can only use if there are fewer than four real players in the survivor team),
Even, I also want to make the dead survivor player auto take over other survivor bots, the code such as
public void Event_PlayerDeath(Event event, const char name, bool dontBroadcast)
int client = GetClientOfUserId(event.GetInt("userid"));
if (client && IsClientInGame(client) && GetClientTeam(client) != 3 && !IsFakeClient(client)) TakeOverBot(client);
Although there is this part of "GetClientTeam(client) != 3" in the code, when there are more than 5 players including bots in both the survivors and infected teams, when a real (non-bot) player in the survivor's team dies, although this player takes over other survivor bots, but in addition to him, another real player in the infected team was also inexplicably switched to the survivor team.
If I comment out these two pieces of code, there will be no such inexplicable team change problem. What problems may it be related to?