AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   get_players team (https://forums.alliedmods.net/showthread.php?t=129484)

Backstabnoob 06-13-2010 10:33

get_players team
 
How can I get only terrorists or counter-terrorists in get_players()? with corresponding count.

For cstrike.

#8 SickneSS 06-13-2010 10:39

Re: get_players team
 
new iPlayers[32]
new iNum

get_players(iPlayers, iNum, "ch" /*Ingnores Bots and HLTV */, "TERRORIST" or "CT")

Backstabnoob 06-13-2010 11:03

Re: get_players team
 
get_players(players,num,"ceh","TERRORIST");

This returns CTs, too.

Edit:

This should select one player as a random T:
PHP Code:

public random_t()
{
    new 
players[g_maxplayers];
    static 
num;
    
    
get_players(players,num,"ceh","TERRORIST");
    
    if(
num)
    {
        new 
random_num(1num);
        
        if(
is_user_connected(x) && is_user_alive(x))
            
g_random_t x;
    }



grimvh2 06-13-2010 14:54

Re: get_players team
 
PHP Code:

RandomPlayer()
{
    new 
players[32], pnum;
    
get_players(playerspnum);
    
// get_players(players, pnum, "e", "CT");
    //get_players(players, pnum, "e", "TERRORIST"
   
    
if( !pnum ) return -1;
    
    return 
players[random(pnum)];



Upri98 01-26-2020 05:24

Re: get_players team
 
Quote:

Originally Posted by grimvh2 (Post 1207798)
PHP Code:

RandomPlayer()
{
    new 
players[32], pnum;
    
get_players(playerspnum);
    
// get_players(players, pnum, "e", "CT");
    //get_players(players, pnum, "e", "TERRORIST"
   
    
if( !pnum ) return -1;
    
    return 
players[random(pnum)];



Can someone explain this step?
Does it have any return value or smth?

Code:

if( !pnum )

thEsp 01-26-2020 06:05

Re: get_players team
 
Dude why do you even bother restoring a 10 years old thread? :O
Either way, if there are no players (!pnum) the function returns -1.

HamletEagle 01-26-2020 06:18

Re: get_players team
 
Quote:

Originally Posted by thEsp (Post 2681668)
Dude why do you even bother restoring a 10 years old thread? :O
Either way, if there are no players (!pnum) the function returns -1.

Because he has a legitimate question about the topic.

pnum is the number of players. If pnum is 0(!pnum is the same as pnum == 0) then there are no players so a random player cannot be retrieved.

Bugsy 01-26-2020 11:54

Re: get_players team
 
Yeah, I give him credit for searching first.

Upri98, to use that RandomPlayer function you would do something like:
PHP Code:

new iRandom RandomPlayer();

if ( 
iRandom == -)
{
    
//No random players available
}
else
{
    
//iRandom is your random player




All times are GMT -4. The time now is 14:56.

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