Raised This Month: $ Target: $400
 0% 

Get a random player from CT&T team


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
11922911
Senior Member
Join Date: Dec 2011
Location: Yuen Long Country
Old 02-18-2013 , 01:14   Get a random player from CT&T team
Reply With Quote #1

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.

Last edited by 11922911; 02-18-2013 at 10:56.
11922911 is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 02-18-2013 , 01:22   Re: Get Random Player?
Reply With Quote #2

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

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
11922911
Senior Member
Join Date: Dec 2011
Location: Yuen Long Country
Old 02-18-2013 , 01:24   Re: Get Random Player?
Reply With Quote #3

but i want to skip non CT/T player

Last edited by 11922911; 02-18-2013 at 01:24.
11922911 is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 02-18-2013 , 01:39   Re: Get Random Player?
Reply With Quote #4

Quote:
Originally Posted by 11922911 View Post
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?
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
11922911
Senior Member
Join Date: Dec 2011
Location: Yuen Long Country
Old 02-18-2013 , 01:54   Re: Get a random player from CT&T team
Reply With Quote #5

Thanks for your tips, edited.
11922911 is offline
Podarok
BANNED
Join Date: Jan 2011
Location: Narnia
Old 02-18-2013 , 01:55   Re: Get a random player from CT&T team
Reply With Quote #6

No, he wants to skip SPECTATOR team. Just check the team
PHP Code:
cs_get_user_team(id) != CS_TEAM_SPECTATOR 

Last edited by Podarok; 02-18-2013 at 01:55.
Podarok is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 02-18-2013 , 09:12   Re: Get a random player from CT&T team
Reply With Quote #7

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];

__________________

Last edited by hleV; 02-19-2013 at 06:31.
hleV 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 21:39.


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