SA-MP Forums Archive
How to get the ammount of players alive? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How to get the ammount of players alive? (/showthread.php?tid=147812)



How to get the ammount of players alive? - Jokerstyle - 14.05.2010

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


Re: How to get the ammount of players alive? - Faith - 14.05.2010

variables.

new PlayerAlive[MAX_PLAYERS];

OnPlayerSpawn
PlayerAlive = 1

OnPlayerDeath
PlayerAlive = 0


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



Re: How to get the ammount of players alive? - Jokerstyle - 14.05.2010

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 .


Re: How to get the ammount of players alive? - chaosnz - 14.05.2010

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.



Re: How to get the ammount of players alive? - Calgon - 14.05.2010

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.


Re: How to get the ammount of players alive? - Jokerstyle - 14.05.2010

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);



Re: How to get the ammount of players alive? - Killa_ - 14.05.2010

Use %d instead of %s


Re: How to get the ammount of players alive? - [03]Garsino - 14.05.2010

%s is for strings, use %d


Re: How to get the ammount of players alive? - Jokerstyle - 14.05.2010

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




Re: How to get the ammount of players alive? - Killa_ - 14.05.2010

Where did you put the textdraw code?