[HELP] how to get the player who has the highst stats
#1

hello all
i need help pleas if some one can explain me how can i check who's the player who has the highest stats !
i explainer ! i've creating a killing medal system (double kill triple kill ect)
The killer (player) has +1 every time he kills an other player
Код:
new gPlayerKills[ MAX_PLAYERS ];
public OnPlayerDeath( playerid, killerid, reason )
{
    new string1[ 200 ], name[30];
    GetPlayerName( killerid, name, 24 );
	gPlayerKills[ killerid ]++;
    gPlayerKills[ playerid ] = 0;
}
what i want is to get the player's name of the guy who has the highest gPlayerKills number (and i will put that on a textdraw ) hop that u understood me !
thnks for reading and trying to help me
Reply
#2

Quote:
Originally Posted by Amine_Mejrhirrou
Посмотреть сообщение
Код:
new gPlayerKills[ MAX_PLAYERS ];
public OnPlayerDeath( playerid, killerid, reason )
{
    new string1[ 200 ], name[30];
    GetPlayerName( killerid, name, 24 );
	gPlayerKills[ killerid ]++;
    gPlayerKills[ playerid ] = 0;
}
Is it like a spree or something? If not then what are u doing to playerid?
Reply
#3

Quote:
Originally Posted by suhrab_mujeeb
Посмотреть сообщение
Is it like a spree or something? If not then what are u doing to playerid?
Look for killer spree filterscripts, and look at how the code is constructed.
Reply
#4

This will return the name of the player with the highest gPlayerKills:

pawn Код:
forward getTopScoringPlayer();
stock getTopScoringPlayer() {
    new _pid = -1, _kills = 0;
    for(new i=0;i<MAX_PLAYERS;i++) {
        if(gPlayerKills[i] > _kills) {
            _pid = i;
            _kills = gPlayerKills[i];
        }
    }
    new pname[24];
    GetPlayerName(_pid, pname, sizeof(pname));
    return pname;
}
at the end of the function, _kills will be the gPlayerKills of the highest ranking player, and _pid the id.
Reply
#5

thnks all for helping me
but it not intresting to just copy and past the code ... can some one explaine me what hapen withe GetTopSCoringPlayer ?
Reply
#6

Quote:
Originally Posted by Amine_Mejrhirrou
Посмотреть сообщение
thnks all for helping me
but it not intresting to just copy and past the code ... can some one explaine me what hapen withe GetTopSCoringPlayer ?
Alright:

1. you declare 2 integers, one will be the ID of the player, the other one will the the SCORE of the player
2. You start with the ID -1 (which is an invalid ID, so nobody) and 0 for the score
2. you loop through all the players
3. When a player has more score then the SCORE integer, the SCORE integer is replaced with this player's score, and the ID integer is set to the ID of the highest scoring player.
4. repeat this, every time a player has more score then the SCORE integer, he is set as the highest scoring player

5. your result will the ID = the id of the player with the highest score, SCORE = the highest score

I hope that made sense.
Reply
#7

To start off do a loop of all the players:

Код:
new HighestKills = -1;
for(new i; i < MAX_PLAYERS; i++)
{
      if(gPlayerKills[ i ] < gPlayerKills[ HighestKills ]) HighestKills = i;    
}
printf("THE HIGHEST KILLS HOLDER ID IS %d", HighestKills);
Reply
#8

ok thanks you i will try to do it tnks again
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)