23.05.2012, 02:17
Hi SA-MP Community,
The title says it all. Help me
The title says it all. Help me
for (new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(GetPlayerWantedLevel(i) == 6)
{
//Code here
}
}
}
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;
}
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);
Well, if two players have a level 6 wanted level, what would you do then? They are both the most wanted.
|
#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;
}
#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;
}
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);
}
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;
}
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. |