Raised This Month: $32 Target: $400
 8% 

[Help] Get total players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Adventx
Member
Join Date: Feb 2014
Location: Romania
Old 08-11-2017 , 16:07   [Help] Get total players
Reply With Quote #1

Hello, I need stock to get all players on server, team and if it's alive.

Thx!
Adventx is offline
Send a message via Yahoo to Adventx
kristi
Senior Member
Join Date: Nov 2016
Old 08-11-2017 , 18:17   Re: [Help] Get total players
Reply With Quote #2

Code:
alivenum() {     new iPlayers[32], iNum;     get_players(iPlayers, iNum, "a");         return iNum; }

Last edited by kristi; 08-11-2017 at 18:17.
kristi is offline
Send a message via Skype™ to kristi
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 08-12-2017 , 07:01   Re: [Help] Get total players
Reply With Quote #3

Quote:
Originally Posted by kristi View Post
Code:
alivenum() {     new iPlayers[32], iNum;     get_players(iPlayers, iNum, "a");         return iNum; }
This will get all the alive players, but won't be seperated in teams.
Code:
stock GetPlayers(iTeam /*1 = TR & 2 = CT*/, bool:alive = false) {     new iPlayers[32], iNum;     get_players(iPlayers, iNum, alive ? "aceh" : "bce", iTeam == 1 ? "TERRORIST" : "CT");     return iNum; }
__________________

Last edited by Napoleon_be; 08-13-2017 at 21:12.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Adventx
Member
Join Date: Feb 2014
Location: Romania
Old 08-17-2017 , 12:59   Re: [Help] Get total players
Reply With Quote #4

Quote:
Originally Posted by Napoleon_be View Post
This will get all the alive players, but won't be seperated in teams.
Code:
stock GetPlayers(iTeam /*1 = TR & 2 = CT*/, bool:alive = false) {     new iPlayers[32], iNum;     get_players(iPlayers, iNum, alive ? "aceh" : "bce", iTeam == 1 ? "TERRORIST" : "CT");     return iNum; }
Thanks,

I have this stock, it's good or not ?

