AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   check team player number (https://forums.alliedmods.net/showthread.php?t=133080)

JeweL` 07-21-2010 17:07

check team player number
 
sorry for my english..

i want to write this on server

%s player on terrorists team, %s player on counter terrorist team..

how i can check that numbers of team players. i didnt find it.

grimvh2 07-21-2010 17:34

Re: check team player number
 
PHP Code:


new players[32], tnumctnum
get_players
(players,ctnum,"e""CT")
get_players(players,tnum,"e""TERRORIST")

// then print tnum and ctnum, thats %i not %s 


ot_207 07-21-2010 17:40

Re: check team player number
 
PHP Code:

#include <cstrike>
#include <amxmodx>

// plugin_init BLA BLA

public client_connect(id)
{
    new 
total get_maxplayers()
    new 
ts
    
new ct
    
    
for (new i=1;i<=total;i++)
    {
        if (
is_user_connected(i))
        {
            if (
cs_get_user_team(i) == CS_TEAM_T)
                
ts++
            if (
cs_get_user_team(i) == CS_TEAM_CT)
                
ct++
        }
    }
    
    
client_print(0print_chat"%d Tero %d CT"tsct)


Wrote it here. So try to be careful when testing it.

grimvh2 07-21-2010 17:53

Re: check team player number
 
ot, can get wrong. U should add a bool and set it true when he connects and false when he disconnects and use that bool instead of is_user_connected().
Worked fine with me on my private projects.

drekes 07-21-2010 18:33

Re: check team player number
 
I would use something like this:
PHP Code:

stock get_terro_amount()
{
    new 
players[32], pnumtempidamount;
    
get_players(playerspnum);
    
    for(new 
0pnumi++)
    {
        
tempid players[i];
        
        if(
is_user_connected(tempid))
        {
            if(
get_user_team(tempid) == 1)
                
amount++;
        }
    }
    
    return 
amount;
}

stock get_ct_amount()
{
    new 
players[32], pnumtempidamount;
    
get_players(playerspnum);
    
    for(new 
0pnumi++)
    {
        
tempid players[i];
        
        if(
is_user_connected(tempid))
        {
            if(
get_user_team(tempid) == 2)
                
amount++;
        }
    }
    
    return 
amount;



Bugsy 07-21-2010 19:27

Re: check team player number
 
untested
PHP Code:

//Usage
new iTs iCTs;
GetTeamCountsiTs iCTs );
client_printprint_chat "Terrorist=%d CT=%d" iTs iCTs );

public 
GetTeamCounts( &TCount , &CTCount )
{
    new 
iMaxPlayers get_maxplayers();
    
TCount 0;
    
CTCount 0;

    for ( new 
<= iMaxPlayers i++ )
    {
        if ( !
is_user_connected) )
            continue;

        switch ( 
cs_get_user_team) )
        {
            case 
CS_TEAM_TTCount++;
            case 
CS_TEAM_CTCTCount++;
        }
    }



fysiks 07-21-2010 21:08

Re: check team player number
 
@drekes, if you use get_players() you don't need to check if they are connected. get_players() won't return non-connected players.

Kreation 07-21-2010 21:12

Re: check team player number
 
Quote:

Originally Posted by fysiks (Post 1247360)
@drekes, if you use get_players() you don't need to check if they are connected. get_players() won't return non-connected players.

Really? Never knew that, I think I got a run time error before from that. Guess not, I'll remove that from my stock.

fysiks 07-21-2010 21:19

Re: check team player number
 
Quote:

Originally Posted by Kreation (Post 1247363)
Really? Never knew that, I think I got a run time error before from that. Guess not, I'll remove that from my stock.

If it returned non-connected players then get_players() would look like:

Code:

stock get_players(players[], &num)
{
    players[0] = 1
    players[1] = 2
    // ...
    players[31] = 32
    num = 32
}

Correct me if you feel that I am wrong.

K.K.Lv 07-21-2010 21:41

Re: check team player number
 
PHP Code:

stock get_team_playernum(iTeam) {
    static 
players[32], num
    
static iNum
    get_players
(playersnum)
    for (new 
0numi++) {
        if (
get_user_team(players[i]) == iTeam) {
            
iNum++
        }
    }
    return 
iNum


un-test.

Quote:

should add a bool and set it true when he connects and false when he disconnects
you can do it like the following code, then, I think you needn't to check when player disconnect.
should work:
PHP Code:

 
const BOOL_ARRAY[33] = {false,...}
 
new 
bool:g_bvar[33]
 
public 
client_connect(id) {
    
g_bvar BOOL_ARRAY
    g_bvar
[id] = true




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

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