Raised This Month: $ Target: $400
 0% 

Count Alive Players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
brhvitor6
Member
Join Date: Oct 2012
Old 02-11-2013 , 22:57   Count Alive Players
Reply With Quote #1

There is any functions to count how many players are alive?

Thx again
brhvitor6 is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 02-11-2013 , 23:01   Re: Count Alive Players
Reply With Quote #2

Create a global variable with a name "count" as an example, then hook the player_spawn and player_death event.

Do count++; on player_spawn and count--; on player_death.
__________________

Last edited by Chaosxk; 02-11-2013 at 23:02.
Chaosxk is offline
MPQC
SourceMod Donor
Join Date: Dec 2011
Old 02-12-2013 , 00:00   Re: Count Alive Players
Reply With Quote #3

For an actual function...

Code:
CountAlive()
{
    new count;
    for (new i = 1; i < MaxClients; i++)
    {
        if (IsClientInGame(i))
        {
            if (IsPlayerAlive(I))
            {
                count++;
            }
        }
    }
    return count;
}
__________________
MPQC is offline
pheadxdll
AlliedModders Donor
Join Date: Jun 2008
Old 02-12-2013 , 00:03   Re: Count Alive Players
Reply With Quote #4

Wrong, it should be i<=MaxClients, otherwise you'll skip a player.

Code:
CountAlive()
{
     new iNum;
     for(new i=1; i<=MaxClients; i++) if(IsClientInGame(i) && IsPlayerAlive(i)) iNum++;
     return iNum;
}
__________________
pheadxdll is offline
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 02-12-2013 , 01:52   Re: Count Alive Players
Reply With Quote #5

Quote:
Originally Posted by Chaosxk View Post
Create a global variable with a name "count" as an example, then hook the player_spawn and player_death event.

Do count++; on player_spawn and count--; on player_death.
Hehe lol need something similiar not long ago, its simple and reliable.
hadnt tought of that :p.
__________________

Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]
striker07 is offline
brhvitor6
Member
Join Date: Oct 2012
Old 02-12-2013 , 09:51   Re: Count Alive Players
Reply With Quote #6

thx, i tried something similar but doesnt work. Thx again guys
brhvitor6 is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 02-12-2013 , 13:18   Re: Count Alive Players
Reply With Quote #7

If you posted your code then it would be much easier to see the problem.
__________________
Chaosxk is offline
brhvitor6
Member
Join Date: Oct 2012
Old 02-12-2013 , 13:35   Re: Count Alive Players
Reply With Quote #8

my error:
I was used
for(new i=0; i<=MaxClients; i++)
insted of
for(new i=1; i<=MaxClients; i++)
brhvitor6 is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 02-12-2013 , 18:16   Re: Count Alive Players
Reply With Quote #9

Wouldn't have made a difference.
__________________
11530 is offline
brhvitor6
Member
Join Date: Oct 2012
Old 02-12-2013 , 20:52   Re: Count Alive Players
Reply With Quote #10

actually when i try to find the index 0 it returns a error saying that there is no index 0
brhvitor6 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 13:49.


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