PHP Code:
stock Get_PlayerCount(AliveTeam
// Alive: 0 - Dead | 1 - Alive | 2 - Both 
// Team: 1 - T | 2 - CT 

    new 
Flag[4], Flag2[12
    new 
Players[32], PlayerNum 

    
if(!Aliveformatex(Flagsizeof(Flag), "%sb"Flag
    else if(
Alive == 1formatex(Flagsizeof(Flag), "%sa"Flag
     
    if(
Team == 1)  
    { 
        
formatex(Flagsizeof(Flag), "%se"Flag
        
formatex(Flag2sizeof(Flag2), "TERRORIST"Flag
    } else if(
Team == 2)  
    { 
        
formatex(Flagsizeof(Flag), "%se"Flag
        
formatex(Flag2sizeof(Flag2), "CT"Flag
    } 
     
    
get_players(PlayersPlayerNumFlagFlag2
     
    return 
PlayerNum 

Adventx is offline
Send a message via Yahoo to Adventx
simanovich
AlliedModders Donor
Join Date: Jun 2012
Location: Israel
Old 08-17-2017 , 14:54   Re: [Help] Get total players
Reply With Quote #5

Your stock won't work, formatex native doesn't support copy-back function (without it the native will run faster but won't allow this kind of stuff: formatex(buffer, len, "%s", buffer) ).
__________________
simanovich is offline
Adventx
Member
Join Date: Feb 2014
Location: Romania
Old 08-17-2017 , 17:11   Re: [Help] Get total players
Reply With Quote #6

Quote:
Originally Posted by simanovich View Post
Your stock won't work, formatex native doesn't support copy-back function (without it the native will run faster but won't allow this kind of stuff: formatex(buffer, len, "%s", buffer) ).
Can you help plss ?
Adventx is offline
Send a message via Yahoo to Adventx
.Ahlach_.
Junior Member
Join Date: Dec 2015
Old 08-18-2017 , 06:31   Re: [Help] Get total players
Reply With Quote #7

PHP Code:
#include <amxmodx>
#include <cstrike>

new all_ttall_ct;
new 
alive_ttalive_ct;

public 
plugin_init() register_clcmd("say /test""TestCommand");

public 
TestCommand(id) {
    
UpdatePlayers();

    
client_print(id3"On the server is:");
    
client_print(id3"%i terrorists (%i alive), %i cts (%i alive)"all_ttalive_ttall_ctalive_ct);
}

stock UpdatePlayers() {
    
all_tt ActivePlayers(CS_TEAM_T);
    
all_ct ActivePlayers(CS_TEAM_CT);
    
alive_tt ActivePlayers(CS_TEAM_Ttrue);
    
alive_ct ActivePlayers(CS_TEAM_CTtrue);
}

stock ActivePlayers(CsTeams:teambool:alive false) {
    static 
players[32], numiactive;
    
get_players(playersnumalive "ach" "bc");
    
active 0;
    for(
0numi++)
        if(
cs_get_user_team(players[i]) == teamactive++;

    return 
active;

.Ahlach_. is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 08-18-2017 , 18:30   Re: [Help] Get total players
Reply With Quote #8

how about this?

PHP Code:

get_playersnum_flags
(const flags[]="ch", const team[]="")
/* flags a=get alive players only || b=get dead players only || e=include team(use the team parameter) || c=don't include bots || h=don't include HLTV */
        
new players[32],pnum;
        
get_players(players,pnum,flags,team// check out more flags in the documentation (amxmodx.inc) 
        
return pnum;

__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 08-18-2017 at 18:34.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Adventx
Member
Join Date: Feb 2014
Location: Romania
Old 08-20-2017 , 12:28   Re: [Help] Get total players
Reply With Quote #9

What do you think about this code
PHP Code:
stock get_player_num(teamalive)
{
    static 
player_num
    player_num 
0
    
    
for(new 0g_MaxPlayersi++)
    {
        if(!
is_user_connected(i))
            continue
            
        if(
alive == AL_NOT)
        {
            if(
is_user_alive(i))
                continue
                
        }
        
        else if(
alive == AL_ALIVE)
        {
            if(!
is_user_alive(i))
                continue    
        }
        
        if(
team == TEAM_ALL)
        {
            if(
cs_get_user_team(i) == CS_TEAM_UNASSIGNED || cs_get_user_team(i) == CS_TEAM_SPECTATOR)
                continue
        }
        
        else if(
team == TEAM_T)
        {
            if(
cs_get_user_team(i) != CS_TEAM_T)
                continue
        }
        
        else if(
team == TEAM_CT) {
            if(
cs_get_user_team(i) != CS_TEAM_CT)
                continue
        }
        
        
player_num++
    }
    
    return 
player_num

I need efficiency stock to get players, can u help me pls ?

I've looked into the zombie plague 5.0 mod and here is the another method, which is great ?

PHP Code:
// Get Zombie Count -returns alive zombies number-
GetZombieCount()
{
    new 
iZombiesid
    
    
for (id 1id <= g_MaxPlayersid++)
    {
        if (
is_user_alive(id) && flag_get(g_IsZombieid))
            
iZombies++
    }
    
    return 
iZombies;
}

// Get Human Count -returns alive humans number-
GetHumanCount()
{
    new 
iHumansid
    
    
for (id 1id <= g_MaxPlayersid++)
    {
        if (
is_user_alive(id) && !flag_get(g_IsZombieid))
            
iHumans++
    }
    
    return 
iHumans;

Adventx is offline
Send a message via Yahoo to Adventx
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-20-2017 , 12:42   Re: [Help] Get total players
Reply With Quote #10

Simply use get_players() as suggested.
__________________
fysiks is offline
Reply


Thread Tools
Display Modes

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 07:18.


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