[HELP] Player Wanted Level
#1

Hello. So I have speed cameras in my server and if someone is speeding for example on 100 km/h, when it's allowed only 80 km/h, the player gets PlayerInfo[i][pWantedLevel]++;. There is a police class, in which you can use a command "/fine", to remove wanted levels from a player for cash, which means, police gets cash and score for giving a fine for a player.

Each WantedLevel is $500. If wanted level is 2, then $1000, if 3 = $1500 etc. I want to know, would be there a short way, like calculating the wanted levels? I just don't want to write a really long line of if(PlayerInfo[playerid][pWantedLevel] < 1), if(PlayerInfo[playerid][pWantedLevel] < 2) etc. But when 50*500=$25000

Here is the code, from "/fine" command:

PHP код:
CMD:fine(playeridparams[])
{
        new 
playerid2;
        new 
id;
        if (
sscanf(params"u"id)) SendClientMessage(playerid0xCCCC99AA"USAGE: /fine [playerid]");
        else if (
id == INVALID_PLAYER_IDSendClientMessage(playerid0xFF0000AA"Player is not online.");
        else
        {
        if(
PlayerInfo[playerid][pClass] == 3)
        {
        if(
GetDistanceBetweenPlayers(playeridplayerid2) > 5)
        {
        if(
PlayerInfo[playerid][pWantedLevel] < 0)
        {
        
SendClientMessage(playerid0x00FF00AA"Player is not wanted!");
        }
        if(
PlayerInfo[playerid][pWantedLevel] < 1)
        {
        
GivePlayerMoney(playerid500);
        
GivePlayerMoney(id, -500);
        new 
tname[MAX_PLAYER_NAME];
        
GetPlayerName(id,tname,sizeof(tname));
        new 
pname[MAX_PLAYER_NAME];
        
GetPlayerName(playerid,pname,sizeof(pname));
        new 
tstring[128];
        new 
pstring[128];
        
SetPlayerScoreplayeridGetPlayerScoreplayerid ) + );
        
format(tstring,sizeof(tstring),"You Have Been Fined -$1000 By Police Officer %s(%d).",pname,playerid);
        
format(tstring,sizeof(pstring),"You have fined %s(%d)! And His Wanted Level Was 1 You Got +1000$",tname,id);
        
SendClientMessage(id,COLOR_RED,tstring);
        
SendClientMessage(playerid,COLOR_RED,pstring);
          }
        }
        }
        }
        return 
1;

Reply
#2

Код:
GivePlayerMoney(playerid, PlayerInfo[playerid][pWantedLevel]*500); 
GivePlayerMoney(id, PlayerInfo[playerid][pWantedLevel]*-500);
Calculation: WantedLevel x 500
If player's wanted level is 5, it will calculate 5 x 500 = 2500.
Reply
#3

Quote:
Originally Posted by Darkwood17
Посмотреть сообщение
Код:
GivePlayerMoney(playerid, PlayerInfo[playerid][pWantedLevel]*500); 
GivePlayerMoney(id, PlayerInfo[playerid][pWantedLevel]*-500);
Calculation: WantedLevel x 500
If player's wanted level is 5, it will calculate 5 x 500 = 2500.
So I don't need if(PlayerInfo[playerid][pWantedLevel] < 1),if(PlayerInfo[playerid][pWantedLevel] < 2) etc?
Reply
#4

