[UNSOLVED] Police Badge
#1

Hello again, I'm trying to create a /showbadge command but I got some small confusions, this is how it looks like so far:

Code:
	if(strcmp(cmd, "/showbadge", true) == 0)
	{
	  if(IsPlayerConnected(playerid))
	  {
	  	tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GREY, "	USAGE: /showbadge [playerid]");
				return 1;
			}
			new para1;
			para1 = ReturnUser(tmp);
			giveplayerid = ReturnUser(tmp);
			if (PlayerInfo[playerid][pLAERank] >= 1)
			{
				if(IsPlayerConnected(para1))
				{
				  if(giveplayerid != INVALID_PLAYER_ID)
				  {
					  GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
						GetPlayerName(playerid, sendername, sizeof(sendername));
						new length = strlen(cmdtext);
						while ((idx < length) && (cmdtext[idx] <= ' '))
						if(!strlen(tmp))
						{
							SendClientMessage(playerid, COLOR_GREY, "	USAGE: /showbadge [playerid]");
							return 1;
						}
						format(string, sizeof(string), "Police Officer %s BlahBlah...", sendername);
						SendClientMessage(para1, COLOR_BLUE, string);
						format(string, sizeof(string), "You have shown %s your badge.", giveplayer);
						SendClientMessage(playerid, COLOR_BLUE, string);
						return 1;
					}
				}
			}
		}
		return 1;
	}
I think it misses something that keeps the player distance?

I hope you know what I mean, thanks
Reply
#2

I dont xd, Maybe explain a little better
Reply
#3

Quote:
Originally Posted by Torran
I dont xd, Maybe explain a little better
I think I fixed that problem with the distance:

Code:
if(strcmp(cmd, "/showbadge", true) == 0)
	{
	  if(IsPlayerConnected(playerid))
	  {
	  	tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GREY, "	USAGE: /showbadge [playerid]");
				return 1;
			}
			new para1;
			new laerank = PlayerInfo[playerid][pLAERank];
			para1 = ReturnUser(tmp);
			giveplayerid = ReturnUser(tmp);
			if (PlayerInfo[playerid][pLAERank] >= 1)
			{
				if(IsPlayerConnected(para1))
				{
					if(giveplayerid != INVALID_PLAYER_ID)
	  			{
		  			if (GetDistanceBetweenPlayers(playerid,giveplayerid) > 5)
						{
		  				SendClientMessage(playerid, COLOR_GREY, "	You are too far away from the player.");
		  				return 1;
						}
				  	GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
						GetPlayerName(playerid, sendername, sizeof(sendername));
						new length = strlen(cmdtext);
						while ((idx < length) && (cmdtext[idx] <= ' '))
						if(!strlen(tmp))
						{
								SendClientMessage(playerid, COLOR_GREY, "	USAGE: /showbadge [playerid]");
								return 1;
						}
						format(string, sizeof(string), "%d %s BlahBlah...", laerank, sendername);
						SendClientMessage(para1, COLOR_BLUE, string);
						format(string, sizeof(string), "You have shown %s your badge.", giveplayer);
						SendClientMessage(playerid, COLOR_BLUE, string);
						return 1;
					}
				}
			}
		}
		return 1;
	}
Anyway, the real question now is, is it possible to create a rank name like, Rank ID 1 = Police Officer (PlayerInfo[playerid][pLAERank]) so it can be shown when you show the badge to a player?

For example, you got Rank 1, and it displays as "Police Officer" at the %d.
Reply
#4

I hope this will help.I made this for my GM.I think you can take an idea to make your own,

