23.05.2012, 10:40
(
Last edited by [ABK]Antonio; 23/05/2012 at 11:12 AM.
)
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;
}
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);
}