Coding help

Zavnice

New member
Joined
Aug 18, 2023
Messages
13
Hello guys. Can someone help me how to make Team balancing code?
Like example:
There are 2 teams, red and blue.
If someone wants to join red Team
But the players in That Team are more than the blue Team (3vs1). Which creates an imbalance. Sorry my english kinda suck. But please help
 
Last edited:

Ezolile

Member
Joined
May 19, 2023
Messages
40
Imagine you have 2 variables. 1 for each team. Both of those are global variables named for example red_team and blue_team. Then you will have code that goes something like this: If player tries to join to red team (by clicking on item, sign, using chat command, etc) check If Variable red_team is larger then blue_team. If it is larger send notification to player that team is full or whatever you wish to do in this case. Else allow player to join red team and increase variable red_team by 1. Same thing you need to do with blue team. Now there is a lot of other things you must code to make this work properly like for example you need to reset these variables when game is finished and to decrease them by 1 when players die or leave game.
Coding teams and queues should be easy but it requires a lot of thinking and testing what could happen in certain cases and way of coding it depends on lot of factors.
I have answered just on your question how to balance teams and with this balance will be +-1 player in team if total of players who want to join is odd number. If it is even number than teams will have same number of players.
 

Zavnice

New member
Joined
Aug 18, 2023
Messages
13
Imagine you have 2 variables. 1 for each team. Both of those are global variables named for example red_team and blue_team. Then you will have code that goes something like this: If player tries to join to red team (by clicking on item, sign, using chat command, etc) check If Variable red_team is larger then blue_team. If it is larger send notification to player that team is full or whatever you wish to do in this case. Else allow player to join red team and increase variable red_team by 1. Same thing you need to do with blue team. Now there is a lot of other things you must code to make this work properly like for example you need to reset these variables when game is finished and to decrease them by 1 when players die or leave game.
Coding teams and queues should be easy but it requires a lot of thinking and testing what could happen in certain cases and way of coding it depends on lot of factors.
I have answered just on your question how to balance teams and with this balance will be +-1 player in team if total of players who want to join is odd number. If it is even number than teams will have same number of players.
what if both teams have same amount of players?
 
Top