How about this
Код:
CMD:fine(playerid, params[])
{
	if(PlayerInfo[playerid][pClass] == 3)
	{
  		new iTargetID;
		if(sscanf(params, "u", iTargetID))
		{
			SendClientMessage(playerid, COLOR_WHITE, "USAGE: /fine [player]");
			return 1;
		}
		if(GetDistanceBetweenPlayers(playerid, playerid2) > 5)
        {
			if(!IsPlayerConnected(iTargetID))
			{
				SendClientMessage(playerid, COLOR_WHITE, "ERROR: Invalid player specified.");
				return 1;
			}
			else if(PlayerInfo[iTargetID][pClass] == 3)
			{
				SendClientMessage(playerid, COLOR_WHITE, "You can't use this command on a law enforcement officer.");
				return 1;
			}
			else if(PlayerInfo[iTargetID][pWantedLevel] >= 6)
			{
				SendClientMessage(playerid, COLOR_GRAD2, "Target is already most wanted.");
				return 1;
			}
			else
			{
				switch(PlayerInfo[iTargetID][pWantedLevel])
				{
					case 0:
					{
					}
					case 1:
					{
					    GivePlayerMoney(playerid, 500);
				        GivePlayerMoney(iTargetID, -500);
				        new tname[MAX_PLAYER_NAME];
				        GetPlayerName(iTargetID,tname,sizeof(tname));
				        new pname[MAX_PLAYER_NAME];
				        GetPlayerName(playerid,pname,sizeof(pname));
				        new tstring[128];
				        new pstring[128];
				        SetPlayerScore(playerid, ++)
				        format(tstring,sizeof(tstring),"You Have Been Fined -$1000 By Police Officer %s(%d).",pname,playerid);
				        format(tstring,sizeof(pstring),"You have fined %s(%d)! And His Wanted Level Was 1 You Got +1000$",tname,iTargetID);
				        SendClientMessage(iTargetID,COLOR_RED,tstring);
				        SendClientMessage(playerid,COLOR_RED,pstring);
				        return 1;
					}
					case 2:
					{
					}
					case 3:
					{
					}
					case 4:
					{
					}
					case 5:
					{
					}
				}
			}
		}
		else SendClientMessage(playerid, COLOR_GRAD2, "You're not near the player specified.");
	}
	else SendClientMessage(playerid, COLOR_GRAD2, "You're not a law enforcement officer.");
	return 1;
}
using switches and cases, you can control what happens if they get fined while having what ever Wanted Level

0 = 1
1 = 2
2 = 3
3 = 4
4 = 5
and 6 is already most wanted, you might want to make some more features for that :P
Reply
#5

Quote:
Originally Posted by D1am0nd
Посмотреть сообщение
So I don't need if(PlayerInfo[playerid][pWantedLevel] < 1),if(PlayerInfo[playerid][pWantedLevel] < 2) etc?
Yes.

Quote:
Originally Posted by SkyFlare
Посмотреть сообщение
How about this
Код:
CMD:fine(playerid, params[])
{
	if(PlayerInfo[playerid][pClass] == 3)
	{
		new iTargetID;
		if(sscanf(params, "u", iTargetID))
		{
			SendClientMessage(playerid, COLOR_WHITE, "USAGE: /fine [player]");
		}
		else if(!IsPlayerConnected(iTargetID))
		{
			SendClientMessage(playerid, COLOR_WHITE, "{0049FF}ERROR{00A5FF}: Invalid player specified.");
		}
		else if(PlayerInfo[iTargetID][pClass] == 3)
		{
			SendClientMessage(playerid, COLOR_WHITE, "You can't use this command on a law enforcement officer.");
		}
		else if(PlayerInfo[iTargetID][pWantedLevel] >= 6)
		{
			SendClientMessage(playerid, COLOR_GRAD2, "Target is already most wanted.");
		}
		else
		{
			switch(PlayerInfo[iTargetID][pWantedLevel])
			{
				case 0:
				{
				}
				case 1:
				{
				    GivePlayerMoney(playerid, 500);
			        GivePlayerMoney(iTargetID, -500);
			        new tname[MAX_PLAYER_NAME];
			        GetPlayerName(iTargetID,tname,sizeof(tname));
			        new pname[MAX_PLAYER_NAME];
			        GetPlayerName(playerid,pname,sizeof(pname));
			        new tstring[128];
			        new pstring[128];
			        SetPlayerScore(playerid, ++)
			        format(tstring,sizeof(tstring),"You Have Been Fined -$1000 By Police Officer %s(%d).",pname,playerid);
			        format(tstring,sizeof(pstring),"You have fined %s(%d)! And His Wanted Level Was 1 You Got +1000$",tname,iTargetID);
			        SendClientMessage(id,COLOR_RED,tstring);
			        SendClientMessage(playerid,COLOR_RED,pstring);
			        return 1;
				}
				case 2:
				{
				}
				case 3:
				{
				}
				case 4:
				{
				}
				case 5:
				{
				}
			}
		}
	}
	else SendClientMessage(playerid, COLOR_GRAD2, "You're not a law enforcement officer.");
	return 1;
}
using switches and cases, you can control what happens if they get fined while having what ever Wanted Level

0 = 1
1 = 2
2 = 3
3 = 4
4 = 5
and 6 is already most wanted, you might want to make some more features for that :P
No, don't do that. This way is not faster.
6 is not the highest wanted level only because you can see 6 start in the HUD. It can go much more higher.
Reply
#6

Quote:
Originally Posted by Darkwood17
Посмотреть сообщение
Yes.



No, don't do that. This way is not faster.
6 is not the highest wanted level only because you can see 6 start in the HUD. It can go much more higher.
Indeed 6 is max you can see, what is the point in adding more than 6 if the player can not see them without extra Textdraws?

