SA-MP Forums Archive
how to get the highest score in the server? - 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: how to get the highest score in the server? (/showthread.php?tid=170423)



how to get the highest score in the server? - Rocky Balboa - 23.08.2010

i was wonder how to get hte highest score of ppl in game .. you know .. not by looking at the score board ..cuz i want to return a specifi function to the player wich has the highest score so can anyone help me ?


Re: how to get the highest score in the server? - Toribio - 23.08.2010

pawn Код:
new highestid = INVALID_PLAYER_ID, highest = -1;
for(new i = 0; i < MAX_PLAYERS; ++i)
{
    if(GetPlayerScore(i) > highest)
    {
        highestid = i;
        highest = GetPlayerScore(i);
    }
}
if(highestid != INVALID_PLAYER_ID)
{
    //your function...
}



Re: how to get the highest score in the server? - Rocky Balboa - 23.08.2010

will it work like this ? to use it as a timer ..
pawn Код:
forward High();
public High()
{
    new highestid = INVALID_PLAYER_ID, highest = -1;
    for(new i = 0; i < MAX_PLAYERS; ++i)
    {
        if(GetPlayerScore(i) > highest)
        {
            highestid = i;
            highest = GetPlayerScore(i);
        }
    }
    for(new i = 0; i < MAX_PLAYERS; ++i)
    {
        if(highestid != INVALID_PLAYER_ID)
        {
            team[i] = 3;
        }
    }
    return 1;
}



Re: how to get the highest score in the server? - Toribio - 23.08.2010

You just have to use this, if you want to set the player whom has the highest score in another team:

pawn Код:
forward High();
public High()
{
    static last; //it's static because it's like a global variable
    new highestid = INVALID_PLAYER_ID, highest = -1;
    for(new i = 0; i < MAX_PLAYERS; ++i)
    {
        if(GetPlayerScore(i) > highest)
        {
            highestid = i;
            highest = GetPlayerScore(i);
        }
    }
    if(highestid != INVALID_PLAYER_ID)
    {
        if(last != highestid)
        {
            //do something to remove the last one with highest score from the team
        }
        team[highestid] = 3;
    }
    last = highestid;
}



Re: how to get the highest score in the server? - Rocky Balboa - 23.08.2010

Quote:
Originally Posted by Toribio
Посмотреть сообщение
//do something to remove the last one with highest score from the team
can u give me an example of what is meant by that ? ..


Re: how to get the highest score in the server? - Rocky Balboa - 23.08.2010

like this ?
Код:
forward High();
public High()
{
    static last; //it's static because it's like a global variable
    new highestid = INVALID_PLAYER_ID, highest = -1;
    for(new i = 0; i < MAX_PLAYERS; ++i)
    {
        if(GetPlayerScore(i) > highest)
        {
            highestid = i;
            highest = GetPlayerScore(i);
        }
    }
    if(highestid != INVALID_PLAYER_ID)
    {
        if(last != highestid)
        {
            team[last] = 0;
        }
        team[highestid] = 3;
    }
    last = highestid;
}



Re: how to get the highest score in the server? - Toribio - 23.08.2010

Yes, I think. You would be sure if you test it.


Re: how to get the highest score in the server? - Kyosaur - 23.08.2010

Wow 500 loops to just keep track of the highest score. Seems sort of slow and unneeded? Im sure you could achieve the same thing with no loops with just a little bit of effort on your part ... it may not be worth it depending how you code (ie everything in ONE GM, or everything in filterscripts).

If everything is in a single GM, then you can simpley hook the native function that sets a player's score, and inside of your newly hooked function, track the kills.


Re: how to get the highest score in the server? - Toribio - 23.08.2010

His gamemode's performance is not my business, if he wants performance he should do what he think that would be better. I don't even know how his gamemode looks like. I just gave him the theory.