26.09.2010, 16:55
(
Последний раз редактировалось Nero_3D; 16.10.2010 в 22:33.
)
:/ Try that
(If you want the highest kills from the guys in the server use Selection sort)
(If you want the highest kills from the guys in the server use Selection sort)
pawn Код:
stock UpdateKillsTop(killerid, kills)
{ //returns 1 for update and 0 for no update
new kname[MAX_PLAYER_NAME];
if(GetPlayerName(killerid, kname, MAX_PLAYER_NAME)) //Checking if the player is connected
for(new i; i < sizeof TopKills; i++) //Loops through all TopKills
if(kills > TopKills[i])
{ //Checks if the player got more kills than the highscore
if(strcmp(TopKillsName[i], kname) != 0)
{ //If he isnt already on that place we put everyone one place down
new j = (sizeof TopKills - 1);
for( ; j > i; j--)
if(strcmp(TopKillsName[j], kname, true) == 0)
break;
if (j == i) j = (sizeof TopKills - 1);
for( ; j > i; j--)
TopKills[j] = TopKills[(j - 1)],
TopKillsName[j] = TopKillsName[(j - 1)];
}
TopKills[i] = kills;
TopKillsName[i] = kname;
UpdateKillsFile(); //Function for saving everything to file
return 1; //Highscore updated
}
else if (strcmp(TopKillsName[i], kname) == 0)
break; //Abort if we found himself
return 0; //Nothing updated
}
pawn Код:
stock UpdateTopFile()
{
new File:gfile = fopen("Top.data", io_write); //Call the file how you want
if(gfile) {
new string[64], i;
while(i++ < sizeof TopKills) {
format(string, sizeof string, "%d. %s\r\n", TopKills[i], TopKillsName[i]);
fwrite(gfile, string);
}
fclose(gfile);
return 1;
}
return 0;
}