AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Get a random player from CT&T team (https://forums.alliedmods.net/showthread.php?t=208841)

11922911 02-18-2013 01:14

Get a random player from CT&T team
 
PHP Code:

new iPlayers[32], iPlayersNum;
get_playersiPlayersiPlayersNum"h" )

new 
iBitsumiCountplayeri;
for( 
0iPlayersNum++ )
{
    
player iPlayers[i]
    if( 
<= _:cs_get_user_team(player) <= )
    {
        
iBitsum |= (1<<player)
        
iCount++
    }
}

if( !
iCount ) return;

new 
iRandom random(iCount);
iCount 0
for( 0iPlayersNum++ )
{
    
player iPlayers[i]
    if( 
iBitsum & (1<<player) )
        
iCount ++;

    if( 
iCount == iRandom )
    {
        
iRandom player
        
break;
    }


PHP Code:

new iRandom;
new 
iPlayers[32], iCount;
get_playersiPlayersiCount"e""TERRORIST" )
if( 
iCount iRandom iPlayers[random(iCount)]
get_playersiPlayersiCount"e""CT" )
if( 
iCount && (!iRandom || random_num(01)) ) iRandom iPlayers[random(iCount)] 

PHP Code:

new g_iMaxPlayers get_maxplayers();
new 
iPlayers[32], iCounti;
for( 
1g_iMaxPlayers++ )
{
    if( 
is_user_connected(i) && (<= _:cs_get_user_team(i) <= 2) )
    {
        
iPlayers[i] = iCount
        iCount 
++
    }
}

if( !
iCount ) return;
new 
iRandom iPlayers[random(iCount)] 

PHP Code:

new iRandomiPlayers[32], iCount 1;
while( 
iCount && !iRandom )
{
    
get_playersiPlayersiCount"h" )
    
iRandom random(iPlayers[iCount])
    if( !(
<= _:cs_get_user_team(iRandom) <= 2) ) iRandom 0


I have no idea what is the best way to do this.
:cry:

YamiKaitou 02-18-2013 01:22

Re: Get Random Player?
 
PHP Code:

new Players[32], iPlayersiRandomPlayer;
get_players(PlayersiPlayers"h");
iRandomPlayer Players[random(iPlayers)];
// iRandomPlayer contains the Index of a random player 


11922911 02-18-2013 01:24

Re: Get Random Player?
 
but i want to skip non CT/T player

YamiKaitou 02-18-2013 01:39

Re: Get Random Player?
 
Quote:

Originally Posted by 11922911 (Post 1896628)
but i want to skip non CT/T player

Then you should have said so. You only asked how to get a random player. So you want a random player that is on the SPECTATOR team?

11922911 02-18-2013 01:54

Re: Get a random player from CT&T team
 
Thanks for your tips, edited.

Podarok 02-18-2013 01:55

Re: Get a random player from CT&T team
 
No, he wants to skip SPECTATOR team. Just check the team
PHP Code:

cs_get_user_team(id) != CS_TEAM_SPECTATOR 


hleV 02-18-2013 09:12

Re: Get a random player from CT&T team
 
Should work.
PHP Code:

GetRandomInTeamPlayer()
{
    new 
ts[32], cts[32];
    new 
tCountctCount;
    
get_players(tstCount"e""TERRORIST");
    
get_players(ctsctCount"e""CT");
    
    if (!
tCount && !ctCount)
        return 
0;
    
    new 
index random(tCount ctCount);
    
    if (
index >= tCount)
        return 
cts[index tCount];
    
    return 
ts[index];




All times are GMT -4. The time now is 21:39.

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