AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Randomize Teams (https://forums.alliedmods.net/showthread.php?t=306956)

ish12321 04-20-2018 05:51

Randomize Teams
 
Hello,
Could someone please help me with a code snippet that can be used to randomize teams ? I tried something but that made, most of the time, unbalanced teams, i.e., the number of players in CT and T have a difference more than 1.

Natsheh 04-20-2018 05:55

Re: Randomize Teams
 
Post the code .

ish12321 04-20-2018 06:33

Re: Randomize Teams
 
Actually I'm not getting the perfwct way to do it. What I'm doing is just using random_num() function with cs_set_user_team

soumyadip77 04-20-2018 08:13

Re: Randomize Teams
 
PHP Code:

public RandomTeams()
{
    
MatchStart true

    
new players[32], pnumtempid;
    
    
get_players(playerspnum"h");

    for( new 
ii<pnumi++ ) 
    {
        
tempid players[i];
        
        switch ( 
cs_get_user_teamtempid ) )
        {
            case 
CS_TEAM_TCS_TEAM_CT:
            {
                if(
is_user_alivetempid))
                
                
user_silentkill(tempid);

                
rg_set_user_team(tempidTEAM_SPECTATORMODEL_AUTOtrue)
            }
        }
    }
    new 
topickidop

    
while (AnyoneInSpec()) 
    {
        if (
cs_get_user_team(players[idop]) == CS_TEAM_UNASSIGNED)
        {
            
idop++
            continue;
        }

        
topick random(2)

        if (
topick == 1)
        {
            
rg_set_user_team(players[idop], TEAM_TERRORISTMODEL_AUTOtrue)
        }
        else
        {
            
rg_set_user_team(players[idop], TEAM_CTMODEL_AUTOtrue)
        }
        new 
pplayers[32], ppnumtempid;

        new 
ppplayers[32], pppnum;

        new 
temppnum


        get_players
(playerspnum"h");

        
get_players(pplayersppnum"he""CT")

        
get_players(ppplayerspppnum"he""TERRORIST")
        
        if (
ppnum == pnum/2)
        {
            
get_players(playerstemppnum"h");
            
            for( new 
ii<temppnumi++ )
            {
                
tempid players[i];
                
                if (
cs_get_user_team(tempid) == CS_TEAM_SPECTATOR)
                {
                    
rg_set_user_team(tempidTEAM_TERRORISTMODEL_AUTOtrue)
                }
            }
        }
        
        else if (
pppnum == pnum/2)
        {
            
get_players(playerstemppnum"h");
            
            for( new 
ii<temppnumi++ )
            {
                
tempid players[i];
                
                if (
cs_get_user_team(tempid) == CS_TEAM_SPECTATOR)
                {
                    
rg_set_user_team(tempidTEAM_CTMODEL_AUTOtrue)
                }
            }
        }
        
        
idop++
    }




^SmileY 04-20-2018 09:08

Re: Randomize Teams
 
Search bro,

https://forums.alliedmods.net/showpo...03&postcount=5

ish12321 04-20-2018 09:50

Re: Randomize Teams
 
Quote:

Originally Posted by ^SmileY (Post 2588604)

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

GoldNux 04-21-2018 05:28

Re: Randomize Teams
 
Quote:

Originally Posted by ish12321 (Post 2588610)
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

ish12321 04-21-2018 10:10

Re: Randomize Teams
 
Quote:

Originally Posted by GoldNux (Post 2588683)
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.

GoldNux 04-21-2018 12:41

Re: Randomize Teams
 
Quote:

Originally Posted by ish12321 (Post 2588720)
That is not what I require.

It can randomize the teams, but it might not do it the way you want.

ish12321 04-21-2018 15:37

Re: Randomize Teams
 
Quote:

Originally Posted by GoldNux (Post 2588732)
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


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

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