How to get the ammount of players alive?
#1

The title says it
I would be greatful for you help. =)
Reply
#2

variables.

new PlayerAlive[MAX_PLAYERS];

OnPlayerSpawn
PlayerAlive = 1

OnPlayerDeath
PlayerAlive = 0


if( (PlayerAlive) = 1){
// player's alive)
}else{
// Player's dead
Reply
#3

I think you got it worng, I want something which tells the total ammount of players a life, not if a player is alive or not .
Reply
#4

Im not 100% sure how it would go but

for in OnPlayerSpawn put "Alive[playerid] = 1;" and under it have a count for example "AliveCount++;" you will need to define the count thou.
And in OnPlayerDeath put "Alive[playerid] = 0;" and "AliveCount--;"

Now if you want it in a command to see how many are alive, this might help. I think.

format(string, sizeof(string), "~r~Players Alive ~n~~y~ $%d",AliveCount);
GameTextForPlayer(playerid, string, 5000, 1);

You will need to have a "new string;" at the top of your onplayercommandtext callback. As well as "AliveCount;"

Now that possibly might work. Dont quote me on it as its untested.
Reply
#5

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.
Reply
#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
#7

Use %d instead of %s
Reply
#8

%s is for strings, use %d
Reply
#9

Quote:
Originally Posted by Killa_
Use %d instead of %s
It's not working lol =S

Reply
#10

Where did you put the textdraw code?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)