pawn Code:
if(strcmp(cmd,"/showbadge",true)==0)
{
  if(IsPlayerConnected(playerid)) {
    if(IsACop(playerid) || IsAPrisonGuard(playerid)) {
      tmp = strtok(cmdtext, idx);
      if(!strlen(tmp)) {
        SendClientMessage(playerid, COLOR_WHITE, "USAGE: /showbadge [playerid/PartOfName]");
        return 1;
      }
      giveplayerid = ReturnUser(tmp);
      if(IsPlayerConnected(giveplayerid)) {
        if(giveplayerid != INVALID_PLAYER_ID) {
          if (ProxDetectorS(8.0, playerid, giveplayerid)) {
            if(giveplayerid == playerid) { SendClientMessage(playerid, COLOR_GREY, "You cant show your badge to yourself!"); return 1; }
            GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
//GetPlayerName(playerid, sendername, sizeof(sendername));
            format(string, sizeof(string), "* %s takes out his/her badge from his/her pocket.", sendername);
            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            GetPlayerName(playerid,sendername,sizeof(sendername));
            if(PlayerInfo[playerid][pMember] == 1 || PlayerInfo[playerid][pLeader] == 1) {
              if(PlayerInfo[playerid][pRank] == 11) { format(string, sizeof(string), "** Rank/Name: Chief of Police - %s", sendername); }
              else if(PlayerInfo[playerid][pRank] == 10) { format(string, sizeof(string), "** Rank/Name: Commander - %s", sendername); }
              else if(PlayerInfo[playerid][pRank] == 9) { format(string, sizeof(string), "** Rank/Name: Captain - %s", sendername); }
              else if(PlayerInfo[playerid][pRank] == 8) { format(string, sizeof(string), "** Rank/Name: Lieutenant - %s", sendername); }
              else if(PlayerInfo[playerid][pRank] == 7) { format(string, sizeof(string), "** Rank/Name: Staff Sergeant - %s", sendername); }
              else if(PlayerInfo[playerid][pRank] == 6) { format(string, sizeof(string), "** Rank/Name: Sergeant - %s", sendername); }
              else if(PlayerInfo[playerid][pRank] == 5) { format(string, sizeof(string), "** Rank/Name: Senior Lead Officer - %s", sendername); }
              else if(PlayerInfo[playerid][pRank] == 4) { format(string, sizeof(string), "** Rank/Name: Lead Officer - %s", sendername); }
              else if(PlayerInfo[playerid][pRank] == 3) { format(string, sizeof(string), "** Rank/Name: Police Officer II - %s", sendername); }
              else if(PlayerInfo[playerid][pRank] == 2) { format(string, sizeof(string), "** Rank/Name: Police Officer I - %s", sendername); }
              else if(PlayerInfo[playerid][pRank] == 1) { format(string, sizeof(string), "** Rank/Name: Cadet - %s", sendername); }
            }
            else if(PlayerInfo[playerid][pMember] == 2 || PlayerInfo[playerid][pLeader] == 2) {
              if(PlayerInfo[playerid][pRank] == 6) { format(string, sizeof(string), "** FBI Rank/Name: Director - %s ", sendername); }
              else if(PlayerInfo[playerid][pRank] == 5) { format(string, sizeof(string), "** FBI Rank/Name: Deputy Director - %s ", sendername); }
              else if(PlayerInfo[playerid][pRank] == 4) { format(string, sizeof(string), "** FBI Rank/Name: Commander - %s ", sendername); }
              else if(PlayerInfo[playerid][pRank] == 3) { format(string, sizeof(string), "** FBI Rank/Name: Intelligence Agent - %s ", sendername); }
              else if(PlayerInfo[playerid][pRank] == 2) { format(string, sizeof(string), "** FBI Rank/Name: Special Agent - %s ", sendername); }
              else if(PlayerInfo[playerid][pRank] == 1) { format(string, sizeof(string), "** FBI Rank/Name: Trainee Agent - %s ", sendername); }
            }
            else if(IsAPrisonGuard(playerid)) {
              if(PlayerInfo[playerid][pRank] == 6) { format(string, sizeof(string), "** LS Prison Rank/Name: Warden - %s ", sendername); }
              else if(PlayerInfo[playerid][pRank] == 5) { format(string, sizeof(string), "** LS Prison Rank/Name: Deputy Warden - %s ", sendername); }
              else if(PlayerInfo[playerid][pRank] == 4) { format(string, sizeof(string), "** LS Prison Rank/Name: Guard`s Commander - %s ", sendername); }
              else if(PlayerInfo[playerid][pRank] == 3) { format(string, sizeof(string), "** LS Prison Rank/Name: Senior Guard - %s ", sendername); }
              else if(PlayerInfo[playerid][pRank] == 2) { format(string, sizeof(string), "** LS Prison Rank/Name: Guard - %s ", sendername); }
              else if(PlayerInfo[playerid][pRank] == 1) { format(string, sizeof(string), "** LS Prison Rank/Name: Trainee - %s ", sendername); }
            }
            SendClientMessage(giveplayerid, COLOR_GREY, string);
            format(string, sizeof(string), "* %s has shown his/her badge to you.", sendername);
            SendClientMessage(giveplayerid, COLOR_GREY, string);
            format(string, sizeof(string), "* You have shown your Badge to %s.", giveplayer);
            SendClientMessage(playerid, COLOR_GREY, string);
          }
          else {
            SendClientMessage(playerid, COLOR_GREY, "  That player is not near you!");
            return 1;
          }
        }
      }
      else {
        SendClientMessage(playerid, COLOR_GREY, "  That player is Offline!");
        return 1;
      }
    }
  }
  return 1;
}
Reply
#5

