How to get the ammount of players alive?
#6

Quote:
Originally Posted by Freddo [BINMAN
]
pawn Код:
new AliveCount;

for( new i = 0; i < MAX_PLAYERS; i++ )
{
    if( GetPlayerState( i ) != 7 )
    {
      AliveCount++;
    }
}
Using ******' foreach function would be more efficient. You'll have to reset the variables value (AliveCount = 0 every time you want to re-run the code, otherwise it'll pile on to each count, resulting in an inaccurate result.

For example:

pawn Код:
new AliveCount;

if( ! strcmp( cmdtext, "/alivecount", true ) )
{
    AliveCount = 0;
    for( new i = 0; i < MAX_PLAYERS; i++ )
    {
        if( GetPlayerState( i ) != 7 )
        {
          AliveCount++;
        }
    }
}
The code above should be used under OnPlayerCommandText.
It's compiling fine, now I want to display AliveCount in a Textdraw, but it isn'T working =S
pawn Код:
format(string, sizeof(string), "Players Alive: %s", AliveCount);
    TextDrawSetString(Textdraw0, string);
    TextDrawShowForAll(Text:Textdraw0);
Reply


Messages In This Thread
How to get the ammount of players alive? - by Jokerstyle - 14.05.2010, 17:08
Re: How to get the ammount of players alive? - by Faith - 14.05.2010, 17:10
Re: How to get the ammount of players alive? - by Jokerstyle - 14.05.2010, 17:14
Re: How to get the ammount of players alive? - by chaosnz - 14.05.2010, 17:35
Re: How to get the ammount of players alive? - by Calgon - 14.05.2010, 17:40
Re: How to get the ammount of players alive? - by Jokerstyle - 14.05.2010, 17:46
Re: How to get the ammount of players alive? - by Killa_ - 14.05.2010, 17:47
Re: How to get the ammount of players alive? - by [03]Garsino - 14.05.2010, 17:48
Re: How to get the ammount of players alive? - by Jokerstyle - 14.05.2010, 17:51
Re: How to get the ammount of players alive? - by Killa_ - 14.05.2010, 17:53

Forum Jump:


Users browsing this thread: 1 Guest(s)