Raised This Month: $51 Target: $400
 12% 

Solved Randomize Teams


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

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.
__________________
['O|s|G'] | Death Wins a.k.a Ish Chhabra was here

Last edited by ish12321; 04-23-2018 at 23:50.
ish12321 is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 04-20-2018 , 05:55   Re: Randomize Teams
Reply With Quote #2

Post the code .
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
ish12321
Veteran Member
Join Date: May 2016
Old 04-20-2018 , 06:33   Re: Randomize Teams
Reply With Quote #3

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
__________________
['O|s|G'] | Death Wins a.k.a Ish Chhabra was here
ish12321 is offline
soumyadip77
Senior Member
Join Date: Jul 2017
Location: INDIA,KOLKATA
Old 04-20-2018 , 08:13   Re: Randomize Teams
Reply With Quote #4

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++
    }


soumyadip77 is offline
Send a message via Skype™ to soumyadip77
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 04-20-2018 , 09:08   Re: Randomize Teams
Reply With Quote #5

Search bro,

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

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
ish12321
Veteran Member
Join Date: May 2016
Old 04-20-2018 , 09:50   Re: Randomize Teams
Reply With Quote #6

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 #7

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 #8

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 #9

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 #10

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
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 00:19.


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