(Oh shit tja FreddeN, har lirat med dig skit mkt ju, SOLS osv, [LSPD]Eric hдr ^^)

You have to use else if statements to state different ranks in a string.

EDIT: Look at the previous post for an example.
Reply
#6

Quote:
Originally Posted by Souvlaki
I hope this will help.I made this for my GM.I think you can take an idea to make your own,

pawn Code:
if(strcmp(cmd,"/showbadge",true)==0)
{
  if(IsPlayerConnected(playerid)) {
    if(IsACop(playerid) || IsAPrisonGuard(playerid)) {
      tmp = strtok(cmdtext, idx);
      if(!strlen(tmp)) {
        SendClientMessage(playerid, COLOR_WHITE, "USAGE: /showbadge [playerid/PartOfName]");
        return 1;
      }
      giveplayerid = ReturnUser(tmp);
      if(IsPlayerConnected(giveplayerid)) {
        if(giveplayerid != INVALID_PLAYER_ID) {
          if (ProxDetectorS(8.0, playerid, giveplayerid)) {
            if(giveplayerid == playerid) { SendClientMessage(playerid, COLOR_GREY, "You cant show your badge to yourself!"); return 1; }
            GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
//GetPlayerName(playerid, sendername, sizeof(sendername));
            format(string, sizeof(string), "* %s takes out his/her badge from his/her pocket.", sendername);
            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            GetPlayerName(playerid,sendername,sizeof(sendername));
            if(PlayerInfo[playerid][pMember] == 1 || PlayerInfo[playerid][pLeader] == 1) {
              if(PlayerInfo[playerid][pRank] == 11) { format(string, sizeof(string), "** Rank/Name: Chief of Police - %s", sendername); }
              else if(PlayerInfo[playerid][pRank] == 10) { format(string, sizeof(string), "** Rank/Name: Commander - %s", sendername); }
              else if(PlayerInfo[playerid][pRank] == 9) { format(string, sizeof(string), "** Rank/Name: Captain - %s", sendername); }
              else if(PlayerInfo[playerid][pRank] == 8) { format(string, sizeof(string), "** Rank/Name: Lieutenant - %s", sendername); }
              else if(PlayerInfo[playerid][pRank] == 7) { format(string, sizeof(string), "** Rank/Name: Staff Sergeant - %s", sendername); }
              else if(PlayerInfo[playerid][pRank] == 6) { format(string, sizeof(string), "** Rank/Name: Sergeant - %s", sendername); }
              else if(PlayerInfo[playerid][pRank] == 5) { format(string, sizeof(string), "** Rank/Name: Senior Lead Officer - %s", sendername); }
              else if(PlayerInfo[playerid][pRank] == 4) { format(string, sizeof(string), "** Rank/Name: Lead Officer - %s", sendername); }
              else if(PlayerInfo[playerid][pRank] == 3) { format(string, sizeof(string), "** Rank/Name: Police Officer II - %s", sendername); }
              else if(PlayerInfo[playerid][pRank] == 2) { format(string, sizeof(string), "** Rank/Name: Police Officer I - %s", sendername); }
              else if(PlayerInfo[playerid][pRank] == 1) { format(string, sizeof(string), "** Rank/Name: Cadet - %s", sendername); }
            }
            else if(PlayerInfo[playerid][pMember] == 2 || PlayerInfo[playerid][pLeader] == 2) {
              if(PlayerInfo[playerid][pRank] == 6) { format(string, sizeof(string), "** FBI Rank/Name: Director - %s ", sendername); }
              else if(PlayerInfo[playerid][pRank] == 5) { format(string, sizeof(string), "** FBI Rank/Name: Deputy Director - %s ", sendername); }
              else if(PlayerInfo[playerid][pRank] == 4) { format(string, sizeof(string), "** FBI Rank/Name: Commander - %s ", sendername); }
              else if(PlayerInfo[playerid][pRank] == 3) { format(string, sizeof(string), "** FBI Rank/Name: Intelligence Agent - %s ", sendername); }
              else if(PlayerInfo[playerid][pRank] == 2) { format(string, sizeof(string), "** FBI Rank/Name: Special Agent - %s ", sendername); }
              else if(PlayerInfo[playerid][pRank] == 1) { format(string, sizeof(string), "** FBI Rank/Name: Trainee Agent - %s ", sendername); }
            }
            else if(IsAPrisonGuard(playerid)) {
              if(PlayerInfo[playerid][pRank] == 6) { format(string, sizeof(string), "** LS Prison Rank/Name: Warden - %s ", sendername); }
              else if(PlayerInfo[playerid][pRank] == 5) { format(string, sizeof(string), "** LS Prison Rank/Name: Deputy Warden - %s ", sendername); }
              else if(PlayerInfo[playerid][pRank] == 4) { format(string, sizeof(string), "** LS Prison Rank/Name: Guard`s Commander - %s ", sendername); }
              else if(PlayerInfo[playerid][pRank] == 3) { format(string, sizeof(string), "** LS Prison Rank/Name: Senior Guard - %s ", sendername); }
              else if(PlayerInfo[playerid][pRank] == 2) { format(string, sizeof(string), "** LS Prison Rank/Name: Guard - %s ", sendername); }
              else if(PlayerInfo[playerid][pRank] == 1) { format(string, sizeof(string), "** LS Prison Rank/Name: Trainee - %s ", sendername); }
            }
            SendClientMessage(giveplayerid, COLOR_GREY, string);
            format(string, sizeof(string), "* %s has shown his/her badge to you.", sendername);
            SendClientMessage(giveplayerid, COLOR_GREY, string);
            format(string, sizeof(string), "* You have shown your Badge to %s.", giveplayer);
            SendClientMessage(playerid, COLOR_GREY, string);
          }
          else {
            SendClientMessage(playerid, COLOR_GREY, "  That player is not near you!");
            return 1;
          }
        }
      }
      else {
        SendClientMessage(playerid, COLOR_GREY, "  That player is Offline!");
        return 1;
      }
    }
  }
  return 1;
}
I'm this far, I cant figure out the last part, anyone know what the error is right now?

