How to get the most wanted player in a game?
#13

pawn Code:
#define MAX_WANTED_DISPLAY (3) //we'll only ever show 3 players that have the same wanted level

CMD:topwanted(playerid, params[])
{
    new LastTop = 0, top[MAX_WANTED_DISPLAY];
    for(new i=0; i < MAX_WANTED_DISPLAY; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(GetPlayerWantedLevel(i) > GetPlayerWantedLevel(top[0]));
            {
                top[0] = i; //set the first cell in our array to the players id
                if(top[1] != -1) //put in an if just for a little performance boost
                {
                    for(new update=1; update < MAX_WANTED_DISPLAY; update++)
                    {
                        top[update] = -1; //reset the array (starting from 1)
                        LastTop = 0; //reset our LastTop variable so we can use it if another is equal
                    }
                }
            }
            //if they're the same, we put them into the array in the next slot (next to whatever the last one was)
            else if(GetPlayerWantedLevel(i) == GetPlayerWantedLevel(top[0]))
            {
                //We make sure LastTop isn't the size of the array of course
                if(LastTop != sizeof(top))
                {
                    top[LastTop+1] = i;
                    LastTop++; //increase our last top variable + 1
                }
            }
        }
    }
   
    SendClientMessage(playerid, 0xFFFFFFAA, "!==========[Top Wanted]==========!"
   
    new string[30], name[MAX_PLAYER_NAME];
    for(new index=0; index < MAX_WANTED_DISPLAY; index++)
    {
        if(top[index] != -1) //make sure the slot is in use
        {
            GetPlayerName(top[index], name, sizeof(name)); //get the name of the ID on that array slot
            format(string, sizeof(string), "%s - %d", name, GetPlayerWantedLevel(top[index]));
            SendClientMessage(playerid, 0xCCCCCCAA, string);
        }
    }
   
    SendClientMessage(playerid, 0xFFFFFFAA, "!================================!"
    return 1;
}
Something like this? It still displays the Top wanted person however, it makes it so if there's multiple with the same wanted level...It displays up to MAX_WANTED_DISPLAY amount of people. If it doesn't work, post here (untested)



EDIT:

Here's one that lists all wanted players in a dialog (organized)
pawn Code:
CMD:wantedlist(playerid, params[])
{
    new DialogString[400], WantedLevel[MAX_PLAYERS], tmpwanted, count=0;

    for(new i=0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            tmpwanted = GetPlayerWantedLevel(i);
            if(tmpwanted > 0) { WantedLevel[i] = tmpwanted; count++; }
        }
    }

    BubbleSort(WantedLevel, 0, MAX_PLAYERS);

    new name[MAX_PLAYER_NAME], string[35];

    if(count != 0)
    {
        for(new i=0; i < MAX_PLAYERS; i++)
        {
            if(WantedLevel[i] > 0)
            {
                GetPlayerName(i, name, sizeof(name));
                format(string, sizeof(string), "%d. %s - %d\n", i+1, name, GetPlayerWantedLevel(i));
                strcat(DialogString, string, sizeof(DialogString));
            }
        }
    }
    else format(DialogString, sizeof(DialogString), "No wanted players online.");
    ShowPlayerDialog(playerid, 1, DIALOG_STYLE_LIST, "Wanted List", DialogString, "Ok", "");
    return 1;
}


stock BubbleSort(Array[], begin, end) //at least similar
{
    new tmpslot=0, bool:swapped;
    do
    {
        swapped = false;
        for(new index=begin+1; index < end; index++)
        {
            if(Array[index-1] > Array[index])
            {
                tmpslot = Array[index];
                Array[index] = Array[index-1];
                Array[index-1] = tmpslot;
                swapped = true;
            }
        }
    } while(swapped);
}
Reply


Messages In This Thread
How to get the most wanted player in a game? - by Faisal_khan - 23.05.2012, 02:17
Re: How to get the most wanted player in a game? - by Jonny5 - 23.05.2012, 02:20
Re: How to get the most wanted player in a game? - by iGetty - 23.05.2012, 02:22
Re: How to get the most wanted player in a game? - by SuperViper - 23.05.2012, 02:38
Re: How to get the most wanted player in a game? - by ViniBorn - 23.05.2012, 02:38
Re: How to get the most wanted player in a game? - by Faisal_khan - 23.05.2012, 07:08
Re: How to get the most wanted player in a game? - by MP2 - 23.05.2012, 07:23
Re: How to get the most wanted player in a game? - by Niko_boy - 23.05.2012, 07:26
Re: How to get the most wanted player in a game? - by MP2 - 23.05.2012, 07:38
Re: How to get the most wanted player in a game? - by Faisal_khan - 23.05.2012, 09:40
Re: How to get the most wanted player in a game? - by leonardo1434 - 23.05.2012, 10:15
Re: How to get the most wanted player in a game? - by Niko_boy - 23.05.2012, 10:20
Re: How to get the most wanted player in a game? - by [ABK]Antonio - 23.05.2012, 10:40
Re: How to get the most wanted player in a game? - by Face9000 - 23.05.2012, 10:55
Re: How to get the most wanted player in a game? - by Faisal_khan - 23.05.2012, 11:00
Re: How to get the most wanted player in a game? - by Faisal_khan - 23.05.2012, 11:03
Re: How to get the most wanted player in a game? - by Faisal_khan - 23.05.2012, 13:49
Re: How to get the most wanted player in a game? - by Jonny5 - 23.05.2012, 13:54
Re: How to get the most wanted player in a game? - by Faisal_khan - 23.05.2012, 14:01
Re: How to get the most wanted player in a game? - by kaisersouse - 23.05.2012, 14:54

Forum Jump:


Users browsing this thread: 8 Guest(s)