TOP 5 problem
#1

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
        }
    }
}
Reply
#2

pawn Код:
//Code updated - post below
Thats not tested and there is no saving code only the pseudo function "UpdateKillsTopFile"
I added it because your give code didnt saved anything at all
And it should be in an extra function, in my opinion
Reply
#3

Thank you for the code but now there are this problem:
/imageshack/img830/4777/samp007hv.png
Reply
#4

But i think it's not possible to remove them ?
Reply
#5

:/ Try that

(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;
}
Reply
#6

Thank you Nero_3D for helping
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)