Here you go:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
That is called whenever the player types a /command.
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext, "/getwanted"))
This will compare two strings, in this case cmdtext(the /command the player typed), and "/getwanted". So, if the player types "/getwanted" it will trigger the callback(OnPlayerCommandText), and go down the list of strcmps, when it reaches this on, "/getwanted", it will continue into what this command does.
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext, "/getwanted")) {
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) {
SendClientMessage(playerid, Red1, "Error: /getwanted [Player ID]");
return 1;
}
}
This will see if they typed anything after the command(the ID, "/getwanted 13", for example) and return them back if they did not.
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext, "/getwanted")) {
new tmp[128] = strtok(cmdtext, idx);
if(!strlen(tmp)) {
SendClientMessage(playerid, Red1, "Error: /getwanted [Player ID]");
return 1;
}
new string[128], Wanted, CheckID = strval(tmp);
Wanted = GetPlayerWantedLevel(playerid);
format(string, 128, "This player has a %d Wanted Level", Wanted);
SendClientMessage(playerid, COLOR, string);
return 1;
}
Now what this last bit of code does, is declare string, Wanted, and CheckID(and also converts tmp into an integer instead of a string). Then it "puts" the players wanted level into the variable Wanted. It edits the variable string and makes a nice message including their wanted level, and it sends that to the player who entered the command. It then returns the player so they don't get an unknown command message.
There you go, a simple wanted command.