Code:
	if(strcmp(cmd, "/showbadge", true) == 0)
	{
	  if(IsPlayerConnected(playerid))
	  {
	  	tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GREY, "	USAGE: /showbadge [playerid]");
				return 1;
			}
			new para1;
			para1 = ReturnUser(tmp);
			giveplayerid = ReturnUser(tmp);
      if(gTeam[playerid] == TEAM_LSPD)
			{
			  if(PlayerInfo[playerid][pLAERank] >= 1)
			  {
					if(IsPlayerConnected(para1))
					{
						if(giveplayerid != INVALID_PLAYER_ID)
		  			{
			  			if (GetDistanceBetweenPlayers(playerid,giveplayerid) > 5)
							{
			  				SendClientMessage(playerid, COLOR_GREY, "	You are too far away from the player.");
			  				return 1;
							}
					  	GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
							GetPlayerName(playerid, sendername, sizeof(sendername));
							new length = strlen(cmdtext);
							while ((idx < length) && (cmdtext[idx] <= ' '))
							if(!strlen(tmp))
							{
									SendClientMessage(playerid, COLOR_GREY, "	USAGE: /showbadge [playerid]");
									return 1;
							}
							format(string, sizeof(string), "* %s takes hold of his badge and shows it to %s.", sendername, giveplayer);
							ProxDetector(30.0, playerid, string, COLOR_LILAC,COLOR_LILAC,COLOR_LILAC,COLOR_LILAC,COLOR_LILAC);
							if(PlayerInfo[playerid][pLAERank] == 10) { format(string, sizeof(string), "Chief of Police %s", sendername); }
							else if(PlayerInfo[playerid][pLAERank] == 9) { format(string, sizeof(string), "Assistant Chief %s", sendername); }
							else if(PlayerInfo[playerid][pLAERank] == 8) { format(string, sizeof(string), "Deputy Chief %s", sendername); }
							else if(PlayerInfo[playerid][pLAERank] == 7) { format(string, sizeof(string), "Commander %s", sendername); }
							else if(PlayerInfo[playerid][pLAERank] == 6) { format(string, sizeof(string), "Captain %s", sendername); }
							else if(PlayerInfo[playerid][pLAERank] == 5) { format(string, sizeof(string), "Lieutenant %s", sendername); }
							else if(PlayerInfo[playerid][pLAERank] == 4) { format(string, sizeof(string), "Sergeant %s", sendername); }
							else if(PlayerInfo[playerid][pLAERank] == 3) { format(string, sizeof(string), "Detective %s", sendername); }
							else if(PlayerInfo[playerid][pLAERank] == 2) { format(string, sizeof(string), "Senior Lead Officer %s", sendername); }
							else if(PlayerInfo[playerid][pLAERank] == 1) { format(string, sizeof(string), "Police Officer %s", sendername); }
						}
					}
				}
				else
				{
					SendClientMessage(playerid, COLOR_GREY, "	You are not authorized to use that command.");
 					return 1;
				}
			}
			else
			{
				SendClientMessage(playerid, COLOR_GREY, "	You are not a Police Officer.");
				return 1;
			}
		}
		return 1;
	}
