Check Who Has The Most Cookies At The End... - 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: Check Who Has The Most Cookies At The End... (
/showthread.php?tid=275183)
Check Who Has The Most Cookies At The End... -
Tigerbeast11 - 08.08.2011
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...?
Re: Check Who Has The Most Cookies At The End... -
admantis - 08.08.2011
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;
}
Re: Check Who Has The Most Cookies At The End... -
Tigerbeast11 - 08.08.2011
Where would I put the giveplayermoney function?
Re: Check Who Has The Most Cookies At The End... -
Tigerbeast11 - 08.08.2011
Up... Sorry for the bump...
Re: Check Who Has The Most Cookies At The End... -
Scarred - 08.08.2011
At the "end", inside of a loop:
pawn Код:
GivePlayerMoney(GetPlayerWithMostCookies(i), amount);
Re: Check Who Has The Most Cookies At The End... -
Tigerbeast11 - 08.08.2011
But what if more than one player has the highest cookies?
Re: Check Who Has The Most Cookies At The End... -
AndreT - 08.08.2011
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!
Re: Check Who Has The Most Cookies At The End... -
Tigerbeast11 - 08.08.2011
Is there any way to give both players money if it's a tie?