26.09.2010, 14:50
Hello. I have a problem when setting new record on top 5. If i was on the first place and other beats my record, i am removed from top 5. But i want to set my record one step down, to second place (but if i broken not my own record, because it would be two of me in TOP 5: first and second).
pawn Код:
stock UpdateKillsTop(killerid,kills)
{
new playername2[MAX_PLAYER_NAME];
GetPlayerName(killerid, playername2, MAX_PLAYER_NAME);
new recordflag=-1;
//Init to -1 or it will be 0 and fail to work
new pflag=-1;
for(new i = 0; i < 5; i++)
{
//run through highscorelist to see if new highscore
if (TopKills[i] == 0)
{
//check if record is not set (0) previously
TopKills[i] = 0;
//if no previous record, set dummy record
}
if (strcmp(TopKillsNames[i], playername2) == 0 && pflag ==-1)
{ //check for personal best score
pflag = i;
//mark where best personal record is
}
if (kills > TopKills[i] && recordflag ==-1 && (pflag == -1 || pflag == i) )
{ //new record
//personal flag must always be equal or nonexistant (-1) for a valid (personal) record
recordflag = i;
//Record number
}
}
if (recordflag>-1)
{
//new highscore
new tmp1[255];
format(tmp1,sizeof(tmp1),"Top5/Kills.txt"); //time to update list (file)
for(new i = 0; i < 5; i++)
{
if(i == recordflag)
{
//record goes to correct place in list
TopKills[i] = kills;
TopKillsNames[i] = playername2;
}
if(strcmp(TopKillsNames[i], playername2)==0)
{
//skip all records that matches racername
continue;
}
if(TopKills[i] == 0)
{
//ignore dummy records
break;
}
//write from old record list
}
}
}