Reply
#7

Never mind, I think I fixed it:

Code:
	if(strcmp(cmd, "/showbadge", true) == 0)
	{
	  if(IsPlayerConnected(playerid))
	  {
	  	tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GREY, "	USAGE: /showbadge [playerid]");
				return 1;
			}
			new para1;
			para1 = ReturnUser(tmp);
			giveplayerid = ReturnUser(tmp);
      if(gTeam[playerid] == TEAM_LSPD)
			{
			  if(PlayerInfo[playerid][pLAERank] >= 1)
			  {
					if(IsPlayerConnected(para1))
					{
						if(giveplayerid != INVALID_PLAYER_ID)
		  			{
			  			if (GetDistanceBetweenPlayers(playerid,giveplayerid) > 5)
							{
			  				SendClientMessage(playerid, COLOR_GREY, "	You are too far away from the player.");
			  				return 1;
							}
					  	GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
							GetPlayerName(playerid, sendername, sizeof(sendername));
							new length = strlen(cmdtext);
							while ((idx < length) && (cmdtext[idx] <= ' '))
							if(!strlen(tmp))
							{
									SendClientMessage(playerid, COLOR_GREY, "	USAGE: /showbadge [playerid]");
									return 1;
							}
							format(string, sizeof(string), "* %s takes hold of his badge and shows it to %s.", sendername, giveplayer);
							ProxDetector(30.0, playerid, string, COLOR_LILAC,COLOR_LILAC,COLOR_LILAC,COLOR_LILAC,COLOR_LILAC);
							if(PlayerInfo[playerid][pLAERank] == 10) { format(string, sizeof(string), "Chief of Police %s, Los Santos Police Department.", sendername); }
							else if(PlayerInfo[playerid][pLAERank] == 9) { format(string, sizeof(string), "Assistant Chief %s, Los Santos Police Department.", sendername); }
							else if(PlayerInfo[playerid][pLAERank] == 8) { format(string, sizeof(string), "Deputy Chief %s, Los Santos Police Department.", sendername); }
							else if(PlayerInfo[playerid][pLAERank] == 7) { format(string, sizeof(string), "Commander %s, Los Santos Police Department.", sendername); }
							else if(PlayerInfo[playerid][pLAERank] == 6) { format(string, sizeof(string), "Captain %s, Los Santos Police Department.", sendername); }
							else if(PlayerInfo[playerid][pLAERank] == 5) { format(string, sizeof(string), "Lieutenant %s, Los Santos Police Department.", sendername); }
							else if(PlayerInfo[playerid][pLAERank] == 4) { format(string, sizeof(string), "Sergeant %s, Los Santos Police Department.", sendername); }
							else if(PlayerInfo[playerid][pLAERank] == 3) { format(string, sizeof(string), "Detective %s, Los Santos Police Department.", sendername); }
							else if(PlayerInfo[playerid][pLAERank] == 2) { format(string, sizeof(string), "Senior Lead Officer %s, Los Santos Police Department.", sendername); }
							else if(PlayerInfo[playerid][pLAERank] == 1) { format(string, sizeof(string), "Police Officer %s, Los Santos Police Department.", sendername); }
							SendClientMessage(giveplayerid, COLOR_BLUE, string);
							format(string, sizeof(string), "You have shown your badge to %s.", giveplayer);
							SendClientMessage(playerid, COLOR_BLUE, string);
						}
					}
				}
				else
				{
					SendClientMessage(playerid, COLOR_GREY, "	You are not authorized to use that command.");
 					return 1;
				}
			}
			else
			{
				SendClientMessage(playerid, COLOR_GREY, "	You are not a Police Officer.");
				return 1;
			}
		}
		return 1;
	}
Thanks for your help dudes, have a good one
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)