He wanted the fine for them, he got it, but he can easily set it more than 6

Код:
CMD:fine(playerid, params[])
{
	if(PlayerInfo[playerid][pClass] == 3)
	{
  		new iTargetID;
		if(sscanf(params, "u", iTargetID))
		{
			SendClientMessage(playerid, COLOR_WHITE, "USAGE: /fine [player]");
			return 1;
		}
		if(GetDistanceBetweenPlayers(playerid, playerid2) > 5)
        {
			if(!IsPlayerConnected(iTargetID))
			{
				SendClientMessage(playerid, COLOR_WHITE, "ERROR: Invalid player specified.");
				return 1;
			}
			else if(PlayerInfo[iTargetID][pClass] == 3)
			{
				SendClientMessage(playerid, COLOR_WHITE, "You can't use this command on a law enforcement officer.");
				return 1;
			}
			else if(PlayerInfo[iTargetID][pWantedLevel] >= 10)// If they are Level 10 Wanted Level
			{
				SendClientMessage(playerid, COLOR_GRAD2, "Target is already most wanted.");
				return 1;
			}
			else
			{
				switch(PlayerInfo[iTargetID][pWantedLevel])
				{
					case 0:// If they are Level 0 Wanted Level
					{
					}
					case 1:// If they are Level 1 Wanted Level
					{
					    GivePlayerMoney(playerid, 500);
				        GivePlayerMoney(iTargetID, -500);
				        new tname[MAX_PLAYER_NAME];
				        GetPlayerName(iTargetID,tname,sizeof(tname));
				        new pname[MAX_PLAYER_NAME];
				        GetPlayerName(playerid,pname,sizeof(pname));
				        new tstring[128];
				        new pstring[128];
				        SetPlayerScore(playerid, ++)
				        format(tstring,sizeof(tstring),"You Have Been Fined -$1000 By Police Officer %s(%d).",pname,playerid);
				        format(tstring,sizeof(pstring),"You have fined %s(%d)! And His Wanted Level Was 1 You Got +1000$",tname,iTargetID);
				        SendClientMessage(iTargetID,COLOR_RED,tstring);
				        SendClientMessage(playerid,COLOR_RED,pstring);
				        return 1;
					}
					case 2:// If they are Level 2 Wanted Level
					{
					}
					case 3:// If they are Level 3 Wanted Level
					{
					}
					case 4:// If they are Level 4 Wanted Level
					{
					}
					case 5:// If they are Level 5 Wanted Level
					{
					}
					case 6:// If they are Level 6 Wanted Level
					{
					}
					case 7:// If they are Level 7 Wanted Level
					{
					}
					case 8:// If they are Level 8 Wanted Level
					{
					}
					case 9:// If they are Level 9 Wanted Level
					{
					}
				}
			}
		}
		else SendClientMessage(playerid, COLOR_GRAD2, "You're not near the player specified.");
	}
	else SendClientMessage(playerid, COLOR_GRAD2, "You're not a law enforcement officer.");
	return 1;
}
Reply
#7

Quote:
Originally Posted by SkyFlare
Посмотреть сообщение
Indeed 6 is max you can see, what is the point in adding more than 6 if the player can not see them without extra Textdraws?

He wanted the fine for them, he got it, but he can easily set it more than 6
The player can have more than 6 wanted level, but he won't see it and there's no point seeing more than 6 stars.
If he want to limit them, your way won't be good again. There's a shorter and faster way.
Reply
#8

