13.06.2017, 21:56
(
Last edited by Daymen; 13/06/2017 at 11:42 PM.
)
![](http://i.imgur.com/1b2Tt6y.png)
![](http://i.imgur.com/jnHmrN8.png)
In servers where wanted levels are a main factor of the gamemode, it's nice to have a command to see whom is the highest wanted player
within the server at any given time. This can be useful for having a contest to see whom gets the highest wanted level, or even just a
player-used command like so. The great thing about the code I'm providing is that it can be expanded into various uses, not just the command itself!
![](http://i.imgur.com/wLM2L2d.png)
You will want to start out by creating the command itself that you would like it to be listed as. ( This command is created using the ZCMD command processor. )
Code:
CMD:mostwanted( playerid, params[] ) { //This is how you will cast the command in-game. return 1; //This ends the command's functionality. }
Code:
new iMostWantedPlayer, iMostWanted ;
If it's higher than the current highest, it will set the iMostWantedPlayer variable to that player's ID.
Code:
for (new i = 0; i < MAX_PLAYERS; i++) { //Starts the loops for players. new iLevel = GetPlayerWantedLevel( iMostWantedPlayer ) //Creates a virtual level to compare to others as it loops through player IDs. ; if ( iLevel != 0 && iLevel > iMostWanted ) { //If the current iLevel is higher than the previous iMostWanted level, it will adjust. iMostWanted = iLevel; //Sets new highest wanted level. iMostWantedPlayer = i; //Grabs the most wanted player's ID. } }
Code:
if ( iMostWanted == 0 || !IsPlayerConnected( iMostWantedPlayer) ) { //If there 0 wanted players online, or if the person whom had the highest wanted level is now offline, it will return this value. (The IsPlayerConnected is just a fail safe and isn't completely necessary. It's a "just-in-case" factor.) return SendClientMessage(playerid, -1, "{b20000}[MOST WANTED] {FFFFFF}There aren't any civilians with a wanted level."); //The message that is returned if those checks aren't passed. }
Code:
format( szNormalString, sizeof( szNormalString ), "{b20000}[MOST WANTED] {FFFFFF}%s is the most wanted player with a wanted level of %i! {FF0000}Proceed with caution.", ReturnPlayerName( iMostWantedPlayer ), iMostWanted ); //Formats the message and it's data to be sent into a message. SendClientMessage( playerid, -1, szNormalString ); //Responsible for carrying out the client message.
[ You can combine the 'szName' variable into the top of the file for use among the entire file, if using in a gamemode or a large filterscript. ]
Code:
new szName[MAX_PLAYER_NAME] ; stock ReturnPlayerName(playerid) { GetPlayerName(playerid, szName, sizeof(szName)); return szName; }
![](http://i.imgur.com/UzaCIOn.png)
In the end, you should have the following code:
Code:
new szName[MAX_PLAYER_NAME] ; CMD:mostwanted( playerid, params[] ) { new iMostWantedPlayer, iMostWanted ; for (new i = 0; i < MAX_PLAYERS; i++) { new iLevel = GetPlayerWantedLevel( iMostWantedPlayer ) ; if ( iLevel != 0 && iLevel > iMostWanted ) { iMostWanted = iLevel; iMostWantedPlayer = i; } } if ( iMostWanted == 0 || !IsPlayerConnected( iMostWantedPlayer) ) { return SendClientMessage(playerid, -1, "{b20000}[MOST WANTED] {FFFFFF}There aren't any civilians with a wanted level."); } format( szNormalString, sizeof( szNormalString ), "{b20000}[MOST WANTED] {FFFFFF}%s is the most wanted player with a wanted level of %i! {FF0000}Proceed with caution.", ReturnPlayerName( iMostWantedPlayer ), iMostWanted ); SendClientMessage( playerid, -1, szNormalString ); return 1; } stock ReturnPlayerName(playerid) { GetPlayerName(playerid, szName, sizeof(szName)); return szName; }
![](http://i.imgur.com/tVzmMss.png)