how to get the highest score in the server?
#1

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

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...
}
Reply
#3

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

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

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 ? ..
Reply
#6

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

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

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.
Reply
#9

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)