Score update problem - 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: Score update problem (
/showthread.php?tid=260929)
Score update problem -
OldDirtyBastard - 11.06.2011
Hi, im having a problem with this very simple feature that should check for the highest score on the server.
The problem is that who ever on the server has a higher score than 0 it states him also as the player
with the highest score. (now imagine the spam with like 50 people on the server)
Can anyone please take a look at the code and tell me what could be wrong?
pawn Код:
public ScoreUpdate()
{
new string[128];
new highest = -1;
new name[MAX_PLAYER_NAME];
for(new slots = GetMaxPlayers(), i; i < slots; i++)
{
if(!IsPlayerConnected(i))
continue;
if(GetPlayerScore(i) > highest)
{
highest = GetPlayerScore(i);
GetPlayerName(i, name, sizeof(name));
format(string, sizeof(string), "Player %s is currently the top killer with a score of %d kills!", name, highest);
SendClientMessageToAll(COLOR_ORANGE, string);
}
}
return 1;
}
Thanks, regards.
Re: Score update problem -
Cyanide - 11.06.2011
You're calling the SendClientMessageToAll function inside the loop. A for loop starts by a designated number and reaches up to its destination. Imagine in your server, your players had the score of their playerid (Ex: I'm playerid 9, my score is 9), it will just keep spamming every name that is bigger.
pawn Код:
public ScoreUpdate()
{
new string[128];
new highest = -1;
new highestPlayer;
new name[MAX_PLAYER_NAME];
for(new slots = GetMaxPlayers(), i; i < slots; i++)
{
if(!IsPlayerConnected(i))
continue;
if(GetPlayerScore(i) > highest)
{
highest = GetPlayerScore(i);
highestPlayer = i;
}
}
GetPlayerName(highestPlayer, name, sizeof(name));
format(string, sizeof(string), "Player %s is currently the top killer with a score of %d kills!", name, highest);
SendClientMessageToAll(COLOR_ORANGE, string);
return 1;
}
Re: Score update problem -
OldDirtyBastard - 11.06.2011
Thanks alot!