pawn Код:
CMD:fine(playerid, params[])
{
    if(PlayerInfo[playerid][pClass] == 3)
    {
        if(PlayerInfo[playerid][pJailTime] > 0) return SendClientMessageEx(playerid, COLOR_WHITE, "You cannot use this in jail/prison.");
        new iTargetID;
        if(sscanf(params, "u", iTargetID)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: (/su)spect [player]");
        if(!IsPlayerConnected(iTargetID))  return SendClientMessageEx(playerid, COLOR_WHITE, "{0049FF}ERROR{00A5FF}: Invalid player specified.");
        if(PlayerInfo[iTargetID][pClass] == 3) return SendClientMessageEx(playerid, COLOR_WHITE, "You can't use this command on a law enforcement officer.");
         if(PlayerInfo[iTargetID][pWantedLevel] >= 6) return SendClientMessageEx(playerid, COLOR_GRAD2, "Target is already most wanted.");
        if(PlayerInfo[iTargetID][pWantedLevel] == 0) return SendClientMessageEx(playerid, COLOR_WHITE, "Player is not wanted.");
        GivePlayerMoney(playerid, PlayerInfo[playerid][pWantedLevel]*500); // darkwood's code  | 2 * 500 = 1000 | 5 * 500 = 25000, a quicker way.
        GivePlayerMoney(id, PlayerInfo[playerid][pWantedLevel] * -500); // ^^^

        new tname[MAX_PLAYER_NAME];
        GetPlayerName(id,tname,sizeof(tname));
        new pname[MAX_PLAYER_NAME];
        GetPlayerName(playerid,pname,sizeof(pname));
        new tstring[128];
        new pstring[128];
        SetPlayerScore( playerid, GetPlayerScore( playerid ) + 1 );
        format(tstring,sizeof(tstring),"You Have Been Fined -$1000 By Police Officer %s(%d).",pname,playerid);
        format(pstring,sizeof(pstring),"You have fined %s(%d)! And His Wanted Level Was 1 You Got +1000$",tname,id);
        SendClientMessage(id,COLOR_RED,tstring);
        SendClientMessage(playerid,COLOR_RED,pstring);

    }
    else SendClientMessageEx(playerid, COLOR_GRAD2, "You're not a law enforcement officer.");
    return 1;
}
this, is an optimized form of your command
i've also fixed the formatting codes, you have just formatted tstring 2 times, so that it will only format it as playerid's message only, fixed it and replaced it with pstring
Reply
#9

Quote:
Originally Posted by Sawalha
Посмотреть сообщение
pawn Код:
CMD:fine(playerid, params[])
{
    if(PlayerInfo[playerid][pClass] == 3)
    {
        if(PlayerInfo[playerid][pJailTime] > 0) return SendClientMessageEx(playerid, COLOR_WHITE, "You cannot use this in jail/prison.");
        new iTargetID;
        if(sscanf(params, "u", iTargetID)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: (/su)spect [player]");
        if(!IsPlayerConnected(iTargetID))  return SendClientMessageEx(playerid, COLOR_WHITE, "{0049FF}ERROR{00A5FF}: Invalid player specified.");
        if(PlayerInfo[iTargetID][pClass] == 3) return SendClientMessageEx(playerid, COLOR_WHITE, "You can't use this command on a law enforcement officer.");
         if(PlayerInfo[iTargetID][pWantedLevel] >= 6) return SendClientMessageEx(playerid, COLOR_GRAD2, "Target is already most wanted.");
        if(PlayerInfo[iTargetID][pWantedLevel] == 0) return SendClientMessageEx(playerid, COLOR_WHITE, "Player is not wanted.");
        GivePlayerMoney(playerid, PlayerInfo[playerid][pWantedLevel]*500); // darkwood's code  | 2 * 500 = 1000 | 5 * 500 = 25000, a quicker way.
        GivePlayerMoney(id, PlayerInfo[playerid][pWantedLevel] * -500);

        new tname[MAX_PLAYER_NAME];
        GetPlayerName(id,tname,sizeof(tname));
        new pname[MAX_PLAYER_NAME];
        GetPlayerName(playerid,pname,sizeof(pname));
        new tstring[128];
        new pstring[128];
        SetPlayerScore( playerid, GetPlayerScore( playerid ) + 1 );
        format(tstring,sizeof(tstring),"You Have Been Fined -$1000 By Police Officer %s(%d).",pname,playerid);
        format(pstring,sizeof(pstring),"You have fined %s(%d)! And His Wanted Level Was 1 You Got +1000$",tname,id);
        SendClientMessage(id,COLOR_RED,tstring);
        SendClientMessage(playerid,COLOR_RED,pstring);

    }
    else SendClientMessageEx(playerid, COLOR_GRAD2, "You're not a law enforcement officer.");
    return 1;
}
this, is an optimized form of your command
In 1 way, yes this is optimized, but what if he wanted other things to happen at a higher wanted level, eg: loss of usage of guns at 4 wanted level + or take drivers license away only at wanted level 1,2,3 or what if he doesnt want the price to go up in that rate phase, he can easily define for each level alot easier this way, he isn't limited in any way, he can control each level with my code :P
EDIT: Thanks for fixing the problem with the code I made, but I wasn't trying to pinpoint that part, I was just showing a template of some sort for him to use, as a general guide line.
Reply
#10

Quote:
Originally Posted by SkyFlare
Посмотреть сообщение
In 1 way, yes this is optimized, but what if he wanted other things to happen at a higher wanted level, eg: loss of usage of guns at 4 wanted level + or take drivers license away only at wanted level 1,2,3
well, he didn't mention that, however, he can simply use switch and case, if he wanted to add these features
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)