TOP 5 problem
#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


Messages In This Thread
TOP 5 problem - by BuLLeT[LTU] - 26.09.2010, 14:50
AW: TOP 5 problem - by Nero_3D - 26.09.2010, 15:49
Re: TOP 5 problem - by BuLLeT[LTU] - 26.09.2010, 16:42
Re: TOP 5 problem - by BuLLeT[LTU] - 26.09.2010, 16:50
AW: TOP 5 problem - by Nero_3D - 26.09.2010, 16:55
Re: TOP 5 problem - by BuLLeT[LTU] - 26.09.2010, 17:37

Forum Jump:


Users browsing this thread: 4 Guest(s)