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

Hi SA-MP Community,

The title says it all. Help me
Reply
#2

the wiki knows allot!
you should study all the functions there as it will save you tons of time asking questions.

https://sampwiki.blast.hk/wiki/GetPlayerWantedLevel

ahh sorry misread!

but that function will get their wanted level,
now just loop threw each player and keep the id of the player with the highest level.
Reply
#3

Then to find the most wanted, use a loop to check if a player is wanted level 6.

pawn Code:
for (new i = 0; i < MAX_PLAYERS; i++)
{
    if(IsPlayerConnected(i))
    {
        if(GetPlayerWantedLevel(i) == 6)
        {
            //Code here
        }
    }
}
Untested, but that's how I used to find mine.
Reply
#4

If you're trying to find the player with the highest wanted level, use this function:

pawn Code:
GetMostWantedPlayer()
{
    new highPlayerWantedLevel, player = INVALID_PLAYER_ID, wl;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            wl = GetPlayerWantedLevel(i);
            if(wl > highPlayerWantedLevel)
            {
                highPlayerWantedLevel = wl, player = i;
            }
        }
    }
    return player;
}
Reply
#5

pawn Code:
new MWanted,VBName[MAX_PLAYER_NAME],VBString[40];
for(new v, b = GetMaxPlayers(); v != b; v++)
    if(IsPlayerConnected(v))
        if(GetPlayerWantedLevel(v) > MWanted)
            MWanted = v;

GetPlayerName(MWanted,VBName,MAX_PLAYER_NAME);
format(VBString, sizeof VBString, "Most wanted : %s", VBName);
SendClientMessageToAll(-1,VBString);
Reply
#6

Thanks all +2rep to all.
Reply
#7

Well, if two players have a level 6 wanted level, what would you do then? They are both the most wanted.
Reply
#8

Quote:
Originally Posted by MP2
View Post
Well, if two players have a level 6 wanted level, what would you do then? They are both the most wanted.
same question . but for someother stuff [ofc similar one],
if two player has same wanted and we fethc there names through loop or anything what then =__=
How to figure it out then?
Reply
#9

It depends what you're trying to do. If you want a single most wanted suspect or a list.
Reply
#10

Quote:
Originally Posted by MP2
View Post
It depends what you're trying to do. If you want a single most wanted suspect or a list.
Oh yeah i did'nt thought about it. I wanna make a list so how will I do it?
Reply
#11

this should works.
pawn Code:
#include <a_samp>
#include <foreach>

public OnPlayerCommandText(playerid, cmdtext[])
{
  if (strcmp("/wantedlevel", cmdtext, true) == 0)
    {
    new dialog[256], string[40], name[24];
    format(dialog, sizeof(dialog), "");
    for( new i = 0; i < MAX_PLAYERS; i ++ )
    {
        if( GetPlayerWantedLevel( i ) >= 1 )
        {
            GetPlayerName( i, name, 24);
            format( string, sizeof (string), "%s (%i)", name, GetPlayerWantedLevel( i ) );
            format(dialog, sizeof(dialog), "%s\n%s", dialog, string);
        }
    }
    ShowPlayerDialog( playerid, 1, DIALOG_STYLE_LIST, "Wanted levels", dialog, "Ok", "");
    return 1;

    }
  return 0;
  }
Reply
#12

if you want the list to be in a Order say top -> lower
then you have to use/create a sort function
may be try quickSort by Ryder or Slice's Sort include
Reply
#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
#14

What damn?

Just do this.

pawn Code:
CMD:mwp(playerid, params[])
{
    new count = 1, name[24], string[200];
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        GetPlayerWantedLevel(i);
        if(GetPlayerWantedLevel(i) >= 5)
        {
            GetPlayerName(i, name, sizeof(name));
            format(string, sizeof(string), "%s%s (%d) - Wanted Level: %d\n", string, name,i,GetPlayerWantedLevel(i));
            count ++;
        }
    }

    if(count != 1)
    {
        ShowPlayerDialog(playerid, 26, DIALOG_STYLE_MSGBOX, "Most Wanted Players Online", string, "OK", "");
    }
    else ShowPlayerDialog(playerid, 26, DIALOG_STYLE_MSGBOX, "Most Wanted Players Online", "No online wanted players.", "OK", "");
    return 1;
}
Most wanted players in dialog.

Notice: THERE ARE ONLY LISTED THE PLAYERS WHO HAVE MORE THAN 5 WANTED LEVEL.
Reply
#15

LOL so many suggestions thanks all. I will check all code on by one currently I am checking Viniborns code. +2rep to all
Reply
#16

Here is my code I used Ryders code:
pawn Code:
new
                playerWL[MAX_PLAYERS][Crime],
                index
                ;
            for(new i; i != MAX_PLAYERS; ++i) {
                if(IsPlayerConnected(i) && !IsPlayerNPC(i)) {
                    playerWL[index][player_WantedLevel] = GetPlayerWantedLevel(i);
                    playerWL[index++][player_ID] = i;
                }
            }
            GetPlayerHighestWantedLevel(playerWL, 0, index);

            new
                player_Name[20], string[24+MAX_PLAYER_NAME+1], player_Level[256];
            for(new i; i < 5; ++i) {
                if(i < index) {
                    GetPlayerName(playerWL[i][player_ID], player_Name, sizeof(player_Name));
                    format(string, sizeof(string), "~w~%s", player_Name);
                    format(player_Level, sizeof(player_Level), "%d", playerWL[i][player_WantedLevel]);
                }
                else
                    format(string, sizeof(string), "~r~N/A", player_Name);
            }
            TextDrawSetString(Textdraw38, player_Level);// level TD
            TextDrawShowForPlayer(playerid, Textdraw38);
            TextDrawSetString(Textdraw7, player_Name);//name TD
            TextDrawShowForPlayer(playerid, Textdraw7);
I want this to be more in further 14 textdraws. How can I do it? Can I use a stock function? Explain me in detail.

Thank you.
Reply
#17

Anyone?
Reply
#18

Quote:
Originally Posted by Faisal_khan
View Post
I want this to be more in further 14 textdraws. How can I do it? Can I use a stock function? Explain me in detail.

Thank you.
i dont understand what you mean. Please explain more so we can help. as this makes no sense to me.

and please dont just sit here and bump your thread,
you are not more important that the next person.
Reply
#19

Sorry for bumping.
I want the function of top wanted levels to be added in all TDs. Its just showing 1st one not 2nd 3rd ......
Reply
#20

Saying you're sorry about breaking a rule doesn't mean you get to break it. If you feel you need to apologize for doing something, you're probably better off not doing it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)