Check Who Has The Most Cookies At The End...
#1

I have created a variable:
pawn Код:
new cookies[MAX_PLAYERS];
But how can I check who has the most at the end... I know what to do afterwards but how would I check which players have the most cookies so I can give him some money...?
Reply
#2

pawn Код:
stock GetPlayerWithMostCookies( ) {
    new iRecord = 0;
    new iChoosenPlayer = MAX_PLAYERS + 1;
    foreach(Player, i) {
        if ( cookies[i] > iRecord ){
            iRecord = cookies[i];
            iChoosenPlayer = i;
        }
    }
    return iChoosenPlayer;
}
Reply
#3

Where would I put the giveplayermoney function?
Reply
#4

Up... Sorry for the bump...
Reply
#5

At the "end", inside of a loop:
pawn Код:
GivePlayerMoney(GetPlayerWithMostCookies(i), amount);
Reply
#6

But what if more than one player has the highest cookies?
Reply
#7

Quote:
Originally Posted by Tigerbeast11
Посмотреть сообщение
But what if more than one player has the highest cookies?
Then the player with the smaller ID will be considered to have the most cookies.

@admantis: Depends on how the function is used but you could make iChosenPlayer INVALID_PLAYER_ID initially!
Reply
#8

Is there any way to give both players money if it's a tie?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)