AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Random player (https://forums.alliedmods.net/showthread.php?t=163798)

usaexelent 08-03-2011 10:41

Random player
 
How can i get a random player who's team is not unassigned and not spectator?
I'm making this function on round end

Korxu 08-03-2011 11:11

Re: Random player
 
Maybe this helps you. Look here and here.

get_players (wiki)

usaexelent 08-03-2011 12:43

Re: Random player
 
I know get player command but i need that if player team is spectator or unassigned then it would find other player who is alive.And if that player is dead to then find other player and so on

Bugsy 08-03-2011 12:59

Re: Random player
 
Use get_players()

hornet 08-03-2011 21:26

Re: Random player
 
PHP Code:

getRandPlayer()
{
    new 
players32 ], playernumpList33 ], count;
    
get_playersplayersnum"a" );
    for( new 
num ++ )
    {
        
player players];
        if( 
get_user_teamplayer ) != && get_user_teamplayer ) != )
        continue;
        
        
pListcount ] = player;
        
count ++;
    }
    
    return 
pListrandomcount ) ];



fysiks 08-03-2011 22:42

Re: Random player
 
Use a switch for get_user_team(). Also, no reason to use continue in code so small, it just makes it harder to read.

hornet 08-03-2011 22:50

Re: Random player
 
Quote:

Originally Posted by fysiks (Post 1525302)
Use a switch for get_user_team(). Also, no reason to use continue in code so small, it just makes it harder to read.

Yes Sir ;)

PHP Code:

getRandPlayer()
{
    new 
players32 ], playernumpList33 ], count;
    
get_playersplayersnum"a" );
    for( new 
num ++ )
    {
        
player players];
        if( 
get_user_teamplayer ) == || get_user_teamplayer ) == )
        {
            
pListcount ] = player;
            
count ++;
        }
    }
    
    return 
pListrandomcount ) ];


But to use a switch statement in there, wouldn't that make you have the result code would be written there twice? Or can you actually do
PHP Code:

case 2:
{
    
//


...?

fysiks 08-03-2011 23:01

Re: Random player
 
1, 2

jim_yang 08-03-2011 23:03

Re: Random player
 
or 0 < team < 3

fysiks 08-03-2011 23:06

Re: Random player
 
Quote:

Originally Posted by jim_yang (Post 1525313)
or 0 < team < 3

If you use get_user_team() there does it only get called once?


All times are GMT -4. The time now is 03:28.

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