AlliedModders

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

fmfs10 03-16-2010 15:48

Randomize teams
 
Hello... Like i said in another post (just edited it because i don't need this anymore), i'm making a for MIX, CPL and CF.
I just want to know, how can i put players from spec to a random team, respecting the limitteams of course. And if possible, show to me how everything is working

Sorry for my bad english

And thanks for you response =D

Brreaker 03-16-2010 16:12

Re: Randomize teams
 
register_clcmd("amx_random", "pRandom", ADMIN_KICK, "Random player teams")

public pRandom(id) {
new iRandomNum = random_num(0, 1)
switch(iRandomNum) {
case 0: cs_set_user_team(id, CS_TEAM_T)
case 1: cs_set_user_team(id, CS_TEAM_CT)
}

Just a suggestion :)

grimvh2 03-16-2010 16:18

Re: Randomize teams
 
I use this ,
pretty easy but it does the trick xD

PHP Code:

public RandomTeams() // Randomize Teams
{
    new 
players[32], pnumplayerctsts;
    
get_players(playerspnum);
    
    for( new 
i=0i<pnumi++ )
    {
        
player players[i];
        
        if(!
cts && !ts)
        {
            
select_model(player,1,random_num(1,4));
            
ts++;
            
cts=0;
        }
        else if(!
cts && ts)
        {
            
select_model(player,2,random_num(1,4));
            
ts=0;
            
cts++;
        }
        else if(
cts && !ts)
        {
            
select_model(player,1,random_num(1,4));
            
ts++;
            
cts=0;
        }
    }
}


select_model(idteammodel// Set Models
{
    switch(
team) {
        case 
1: {
            switch(
model) {
                case 
1cs_set_user_team(idCS_TEAM_TCS_T_TERROR);
                case 
2cs_set_user_team(idCS_TEAM_TCS_T_LEET);
                case 
3:    cs_set_user_team(idCS_TEAM_TCS_T_ARCTIC);
                case 
4cs_set_user_team(idCS_TEAM_TCS_T_GUERILLA);
            }
        }
        case 
2: {
            switch(
model) {
                case 
1cs_set_user_team(idCS_TEAM_CTCS_CT_URBAN);
                case 
2cs_set_user_team(idCS_TEAM_CTCS_CT_GSG9);
                case 
3cs_set_user_team(idCS_TEAM_CTCS_CT_SAS);
                case 
4cs_set_user_team(idCS_TEAM_CTCS_CT_GIGN);
                case 
5cs_set_user_team(idCS_TEAM_CTCS_CT_VIP); //my lil secret
            
}
        }
        case 
3: {
            
cs_set_user_team(idCS_TEAM_SPECTATORCS_DONTCHANGE);
            if(
is_user_alive(id))
                
user_kill(id);
        }
    }



fmfs10 03-17-2010 11:03

Re: Randomize teams
 
Thanks! :wink:
Working great !

Exolent[jNr] 03-17-2010 11:29

Re: Randomize teams
 
Here is a real way to randomize teams.
grim's will be the same each time.

Code:
RandomizeTeams( ) {     new iPlayers[ 32 ], iNum;     get_players( iPlayers, iNum );         for( new i = 0; i < iNum; i++ )     {         if( !( CS_TEAM_T <= cs_get_user_team( iPlayers[ i ] ) <= CS_TEAM_CT ) )         {             iPlayers[ i-- ] = iPlayers[ --iNum ];         }     }         new iPlayer, CsTeams:iTeam = random( 2 ) ? CS_TEAM_T : CS_TEAM_CT;         new iRandom;         while( iNum )     {         iRandom = random( iNum );                 iPlayer = iPlayers[ iRandom ];                 cs_set_user_team( iPlayer, iTeam );                 iPlayers[ iRandom ] = iPlayers[ --iNum ];                 iTeam = CsTeams:( ( _:iTeam ) % 2 + 1 );     } }

grimvh2 03-17-2010 13:02

Re: Randomize teams
 
Quote:

Originally Posted by Exolent[jNr] (Post 1120403)
Here is a real way to randomize teams.
grim's will be the same each time.

Code:
RandomizeTeams( ) { new iPlayers[ 32 ], iNum;
get_players( iPlayers, iNum );

for( new i = 0; i < iNum; i++ ) { if( !( CS_TEAM_T <= cs_get_user_team( iPlayers[ i ] ) <= CS_TEAM_CT ) ) { iPlayers[ i-- ] = iPlayers[ --iNum ];
} } new iPlayer, CsTeams:iTeam = random( 2 ) ? CS_TEAM_T : CS_TEAM_CT;

new iRandom;

while( iNum ) { iRandom = random( iNum );

iPlayer = iPlayers[ iRandom ];

cs_set_user_team( iPlayer, iTeam );

iPlayers[ iRandom ] = iPlayers[ --iNum ];

iTeam = CsTeams:( ( _:iTeam ) % 2 + 1 );
} }


Thats why it was cheap :p

fmfs10 03-17-2010 18:24

Re: Randomize teams
 
Yeah i thinked this too...
But why new iPlayers[32] and not [33]?

Is 0 counting as a player too?

EDIT@

In this way, i can't get players from spec... Why?[

EDITē@

You can't change your name with this, and when you try to change your name, sv_restart doesn't work anymore (i've puted server_cmd(amx_cvar sv_restart 1) in the plugin...)

wrecked_ 03-18-2010 00:09

Re: Randomize teams
 
Quote:

Originally Posted by fmfs10 (Post 1120862)
Yeah i thinked this too...
But why new iPlayers[32] and not [33]?

Is 0 counting as a player too?

No, it is iPlayers[32] because there are 32 cells in that array. Once it is initialized, it becomes 0-31. 0 is not counted when you declare it.

Exolent[jNr] 03-18-2010 00:39

Re: Randomize teams
 
Quote:

Originally Posted by fmfs10 (Post 1120862)
EDIT@

In this way, i can't get players from spec... Why?[

EDITē@

You can't change your name with this, and when you try to change your name, sv_restart doesn't work anymore (i've puted server_cmd(amx_cvar sv_restart 1) in the plugin...)

1. Remove this part:

Code:
    for( new i = 0; i < iNum; i++ )     {         if( !( CS_TEAM_T <= cs_get_user_team( iPlayers[ i ] ) <= CS_TEAM_CT ) )         {             iPlayers[ i-- ] = iPlayers[ --iNum ];         }     }

2. That code snippet has nothing to do with those bugs.
It has to be something else in your code.

hleV 03-18-2010 05:58

Re: Randomize teams
 
PHP Code:

engclient_cmd(0"jointeam""5"); 



All times are GMT -4. The time now is 08:38.

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