Adding [Reason]
#1

pawn Код:
if (strcmp(cmd, "/suspect", true) == 0)
    {
      if(gTeam[playerid] != TEAM_COPS)
        {
          tmp = strtok(cmdtext, index);
          if(strlen(tmp))
            {
              id = strval(tmp);
              if(IsPlayerConnected(id))
                {
                            new name[MAX_PLAYER_NAME], name2[MAX_PLAYER_NAME], string[128];
                            GetPlayerName(playerid, name, sizeof(name));
                            GetPlayerName(playerid, name2, sizeof(name2));
                            format(string, sizeof(string), "-> Police Officer %s has suspected a %s", name, name2 );
                            SendClientMessageToAll(0xFFFF00AA, string);
                            SendClientMessage(id, 0xFFFF00AA, "-> You are now a police suspect, cops will try to arrest you!");
                            SetPlayerWantedLevel(id, 2);
                            return 1;
                            }
                           
                            else return SendClientMessage(id, 0xFFFF00AA, "-> Player not found");
                            }
                           
                            else return SendClientMessage(id, 0xFFFF00AA, "-> You mean: /suspect [PlayerID]");
                            }
                           
                            else return SendClientMessage(id, 0xFFFF00AA, "-> You are not a Police Officer");
                            }

How could I add [Reason] for the command? Like /suspect [PlayerID] [Reason]
Reply
#2

Код:
if(!strcmp(cmd, "/suspect", true))
{
	if(gTeam[playerid] == TEAM_COPS)
	{
		tmp = strtok(cmdtext, index);
		if(!strlen(tmp))return SendClientMessage(id, 0xFFFF00AA, "-> You mean: /suspect [PlayerID] [reason]");
		id = strval(tmp);
		strmid(tmp, cmdtext, strlen(cmd)+strlen(tmp)+2, strlen(cmdtext));
		if(IsPlayerConnected(id))
		{
			new name[MAX_PLAYER_NAME], name2[MAX_PLAYER_NAME], string[128];
			GetPlayerName(playerid, name, sizeof(name));
			GetPlayerName(id, name2, sizeof(name2));
			format(string, sizeof(string), "-> Police Officer %s has suspected a %s. Reason: %s", name, name2, tmp);
			SendClientMessageToAll(0xFFFF00AA, string);
			SendClientMessage(id, 0xFFFF00AA, "-> You are now a police suspect, cops will try to arrest you!");
			SetPlayerWantedLevel(id, 2);
		}else SendClientMessage(playerid, 0xFFFF00AA, "-> Player not found");
	}else SendClientMessage(playerid, 0xFFFF00AA, "-> You are not a Police Officer");
	return 1;
}
Reply
#3

Why do you guys add:

Код:
!strcmp, !strlen
?

EDIT: Can you explain this line:
pawn Код:
strmid(tmp, cmdtext, strlen(cmd) + strlen(tmp) + 2, strlen(cmdtext));
Reply
#4

Код:
if(!strcmp(cmd, "/suspect", true))
{
  // Checking to make sure the player is a cop
  if(gTeam[playerid] != TEAM_COPS)
  return SendClientMessage(playerid, 0xFF0000FF, "-> You are not a police officer.");
  
  // Obtaining the second argument
  tmp = strtok(cmdtext, index);
  
  // Checking the second argument
  if(!strlen(tmp))
  return SendClientMessage(playerid, 0xFF0000FF, "-> You must specify a player ID to suspect them.");

  new targetid = strval(tmp);

  // Checking if the player is valid and connected
  if(!IsPlayerConnected(targetid))
  return SendClientMessage(playerid, 0xFF0000FF, "-> You have either entered an invalid player ID");
  
  // Extracting the reason
  strdel(cmdtext, 0, 10 + strlen(tmp));

  // Checking the reason
  if(strlen(cmd) < 2)
  return SendClientMessage(playerid, 0xFF0000FF, "-> Please provide a reason to suspect the individual.");

  // Getting the player names
  new playername[MAX_PLAYER_NAME];
  new targetname[MAX_PLAYER_NAME];
  GetPlayerName(playerid, playername, MAX_PLAYER_NAME);
  GetPlayerName(targetid, targetname, MAX_PLAYER_NAME);

  new string[128];
  format(string, 128, "-> Police Officer '%s'[ID:%d] has suspected '%s'[ID:%d] of: %s", playername, playerid, targetname, targetid, cmd);
  SendClientMessageToAll(0x0000FFFF, string);
  SendClientMessage(targetid, 0x0000FFFF, "-> You are now a police suspect and may be subject to arrest.");
    
  return 1;
}
Reply
#5

Quote:
Originally Posted by Hot
Why do you guys add:

Код:
!strcmp, !strlen
?

EDIT: Can you explain this line:
pawn Код:
strmid(tmp, cmdtext, strlen(cmd) + strlen(tmp) + 2, strlen(cmdtext));
strmid get the characters from one string, and puts it into another.

Strcmp checks if the two strings are the same. ! means not, so it would check if they weren't the same.

Strlen gets the lengh of the string. ! means not, so it would check if the string had no lengh.
Reply
#6

Quote:
Originally Posted by -The_Badger-
Quote:
Originally Posted by Hot
Why do you guys add:

Код:
!strcmp, !strlen
?

EDIT: Can you explain this line:
pawn Код:
strmid(tmp, cmdtext, strlen(cmd) + strlen(tmp) + 2, strlen(cmdtext));
strmid get the characters from one string, and puts it into another.

Strcmp checks if the two strings are the same. ! means not, so it would check if they weren't the same.

Strlen gets the lengh of the string. ! means not, so it would check if the string had no lengh.
1/2 correct, strcmp works in reverse so the ! means that they are the same
Reply
#7

you mean 4/5 correct. anyway I always put ==0 so i dont think about it. Thanks for correcting anyway.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)