Raised This Month: $ Target: $400
 0% 

Solved Randomize Teams


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ish12321
Veteran Member
Join Date: May 2016
Old 04-20-2018 , 09:50   Re: Randomize Teams
Reply With Quote #1

Quote:
Originally Posted by ^SmileY View Post
I searched but failed to find it. Thanks.

EDIT : As per what I see it is just a sequence like first t second ct third t and so on. Would that not make the randomization each time same until players' id change (some leave and new join). As per this I find there will be only 2 possible cases. I wished something more random
__________________
['O|s|G'] | Death Wins a.k.a Ish Chhabra was here

Last edited by ish12321; 04-20-2018 at 09:53.
ish12321 is offline
GoldNux
Senior Member
Join Date: Mar 2018
Old 04-21-2018 , 05:28   Re: Randomize Teams
Reply With Quote #2

Quote:
Originally Posted by ish12321 View Post
I searched but failed to find it. Thanks.

EDIT : As per what I see it is just a sequence like first t second ct third t and so on. Would that not make the randomization each time same until players' id change (some leave and new join). As per this I find there will be only 2 possible cases. I wished something more random
Check out this plugin that me and my friend put together, bump it if you like it.
https://forums.alliedmods.net/showth...82#post2586082
__________________
Try my version of de_dust2, I think it's great and you should check it out!
https://gamebanana.com/mods/83731

Last edited by GoldNux; 04-21-2018 at 05:28.
GoldNux is offline
ish12321
Veteran Member
Join Date: May 2016
Old 04-21-2018 , 10:10   Re: Randomize Teams
Reply With Quote #3

Quote:
Originally Posted by GoldNux View Post
Check out this plugin that me and my friend put together, bump it if you like it.
https://forums.alliedmods.net/showth...82#post2586082
That is not what I require.
__________________
['O|s|G'] | Death Wins a.k.a Ish Chhabra was here
ish12321 is offline
GoldNux
Senior Member
Join Date: Mar 2018
Old 04-21-2018 , 12:41   Re: Randomize Teams
Reply With Quote #4

Quote:
Originally Posted by ish12321 View Post
That is not what I require.
It can randomize the teams, but it might not do it the way you want.
__________________
Try my version of de_dust2, I think it's great and you should check it out!
https://gamebanana.com/mods/83731
GoldNux is offline
ish12321
Veteran Member
Join Date: May 2016
Old 04-21-2018 , 15:37   Re: Randomize Teams
Reply With Quote #5

Quote:
Originally Posted by GoldNux View Post
It can randomize the teams, but it might not do it the way you want.
Well, thanks for trying to help. I've found a solution myself .
I use random_num(1, 2) and then balance teams such that the number of players in the teams has a max diff of 1
__________________
['O|s|G'] | Death Wins a.k.a Ish Chhabra was here
ish12321 is offline
ish12321
Veteran Member
Join Date: May 2016
Old 04-22-2018 , 14:31   Re: Randomize Teams
Reply With Quote #6

PHP Code:
new players[MAX_PLAYERS], numplayer;
    
get_players_ex(playersnumGetPlayers_ExcludeHLTV);    
    
    for(new 
0numi++)
    {
        
player players[i];

        if(
cs_get_user_team(player) == CS_TEAM_UNASSIGNED)
        {
            continue;
        }

        
user_kill(player);
        
cs_set_user_team(playerCS_TEAM_SPECTATOR);

    }
    
    
get_players_ex(playersnumGetPlayers_ExcludeHLTV GetPlayers_MatchTeam"SPECTATOR");

    for(new 
0numi++)
    {
        
player players[i];
        
cs_set_user_team(playerCsTeams:random_num(12));
    }

    new 
players_CT[MAX_PLAYERS], players_T[MAX_PLAYERS], num_CTnum_T;
    
get_players_ex(players_CTnum_CTGetPlayers_ExcludeHLTV GetPlayers_MatchTeam"CT");
    
get_players_ex(players_Tnum_TGetPlayers_ExcludeHLTV GetPlayers_MatchTeam"TERRORIST");
    
    if(
num_CT num_T)
    {
        for(new 
0num_CTi++)
        {
            if((
num_CT num_T) <= 1)
            {
                break;
            }

            
player players_CT[i];

            
cs_set_user_team(playerCS_TEAM_T);
        }
    }
    else if(
num_T num_CT)
    {
        for(new 
0num_Ti++)
        {
            if((
num_T num_CT) <= 1)
            {
                break;
            }

            
player players_T[i];

            
cs_set_user_team(playerCS_TEAM_CT);
        }
    } 
This is the code I used to randomize teams. It works perfectly for most time ,but sometimes is it sending all players to T or CT. Could someone please check it and point me out the bug ?
__________________
['O|s|G'] | Death Wins a.k.a Ish Chhabra was here
ish12321 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-22-2018 , 19:04   Re: Randomize Teams
Reply With Quote #7

Quote:
Originally Posted by ish12321 View Post
This is the code I used to randomize teams. It works perfectly for most time ,but sometimes is it sending all players to T or CT. Could someone please check it and point me out the bug ?
It's likely because when you're balancing them out you never subtract & add from each team count when moving a player to the opposite team. The for-loop continues for the entirety of num_CT or num_T since the if((num_TEAM1 - num_TEAM2) <= 1) condition never changes.
Code:
if(num_CT > num_T) {     for(new i = 0; i < num_CT; i++)     {         if((num_CT - num_T) <= 1)         {             break;         }                 player = players_CT[i];                 cs_set_user_team(player, CS_TEAM_T);         num_CT--;         num_T++;     } } else if(num_T > num_CT) {     for(new i = 0; i < num_T; i++)     {         if((num_T - num_CT) <= 1)         {             break;         }                 player = players_T[i];                 cs_set_user_team(player, CS_TEAM_CT);         num_T--;         num_CT++;     } }
__________________

Last edited by Bugsy; 04-22-2018 at 19:08.
Bugsy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:41.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode